forked from OSchip/llvm-project
b2348f4ced
[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 |
||
---|---|---|
.. | ||
Inputs | ||
11-27-2007-FloatLiterals.c | ||
badstring_in_if0.c | ||
bcpl-escaped-newline.c | ||
block_cmt_end.c | ||
builtin_redef.c | ||
c90.c | ||
char-escapes.c | ||
char-literal-encoding-error.c | ||
char-literal.cpp | ||
comment-escape.c | ||
conflict-marker.c | ||
constants.c | ||
coroutines.cpp | ||
counter.c | ||
cross-windows-on-linux-default.cpp | ||
cross-windows-on-linux.cpp | ||
cxx-features.cpp | ||
cxx0x_keyword_as_cxx98.cpp | ||
cxx0x_raw_string_delim_length.cpp | ||
cxx0x_raw_string_directives.cpp | ||
cxx0x_raw_string_unterminated.cpp | ||
cxx1y_binary_literal.cpp | ||
cxx1y_digit_separators.cpp | ||
cxx1z-trigraphs.cpp | ||
digraph.c | ||
dollar-idents.c | ||
eof-char.c | ||
eof-file.c | ||
eof-include.c | ||
eof-number.c | ||
eof-string.c | ||
escape_newline.c | ||
gnu-flags.c | ||
has_attribute_objc_boxable.m | ||
has_extension.c | ||
has_extension_cxx.cpp | ||
has_feature_address_sanitizer.cpp | ||
has_feature_boxed_nsvalue_expressions.m | ||
has_feature_c1x.c | ||
has_feature_cxx0x.cpp | ||
has_feature_exceptions.cpp | ||
has_feature_memory_sanitizer.cpp | ||
has_feature_modules.m | ||
has_feature_objc_arc.m | ||
has_feature_rtti.cpp | ||
has_feature_thread_sanitizer.cpp | ||
has_feature_type_traits.cpp | ||
header.cpp | ||
hexfloat.cpp | ||
keywords_test.c | ||
keywords_test.cpp | ||
long-long.cpp | ||
ms-compatibility.c | ||
ms-extensions.c | ||
ms-extensions.cpp | ||
msdos-cpm-eof.c | ||
multiple-include.c | ||
newline-eof-c++98-compat.cpp | ||
newline-eof.c | ||
numeric-literal-trash.c | ||
objc_macros.m | ||
pragma-mark.c | ||
pragma-message.c | ||
pragma-message2.c | ||
pragma-operators.cpp | ||
pragma-region.c | ||
preamble.c | ||
rdar-8914293.c | ||
rdr-6096838-2.c | ||
rdr-6096838.c | ||
string-literal-encoding.c | ||
string-literal-errors.cpp | ||
string_concat.cpp | ||
token-concat.c | ||
token-concat.cpp | ||
unicode-strings.c | ||
unicode.c | ||
unknown-char.c | ||
utf-16.c | ||
utf-16.c.txt | ||
utf8-char-literal.cpp | ||
utf8-invalid.c | ||
warn-date-time.c | ||
warn_binary_literals.cpp | ||
wchar-signedness.c | ||
wchar.c |