[PATCH] D113393: [c++2b] Implement P0849R8 auto(x)

Richard Smith - zygoloid via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Nov 12 18:04:13 PST 2021

rsmith added inline comments.

Comment at: clang/lib/Parse/ParseDeclCXX.cpp:1032
+      // the typename-specifier in a function-style cast expression may
+      // be 'auto' since C++2b
Quuxplusone wrote:
> rsmith wrote:
> > Nice catch :)
> I see zero hits for `git grep 'decltype[(]auto[^)] clang/`. So it seems this corner of the grammar has been missing any tests for a long time, but I hope this PR will add some.
> ```
> decltype(auto*) i = 42; // should be a syntax error
> decltype(auto(42)) i = 42;  // should be OK 
> decltype(auto()) i = 42;  // should be a syntax error
> ```
> Right now I don't see any tests for this stuff in this PR either. So it needs some.
Some of this is tested in the new file test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.type.auto.deduct/p2.cpp (you might need to expand it manually; full-page search for `decltype(auto(` might otherwise not find it). It looks like we are missing tests for things like `decltype(auto*)`. It's not obvious to me what diagnostic would be most useful if `decltype(auto` is not followed by `)`, `(`, or `{`, but my guess is that "expected `)`" pointing at the `*`, rather than an error on the `auto` token, would be the least surprising. So maybe this should be
if (Tok.is(tok::kw_auto) && NextToken().isNot(tok::l_paren, tok::l_brace)) {

  rG LLVM Github Monorepo



More information about the cfe-commits mailing list