On Wed, Dec 01, 2021 at 11:24:58PM -0500, Jason Merrill wrote: > On 12/1/21 10:16, Marek Polacek wrote: > > In C++23, auto(x) is valid, so decltype(auto(x)) should also be valid, > > so > > > > void f(decltype(auto(0))); > > > > should be just as > > > > void f(int); > > > > but currently, everytime we see 'auto' in a parameter-declaration-clause, > > we try to synthesize_implicit_template_parm for it, creating a new template > > parameter list. The code above actually has us calling s_i_t_p twice; > > once from cp_parser_decltype_expr -> cp_parser_postfix_expression which > > fails and then again from cp_parser_decltype_expr -> cp_parser_expression. > > So it looks like we have f<auto, auto> and we accept ill-formed code. > > > > So we need to be more careful about synthesizing the implicit template > > parameter. cp_parser_postfix_expression looked like a sensible place. > > Does this cover other uses of auto in decltype, such as > > void f(decltype(new auto{0}));
Yes: the clearing of auto_is_implicit_function_template_parm_p will happen here too. However, I'm noticing this: void f1(decltype(new auto{0})); void f2(decltype(new int{0})); void g () { int i; void f3(decltype(new auto{0})); void f4(decltype(new int{0})); f1 (&i); // error: no matching function for call to f1(int*) // couldn't deduce template parameter auto:1 f2 (&i); f3 (&i); f4 (&i); } I think the error we issue is bogus. (My patch doesn't change this. clang++ accepts.) Should I file a PR (and investigate)? > ? Should we adjust this flag in cp_parser_decltype along with all the other > flags? I think that's possible, but wouldn't cover auto in default arguments, or array bounds. Thanks, Marek