-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
wrong management of parameter substitution in a concept-id #122971
Comments
@llvm/issue-subscribers-clang-frontend Author: None (mrussoLuxoft)
In the code reported below: (https://godbolt.org/z/TYKhzqhEf)
there are three couples of overloaded function templates, with different constraints. However, func1<std::set<int>{}> leads to an error for Clang and gcc, due to the second overload, because lambda expressions are not immediate context. This is correctly related to the following standard text (current draft): [expr.prim.req.general] - p5: [temp.constr.atomic] - p3: [temp.deduct.general] - p9: However, for func1b<std:::set<int>{}>, gcc and Clang behave differently. Indeed, Clang still considers the error in lambda expression code, whereas gcc ignores it because this time the concept Cb does not use its parameters, relying on the following standard text: [temp.constr.normal] - p(1.4): which means that the substitution leads to no error if a parameter is not used. I initially supposed this was an error for gcc, and posted a potential bug for gcc here, but that discussion led to understand that's a problem of Clang.
|
In the code reported below: (https://godbolt.org/z/TYKhzqhEf)
there are three couples of overloaded function templates, with different constraints.
Let's say that in the couples of func1 and func2, the first overload is designed to
work with std::set and the second with std::map.
However, func1<std::set{}> leads to an error for Clang and gcc, due to the second overload, because lambda expressions are not immediate context.
This is correctly related to the following standard text (current draft):
[expr.prim.req.general] - p5:
"... can result in the formation of invalid types or expressions in the immediate context of its requirements ... In such cases, the requires-expression evaluates to false; it does not cause the program to be ill-formed."
[temp.constr.atomic] - p3:
"To determine if an atomic constraint is satisfied, the parameter mapping and template arguments are first substituted into its expression. If substitution results in an invalid type or expression in the immediate context of the atomic constraint, the constraint is not satisfied. ... "
[temp.deduct.general] - p9:
"When substituting into a lambda-expression, substitution into its body is not in the immediate context. ..."
However, for func1b<std:::set{}>, gcc and Clang behave differently. Indeed, Clang still considers the error in lambda expression code, whereas gcc ignores it because this time the concept Cb does not use its parameters, relying on the following standard text:
[temp.constr.normal] - p(1.4):
"The normal form of a concept-id C<A1 , A2 , ..., An > is the normal form of the constraint-expression of C, after substituting A1 , A2 , ..., An for C’s respective template parameters in the parameter mappings in each atomic constraint. ..."
which means that the substitution leads to no error if a parameter is not used.
I initially supposed this was an error for gcc, and posted a potential bug for gcc here, but that discussion led to understand that's a problem of Clang.
gcc guys seemed to remember a known problem of Clang, but I tried to search with keywords 'concept', 'parameter', and others, and I could not find it. Hope I am not duplicating.
The text was updated successfully, but these errors were encountered: