On Wed, Dec 15, 2021 at 04:17:37PM -0500, Jason Merrill wrote: > On 12/15/21 15:20, Marek Polacek wrote: > > On Mon, Dec 13, 2021 at 10:02:24AM -0500, Jason Merrill wrote: > > > On 12/10/21 17:29, Marek Polacek wrote: > > > > My r11-2202 was trying to enforce [dcl.type.auto.deduct]/4, which says > > > > "If the placeholder-type-specifier is of the form type-constraint[opt] > > > > decltype(auto), T shall be the placeholder alone." But this made us > > > > reject 'constexpr decltype(auto)', which, after clarification from CWG, > > > > should be valid. [dcl.type.auto.deduct]/4 is supposed to be a syntactic > > > > constraint, not semantic, so it's OK that the constexpr marks the object > > > > as const. > > > > > > > > As a consequence, checking TYPE_QUALS in do_auto_deduction is too late, > > > > and we have a FIXME there anyway. So in this patch I'm attempting to > > > > detect 'const decltype(auto)' earlier. If I'm going to use TYPE_QUALS, > > > > it needs to happen before we mark the object as const due to constexpr, > > > > that is, before grokdeclarator's > > > > > > > > /* A `constexpr' specifier used in an object declaration declares > > > > the object as `const'. */ > > > > if (constexpr_p && innermost_code != cdk_function) > > > > ... > > > > > > > > Constrained decltype(auto) was a little problem, hence the TYPENAME > > > > check. But in a typename context you can't use decltype(auto) anyway, > > > > I think. > > > > > > I wonder about checking even earlier, like in > > > cp_parser_decl_specifier_seq? > > > > That _almost_ works except it wouldn't detect things like 'decltype(auto)*' > > because the '*' isn't parsed in cp_parser_decl_specifier_seq, only in > > declarator. So the > > Ah, right. > > > if (a != type) > > { > > error_at (loc, "%qT as type rather than plain " > > "%<decltype(auto)%>", type); > > > > check wouldn't work. Maybe I could just check if the next token is * or & > > and give an error then. > > No, checking in grokdeclarator makes sense. > > > Constrained decltype(auto) was a little problem, hence the TYPENAME > > check. But in a typename context you can't use decltype(auto) anyway, > > I think. > > Maybe check PLACEHOLDER_TYPE_CONSTRAINTS in check_decltype_auto instead?
I've tried that, but that is also true for const constexpr C decltype(auto) x2 = 0; const constexpr C decltype(auto) fn4() { return 0; } where we do want to check if the auto has quals. Therefore the not very pretty TYPENAME check :/. Marek