Skip to content

Commit d6d59e6

Browse files
committed
[Clang] Fix __VA_OPT__ implementation so that it treats the concatenation of a non-placemaker token and placemaker token as a non-placemaker token
Currently the implementation of __VA_OPT__ will treat the concatenation of a non-placemaker token and placemaker token as a placemaker token which is not correct. This will fix the implementation and treat the result as a non-placemaker token. This fixes: llvm#60268 Differential Revision: https://reviews.llvm.org/D142604
1 parent 34aff47 commit d6d59e6

File tree

3 files changed

+41
-33
lines changed

3 files changed

+41
-33
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,9 @@ Bug Fixes in This Version
144144
- Fix assert that fails when the expression causing the this pointer to be
145145
captured by a block is part of a constexpr if statement's branch and
146146
instantiation of the enclosing method causes the branch to be discarded.
147+
- Fix __VA_OPT__ implementation so that it treats the concatenation of a
148+
non-placemaker token and placemaker token as a non-placemaker token.
149+
(`#60268 <https://github.com/llvm/llvm-project/issues/60268>`_)
147150

148151
Bug Fixes to Compiler Builtins
149152
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

clang/lib/Lex/TokenLexer.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -500,8 +500,7 @@ void TokenLexer::ExpandFunctionArguments() {
500500
// the first token in a __VA_OPT__ after a ##, delete the ##.
501501
assert(VCtx.isInVAOpt() && "should only happen inside a __VA_OPT__");
502502
VCtx.hasPlaceholderAfterHashhashAtStart();
503-
}
504-
if (RParenAfter)
503+
} else if (RParenAfter)
505504
VCtx.hasPlaceholderBeforeRParen();
506505
}
507506
continue;
@@ -567,7 +566,7 @@ void TokenLexer::ExpandFunctionArguments() {
567566
continue;
568567
}
569568

570-
if (RParenAfter)
569+
if (RParenAfter && !NonEmptyPasteBefore)
571570
VCtx.hasPlaceholderBeforeRParen();
572571

573572
// If this is on the RHS of a paste operator, we've already copied the
Lines changed: 36 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,36 @@
1-
RUN: %clang_cc1 -E %s -pedantic -std=c++2a | FileCheck -strict-whitespace %s
2-
3-
#define LPAREN() (
4-
#define G(Q) 42
5-
#define F1(R, X, ...) __VA_OPT__(G R X) )
6-
1: int x = F1(LPAREN(), 0, <:-);
7-
// CHECK: 1: int x = 42;
8-
9-
#define F2(...) f(0 __VA_OPT__(,) __VA_ARGS__)
10-
#define EMP
11-
2: F2(EMP)
12-
// CHECK: 2: f(0 )
13-
14-
#define H3(X, ...) #__VA_OPT__(X##X X##X)
15-
3: H3(, 0)
16-
// CHECK: 3: ""
17-
18-
#define H4(X, ...) __VA_OPT__(a X ## X) ## b
19-
4: H4(, 1)
20-
// CHECK: 4: a b
21-
22-
#define H4B(X, ...) a ## __VA_OPT__(X ## X b)
23-
4B: H4B(, 1)
24-
// CHECK: 4B: a b
25-
26-
#define H5A(...) __VA_OPT__()/**/__VA_OPT__()
27-
#define H5B(X) a ## X ## b
28-
#define H5C(X) H5B(X)
29-
5: H5C(H5A())
30-
// CHECK: 5: ab
1+
RUN: %clang_cc1 -E %s -pedantic -std=c++2a | FileCheck -strict-whitespace %s
2+
3+
#define LPAREN() (
4+
#define G(Q) 42
5+
#define F1(R, X, ...) __VA_OPT__(G R X) )
6+
1: int x = F1(LPAREN(), 0, <:-);
7+
// CHECK: 1: int x = 42;
8+
9+
#define F2(...) f(0 __VA_OPT__(,) __VA_ARGS__)
10+
#define EMP
11+
2: F2(EMP)
12+
// CHECK: 2: f(0 )
13+
14+
#define H3(X, ...) #__VA_OPT__(X##X X##X)
15+
3: H3(, 0)
16+
// CHECK: 3: ""
17+
18+
#define H4(X, ...) __VA_OPT__(a X ## X) ## b
19+
4: H4(, 1)
20+
// CHECK: 4: a b
21+
22+
#define H4B(X, ...) a ## __VA_OPT__(X ## X b)
23+
4B: H4B(, 1)
24+
// CHECK: 4B: a b
25+
26+
#define H5A(...) __VA_OPT__()/**/__VA_OPT__()
27+
#define H5B(X) a ## X ## b
28+
#define H5C(X) H5B(X)
29+
5: H5C(H5A())
30+
// CHECK: 5: ab
31+
32+
namespace GH60268 {
33+
#define H6(X, ...) __VA_OPT__(a ## X) ## b
34+
6: H6(, 1);
35+
// CHECK: 6: ab
36+
}

0 commit comments

Comments
 (0)