OSDN Git Service

Suppress non-conforming GNU paste extension in all standard-conforming modes
authorHarald van Dijk <harald@gigawatt.nl>
Mon, 25 Jan 2021 00:56:45 +0000 (00:56 +0000)
committerHarald van Dijk <harald@gigawatt.nl>
Mon, 25 Jan 2021 00:56:45 +0000 (00:56 +0000)
commitf4537935dcdbf390c863591cf556e76c3abab9c1
tree0f0ba3497c083222febe3e0bb4c57c4a5f445229
parenta80ebd01798ca82a4f5ffd6d355c5c9facd83375
Suppress non-conforming GNU paste extension in all standard-conforming modes

The GNU token paste extension that removes the comma in , ## __VA_ARGS__
conflicts with C99/C++11's requirements when a variadic macro has no
named parameters: according to the standard, an invocation as FOO()
gives it a single empty argument, and concatenation of anything with an
empty argument is well-defined. For this reason, the GNU extension was
already disabled in C99 standard-conforming mode. It was not yet
disabled in C++11 standard-conforming mode.

The associated comment suggested that GCC keeps this extension enabled
in C90/C++03 standard-conforming mode, but it actually does not, so
rather than adding a check for C++ language version, this change simply
removes the check for C language version.

Reviewed By: rsmith

Differential Revision: https://reviews.llvm.org/D91913
clang/lib/Lex/TokenLexer.cpp
clang/test/Preprocessor/macro_fn_comma_swallow2.c