cplusplus / CWG

Core Working Group
23 stars 7 forks source link

[temp.constr.decl] Use of parentheses omitted in one of the examples involving constraints #514

Closed ranaanoop closed 3 months ago

ranaanoop commented 3 months ago

Full name of submitter : Anoop Rana

Reference (section label): [temp.constr.decl]

Issue description:

Currently to avoid ambiguity etc we need to add parentheses when using requires-clause with operator. Also the note in temp.pre says:

[ Note: The expression in a requires-clause uses a restricted grammar to avoid ambiguities. Parentheses can be used to specify arbitrary expressions in a requires-clause. [ Example:

template<int N> requires N == sizeof new unsigned short
int f();            // error: parentheses required around == expression

— end example] — end note]

But then in temp.constr.decl one of the example uses the requires-clause with && without parentheses:

template<typename T> concept C1 = true;
template<typename T> concept C2 = sizeof(T) > 0;

template<C1 T> void f4(T) requires C2<T>;
template<typename T> requires C1<T> && C2<T> void f5(T);

As we can see, while declaring f5 the && operator is used in the require-clause without the parentheses but as previously mentioned in temp.pre#8.3, the parentheses should be used.

ranaanoop commented 3 months ago

Actually, as explained here, c++ grammar allows omitting parentheses for || and && but not for other operators. That is, requires has custom behavior for these two operators(|| and &&).