[PATCH] D114439: [Annotation] Allow parameter pack expansions in annotate attribute

Steffen Larsen via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Dec 8 02:50:48 PST 2021


steffenlarsen added inline comments.


================
Comment at: clang/lib/Parse/ParseDecl.cpp:447
             Actions.CorrectDelayedTyposInExpr(ParseAssignmentExpression()));
+
+        if (Tok.is(tok::ellipsis)) {
----------------
erichkeane wrote:
> So I was thinking about this overnight... I wonder if this logic is inverted here?  Aaron can better answer, but I wonder if we should be instead detecting when we are on the 'last' parameter and it is one of these `VariadicExprArgument` things (that accept a pack), then dropping the parser into a loop of:
> 
> while (Tok.is(tok::comma)){
>   Tok.Consume();
>   ArgExpr = CorrectTypos(ParseAssignmentExpr(...));
> }
> // finally, consume the closing paren.
> 
> WDYT?
The parsing of attribute arguments is already this lenient. It does not actually care how many arguments the attribute says it takes (unless it takes a type and then it will only currently supply _one_ argument). It simply consumes as many expressions it can before reaching the end parenthesis, then leaves the attributes to consume them in `clang/lib/Sema/SemaDeclAttr.cpp`.
As a result we do not need any additional work here to handle variadic arguments, but it also means that we have to introduce the restrictions that we can only allow packs in the last argument and allow only that argument to be variadic, as otherwise we have no way of knowing when and where the packs pass between argument boundaries.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D114439/new/

https://reviews.llvm.org/D114439



More information about the cfe-commits mailing list