Skip to content

Commit 8364f53

Browse files
rnktstellar
authored andcommitted
Revert "Suppress non-conforming GNU paste extension in all standard-conforming modes"
This reverts commit f453793. This reverts commit b43c26d. This GNU and MSVC extension turns out to be very popular. Most projects are not using C++20, so cannot use the new __VA_OPT__ feature to be standards conformant. The other workaround, using -std=gnu*, enables too many language extensions and isn't viable. Until there is a way for users to get the behavior provided by the `, ## __VA_ARGS__` extension in the -std=c++17 and earlier language modes, we need to revert this. (cherry picked from commit 61a66e4)
1 parent 8d22f25 commit 8364f53

File tree

2 files changed

+5
-10
lines changed

2 files changed

+5
-10
lines changed

clang/lib/Lex/TokenLexer.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -148,12 +148,12 @@ bool TokenLexer::MaybeRemoveCommaBeforeVaArgs(
148148
return false;
149149

150150
// GCC removes the comma in the expansion of " ... , ## __VA_ARGS__ " if
151-
// __VA_ARGS__ is empty, but not in strict mode where there are no
152-
// named arguments, where it remains. With GNU extensions, it is removed
153-
// regardless of named arguments.
151+
// __VA_ARGS__ is empty, but not in strict C99 mode where there are no
152+
// named arguments, where it remains. In all other modes, including C99
153+
// with GNU extensions, it is removed regardless of named arguments.
154154
// Microsoft also appears to support this extension, unofficially.
155-
if (!PP.getLangOpts().GNUMode && !PP.getLangOpts().MSVCCompat &&
156-
Macro->getNumParams() < 2)
155+
if (PP.getLangOpts().C99 && !PP.getLangOpts().GNUMode
156+
&& Macro->getNumParams() < 2)
157157
return false;
158158

159159
// Is a comma available to be removed?

clang/test/Preprocessor/macro_fn_comma_swallow2.c

-5
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
11
// Test the __VA_ARGS__ comma swallowing extensions of various compiler dialects.
22

33
// RUN: %clang_cc1 -E %s | FileCheck -check-prefix=GCC -strict-whitespace %s
4-
// RUN: %clang_cc1 -E -std=c90 %s | FileCheck -check-prefix=C99 -strict-whitespace %s
54
// RUN: %clang_cc1 -E -std=c99 %s | FileCheck -check-prefix=C99 -strict-whitespace %s
65
// RUN: %clang_cc1 -E -std=c11 %s | FileCheck -check-prefix=C99 -strict-whitespace %s
76
// RUN: %clang_cc1 -E -x c++ %s | FileCheck -check-prefix=GCC -strict-whitespace %s
8-
// RUN: %clang_cc1 -E -x c++ -std=c++03 %s | FileCheck -check-prefix=C99 -strict-whitespace %s
9-
// RUN: %clang_cc1 -E -x c++ -std=c++11 %s | FileCheck -check-prefix=C99 -strict-whitespace %s
107
// RUN: %clang_cc1 -E -std=gnu99 %s | FileCheck -check-prefix=GCC -strict-whitespace %s
118
// RUN: %clang_cc1 -E -fms-compatibility %s | FileCheck -check-prefix=MS -strict-whitespace %s
12-
// RUN: %clang_cc1 -E -x c++ -fms-compatibility %s | FileCheck -check-prefix=MS -strict-whitespace %s
13-
// RUN: %clang_cc1 -E -x c++ -std=c++11 -fms-compatibility %s | FileCheck -check-prefix=MS -strict-whitespace %s
149
// RUN: %clang_cc1 -E -DNAMED %s | FileCheck -check-prefix=GCC -strict-whitespace %s
1510
// RUN: %clang_cc1 -E -std=c99 -DNAMED %s | FileCheck -check-prefix=C99 -strict-whitespace %s
1611

0 commit comments

Comments
 (0)