[PATCH] D142604: [Clang] Fix __VA_OPT__ implementation so that it treats the concatenation of a non-placemaker token and placemaker token as a non-placemaker token
Shafik Yaghmour via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Jan 25 22:32:34 PST 2023
shafik created this revision.
shafik added reviewers: aaron.ballman, erichkeane, hubert.reinterpretcast.
Herald added a project: All.
shafik requested review of this revision.
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: https://github.com/llvm/llvm-project/issues/60268
https://reviews.llvm.org/D142604
Files:
clang/lib/Lex/TokenLexer.cpp
clang/test/Preprocessor/macro_vaopt_p1042r1.cpp
Index: clang/test/Preprocessor/macro_vaopt_p1042r1.cpp
===================================================================
--- clang/test/Preprocessor/macro_vaopt_p1042r1.cpp
+++ clang/test/Preprocessor/macro_vaopt_p1042r1.cpp
@@ -28,3 +28,9 @@
#define H5C(X) H5B(X)
5: H5C(H5A())
// CHECK: 5: ab
+
+namespace GH60268 {
+#define H6(X, ...) __VA_OPT__(a ## X) ## b
+6: H6(, 1);
+// CHECK: 6: ab
+}
Index: clang/lib/Lex/TokenLexer.cpp
===================================================================
--- clang/lib/Lex/TokenLexer.cpp
+++ clang/lib/Lex/TokenLexer.cpp
@@ -501,7 +501,7 @@
assert(VCtx.isInVAOpt() && "should only happen inside a __VA_OPT__");
VCtx.hasPlaceholderAfterHashhashAtStart();
}
- if (RParenAfter)
+ else if (RParenAfter)
VCtx.hasPlaceholderBeforeRParen();
}
continue;
@@ -567,7 +567,7 @@
continue;
}
- if (RParenAfter)
+ if (RParenAfter && !NonEmptyPasteBefore)
VCtx.hasPlaceholderBeforeRParen();
// If this is on the RHS of a paste operator, we've already copied the
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D142604.492335.patch
Type: text/x-patch
Size: 1101 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230126/fc99400b/attachment-0001.bin>
More information about the cfe-commits
mailing list