Add an -Wundef-prefix=<arg1>,<arg2>... option, which is similar to -Wundef, but only give warnings for undefined macros with the given prefixes.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
clang/include/clang/Basic/DiagnosticGroups.td | ||
---|---|---|
108 ↗ | (On Diff #266979) | It seems like you're not using the UndefinedPrefix group in this patch. Is that intentional, or was this left in the patch by mistake? |
Can you still modify the state of -Wundef with #pragma clang diagnostic? Could you add a test to cover it.
clang/include/clang/Basic/DiagnosticGroups.td | ||
---|---|---|
108 ↗ | (On Diff #266979) | This is intentional to map both Wundef and Wundef-prefix to the same warning. And since Wundef is changed to an alias, the Undefined subgroup is used to keep existing outputs/behaviors consistent (to make -Werror=undef work, and to keep the [-Wundef] option name in the diagnostic message). |
Update test case for #pragma clang diagnostic
Update test case to verify that the state of -Wundef can still be modified using #pragma clang diagnostic
clang/lib/Lex/PPExpressions.cpp | ||
---|---|---|
265 | Then we only get errors for undef-prefix=<arg>. Yes this needs to be fixed. |
clang/lib/Lex/PPExpressions.cpp | ||
---|---|---|
265 | That is an option. But then we lose the ability to intentionally turning just the prefixes into errors, like -Wundef-prefix=FOO -Werror or -Wundef-prefix=BAR -Werror=undef-prefix |
- Refine test cases to check combinations of 'Wundef' and 'Wundef-prefix', and with/without 'Werror';
- Fix issues with '-Werror=undef' by explicitly looking for the option.
- Remove implementation details from the help text of 'Wundef';
- Hide help text for 'Wundef-prefix' and 'Wundef'.
Abort the design of making 'Wundef' an alias to 'Wundef-prefix' because it
depends on the alias expansion to work, which adds an empty string to 'UndefPrefixes'
to do the trick. However, any other way to enable 'Wundef', for example, via 'Werror=undef'
or '#pragma clang diagnostic', will not work and cannot be handled easily.
Instead, just suppress 'Wundef-prefix' when 'Wundef' is enabled.
We should provide a description that doesn't mention that this is an alias of -Wundef-prefix, because the alias is an implementation detail.