[PATCH] D35782: [C++2a][Preprocessor] Implement p0306 __VA_OPT__ (Comma omission and comma deletion)
Faisal Vali via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sun Jul 23 20:48:19 PDT 2017
faisalv created this revision.
faisalv added a project: clang.
This patch implements an extension to the preprocessor: __VA_OPT__ which expands into its contents if variadic arguments are supplied, or behaves as an empty token if none.
- currently it is only enabled for C++2a (we could always enable this for various other dialects with the appropriate extension or compatibility warnings)
Given:
#define F(a,...) a #__VA_OPT__(a ## a) a ## __VA_OPT__(__VA_ARGS__)
A few technicalities (most which were clarified through private correspondence between rsmith, hubert and thomas) are worth mentioning:
- the call F(,) Does not supply any tokens for the variadic arguments and hence __VA_OPT__ behaves as a placeholder
- when expanding VA_OPT (for e.g. F(,1) token pasting occurs eagerly within its contents
- a hash or a hashhash prior to __VA_OPT__ does not inhibit expansion of arguments if they are the first token within VA_OPT.
- essentially, when a variadic argument is supplied, argument substitution occurs within the contents as does stringification and concatenation - and this is substituted, potentially strinigified and concatenated content (but not rescanned) is inserted into the macro expansions token stream just prior to the entire stream being rescanned and concatenated.
See wg21.link/P0306 for further details.
See the example files for more involved examples.
Would greatly appreciate timely feedback =)
Repository:
rL LLVM
https://reviews.llvm.org/D35782
Files:
include/clang/Basic/DiagnosticLexKinds.td
include/clang/Lex/Preprocessor.h
include/clang/Lex/TokenLexer.h
include/clang/Lex/VariadicMacroSupport.h
lib/Lex/PPDirectives.cpp
lib/Lex/Preprocessor.cpp
lib/Lex/TokenLexer.cpp
test/Preprocessor/macro_vaopt_check.cpp
test/Preprocessor/macro_vaopt_expand.cpp
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D35782.107846.patch
Type: text/x-patch
Size: 35029 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170724/3d9c4014/attachment-0001.bin>
More information about the cfe-commits
mailing list