LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 41120 - [clang-tidy] readability-identifier-naming incorrectly fixes variables which become keywords
Summary: [clang-tidy] readability-identifier-naming incorrectly fixes variables which ...
Status: RESOLVED FIXED
Alias: None
Product: clang-tools-extra
Classification: Unclassified
Component: clang-tidy (show other bugs)
Version: unspecified
Hardware: PC Windows NT
: P enhancement
Assignee: Daniel Cohen
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-03-18 02:47 PDT by MyDeveloperDay
Modified: 2019-11-01 05:53 PDT (History)
4 users (show)

See Also:
Fixed By Commit(s):


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description MyDeveloperDay 2019-03-18 02:47:24 PDT
Whilst looking at how clang-tidy might be able to handle such large scale variable renaming for something like https://reviews.llvm.org/D59251 I decided to run clang-tidy over the clang code base (starting in lib/Format)

clang-tidy mutated the code so it wouldn't compile in BreakableToken.cpp line 226 which is a Lambda, breaking this down into the following code..

transforming

unsigned BreakableStringLiteral::getContentStartColumn(unsigned lineIndex,
                                                       bool Break) const {
  return StartColumn + Prefix.size();
}

into

unsigned BreakableStringLiteral::getContentStartColumn(unsigned lineIndex,
                                                       bool break) const {
  return StartColumn + Prefix.size();
}

Which then causes compile errors due to the use of "break" as a variable name.

c:/Repos/llvm2/llvm-project/clang/lib/Format/BreakableToken.cpp(226): error C2143: syntax error: missing ')' before 'break'

The same effect can be seen with the following code

------------------------------------------------------------
bool foo() {
  bool Break=true;
  bool Continue=false;

  for (unsigned Columns = 1; Columns <= 10; ++Columns) {
    if (Break)
        return Continue;
    }
  }
  return true;
}
------------------------------------------------------------

Clang-tidy needs an option that will ensure keywords when renamed e.g. (Break,Continue,Do,While,Int,Override,etc..) can be renamed to something that will not cause a compile failure due.

something like

KeyWordPrefix: "XXX_"

could be used to turn

Break

into:

XXX_break

so that violations can be easily identified and renamed later
Comment 1 Daniel Cohen 2019-10-05 06:29:56 PDT
Hi, I tried to fix this by giving a warning and not changing the name.
you can review the code in Phabricator.
https://reviews.llvm.org/D68539
Comment 2 Daniel Cohen 2019-11-01 05:53:58 PDT
Done, merged into master
https://reviews.llvm.org/rGe477988309dbde214a6d16ec690a416882714aac