https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101782

--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
(In reply to Jonathan Wakely from comment #1)
> This is a C++ FE bug.
> 
> This valid C++20 code:
> 
> template<typename T> concept foo = true;
> 
> template<typename T> requires foo<T>
> [[nodiscard]]
> int bar(T) { return 1; }
> 
> is rejected with the -fconcepts-ts flag (as both C++20 and C++17):
> 
> conc.C:4:1: error: two consecutive ‘[’ shall only introduce an attribute
> before ‘[’ token
>     4 | [[nodiscard]]
>       | ^
> 
> For C++17 mode, -fconcepts-ts defines __cpp_concepts=201507L so we could use
> that to suppress the [[nodiscard]] attributes when the flag is given.
> 
> But we can't detect it for C++20 mode (which is when the testsuite errors
> happen) because C++20 defines __cpp_concepts=201907L and -fconcepts-ts
> doesn't change that. So I'm not sure what we can do, other than not apply
> the attribute to constrained functions with a requires-clause.

This is because with -fconcepts-ts the requires-clause argument is parsed as
logical-or-expression rather than constraint-logical-or-expression and for the
former the [ could be part of postfix-expression in there.  Bet that is the
reason why constraint-logical-or-expression exists and allows only
primary-expressions mixed with ||s and &&s.
Perhaps the FE could have a hack, set some parser flag when parsing
requires-clause and in postfix-expression parsing if that flag is set instead
of the [[ error in there pretend [ is not there and ends the expression.

Reply via email to