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 | ||
---|---|---|
127–128 | 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 | ||
---|---|---|
87 | the indentation doesn't look right, running clang-format should fix it. | |
127–128 | this line exceeds the max 80 character limit, clang-format should fix it. | |
clang-tools-extra/include-cleaner/unittests/RecordTest.cpp | ||
227 | 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) | |
232 | the #define Y 2 can be removed, our test doesn't care about it. just use #ifdef X #endif is enough. | |
247 | nit: this can be removed, as the EXPECT_THAT on line 258 covers this. | |
254 | 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 | ||
---|---|---|
127–128 | Right, didn't know default parameter values were possible in C++, thanks. | |
127–128 | Formatting should be fine now. | |
clang-tools-extra/include-cleaner/unittests/RecordTest.cpp | ||
227 | 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. | |
232 | Ok, I'll remove all the fluff. | |
254 | Ok, I've reduced everything to X. |
clang-tools-extra/include-cleaner/unittests/RecordTest.cpp | ||
---|---|---|
247 | 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 | ||
---|---|---|
234 | nit: we can get rid of the main function, it is not needed. | |
237 | nit: this #else line can be removed. | |
242 | The same, can be removed. | |
247 | yeah, the comment was attached to the old snapshot. it is the line 254 now ( ASSERT_THAT(Recorded.MacroReferences, Not(IsEmpty()));). | |
248 | 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. |
the indentation doesn't look right, running clang-format should fix it.