summaryrefslogtreecommitdiffstats
path: root/llvm/lib/MC/ELFObjectWriter.cpp
diff options
context:
space:
mode:
authorNico Weber <nicolasweber@gmx.de>2016-01-19 15:15:31 +0000
committerNico Weber <nicolasweber@gmx.de>2016-01-19 15:15:31 +0000
commitb2348f4ced639e7247cf3a0bba900dd3ca855996 (patch)
tree92ca6736061df2aaa353779f2f8bc6acb46f9054 /llvm/lib/MC/ELFObjectWriter.cpp
parentb13c91f159fa9b631cb15dc02ea0b72b2802ac4d (diff)
downloadbcm5719-llvm-b2348f4ced639e7247cf3a0bba900dd3ca855996.tar.gz
bcm5719-llvm-b2348f4ced639e7247cf3a0bba900dd3ca855996.zip
Add -Wexpansion-to-undefined: warn when using `defined` in a macro definition.
[cpp.cond]p4: Prior to evaluation, macro invocations in the list of preprocessing tokens that will become the controlling constant expression are replaced (except for those macro names modified by the 'defined' unary operator), just as in normal text. If the token 'defined' is generated as a result of this replacement process or use of the 'defined' unary operator does not match one of the two specified forms prior to macro replacement, the behavior is undefined. This isn't an idle threat, consider this program: #define FOO #define BAR defined(FOO) #if BAR ... #else ... #endif clang and gcc will pick the #if branch while Visual Studio will take the #else branch. Emit a warning about this undefined behavior. One problem is that this also applies to function-like macros. While the example above can be written like #if defined(FOO) && defined(BAR) #defined HAVE_FOO 1 #else #define HAVE_FOO 0 #endif there is no easy way to rewrite a function-like macro like `#define FOO(x) (defined __foo_##x && __foo_##x)`. Function-like macros like this are used in practice, and compilers seem to not have differing behavior in that case. So this a default-on warning only for object-like macros. For function-like macros, it is an extension warning that only shows up with `-pedantic`. (But it's undefined behavior in both cases.) llvm-svn: 258128
Diffstat (limited to 'llvm/lib/MC/ELFObjectWriter.cpp')
0 files changed, 0 insertions, 0 deletions
OpenPOWER on IntegriCloud