Records macro references in #ifdef clauses as ambiguous.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
Thanks, this code looks good to me overall. I think we can extend it to handle the Defined, Elifdef, Elifndef cases.
And please add a [include-cleaner] prefix in the commit title.
clang-tools-extra/include-cleaner/lib/Record.cpp | ||
---|---|---|
103 | nit: we can set a default value (RefType::Explicit) for the RT parameter, then we don't need to pass the RefType::Explicit in all callsites. |
clang-tools-extra/include-cleaner/lib/Record.cpp | ||
---|---|---|
103 | this line exceeds the max 80 character limit, clang-format should fix it. | |
103 | the indentation doesn't look right, running clang-format should fix it. | |
clang-tools-extra/include-cleaner/unittests/RecordTest.cpp | ||
228 | I think we can simplify the testcase further -- the header.h is not needed, we can use the macro X in all tests (#ifdef, #ifndef etc) | |
233 | the #define Y 2 can be removed, our test doesn't care about it. just use #ifdef X #endif is enough. | |
248 | nit: this can be removed, as the EXPECT_THAT on line 258 covers this. | |
255 | we're using the index of the array Recorded.MacroRefrences to access another array, it is fine currently (because both arrays has the same size), but we will get an out-of-bound-access issue if we add a case #if defined(X)..to the MainFile. If we just use a single macro X for all testcases, then the RefdNames is not needed, we check EXPECT_EQ("X", Ref.Target.macro().Name->getName());. |
Address review comments. Format and simplify code.
clang-tools-extra/include-cleaner/lib/Record.cpp | ||
---|---|---|
103 | Right, didn't know default parameter values were possible in C++, thanks. | |
103 | Formatting should be fine now. | |
clang-tools-extra/include-cleaner/unittests/RecordTest.cpp | ||
228 | Ok. I was trying to add some variety, but you're right - it's not the job of this test to check that things are included properly. | |
233 | Ok, I'll remove all the fluff. | |
255 | Ok, I've reduced everything to X. |
clang-tools-extra/include-cleaner/unittests/RecordTest.cpp | ||
---|---|---|
248 | Sorry, not sure what this comment refers to. Can it be that the line numbering changed due to my newer patch, and this comment does not show up in the correct place anymore? |
clang-tools-extra/include-cleaner/unittests/RecordTest.cpp | ||
---|---|---|
235 | nit: we can get rid of the main function, it is not needed. | |
238 | nit: this #else line can be removed. | |
243 | The same, can be removed. | |
248 | yeah, the comment was attached to the old snapshot. it is the line 254 now ( ASSERT_THAT(Recorded.MacroReferences, Not(IsEmpty()));). | |
249 | The elifndef and elifdef is a C++2b extension feature, so Inputs.ExtraArgs.push_back("-std=c++2b"); to get rid of the [-Wc++2b-extensions] warning in the testcase. |
nit: we can set a default value (RefType::Explicit) for the RT parameter, then we don't need to pass the RefType::Explicit in all callsites.