-
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
Clang gives an error when using recursion in a concept #55875
Comments
I think this is an MSVC bug. Note that GCC rejects the code as well. This is because you can't have recursion in concepts. GCC and Clang are correct to reject this code, though the error message could be improved to state something to the effect of not allowing recursion in concepts. BTW, there's no need for using recursion at all in this concept since we can use fold expressions. See https://godbolt.org/z/GTsbj9c4x for an example. |
@llvm/issue-subscribers-clang-frontend |
Yes, I know about fold-expressions. I noticed that it's possible to write this using a fold-expression after I originally wrote it.
But still, that moment seemed weird to me. I don't know what the standard says about it. But from my point of view, this code looks logical and should compile. |
"Looks logical" and "should compile" don't always overlap. :) This StackOverflow answer gives a good explanation of why it's not allowed. Additionally, instead of fold expressions, more generally speaking, concepts can be written in terms of type traits which can be recursive. See this StackOverflow answer for an example. |
The case they're talking about there is completely different than it's here. Recursion here is controlled with an expression in the ternary operator that will sometime become false. Consequently, infinity is out of the question. Also, the expression here is complete because the conditions are known at the time of compilation. Also, you can catch me on the point that the ternary operator is not a |
@JoeLoser btw, what do you think of this code? MSVC: https://godbolt.org/z/YvcPov3Te
This error looks very ridiculous. Will someone explain to me what it means? |
@llvm/issue-subscribers-c-20 Author: None (s2s-k)
MSVC: https://godbolt.org/z/M9YKEq6df
Clang: https://godbolt.org/z/rMM61PKKx
I think the compiler gives this error for no reason, because "IsAnyType" has already been declared. Also, Microsoft's compiler compiles this code well. |
The original code is reject by clang/gcc/edg/MVSC: https://godbolt.org/z/rc49hEzcd now The new example is rejected by gcc/clang and accepted by edg/MSVC: https://godbolt.org/z/jrs75nahY Not sure who is correct, but we should probably open a second bug report for this since it looks like a different problem and does not look related to the original one. |
Per [basic.scope], the locus of a concept is immediately adfter the introduction of its name. This let us provide better diagnostics for attempt to define recursive concepts. Note that recursive concepts are not supported per https://eel.is/c++draft/basic#scope.pdecl-note-3, but there is no normative wording for that restriction. This is a known defect introduced by [p1787r6](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/p1787r6.html). Fixes llvm#55875
Per [basic.scope], the locus of a concept is immediately adfter the introduction of its name. This let us provide better diagnostics for attempt to define recursive concepts. Note that recursive concepts are not supported per https://eel.is/c++draft/basic#scope.pdecl-note-3, but there is no normative wording for that restriction. This is a known defect introduced by [p1787r6](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/p1787r6.html). Fixes llvm#55875
Per [basic.scope], the locus of a concept is immediately after the introduction of its name. This let us provide better diagnostics for attempt to define recursive concepts. Note that recursive concepts are not supported per https://eel.is/c++draft/basic#scope.pdecl-note-3, but there is no normative wording for that restriction. This is a known defect introduced by [p1787r6](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/p1787r6.html). Fixes #55875
Per [basic.scope], the locus of a concept is immediately after the introduction of its name. This let us provide better diagnostics for attempt to define recursive concepts. Note that recursive concepts are not supported per https://eel.is/c++draft/basic#scope.pdecl-note-3, but there is no normative wording for that restriction. This is a known defect introduced by [p1787r6](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/p1787r6.html). Fixes llvm#55875
MSVC: https://godbolt.org/z/M9YKEq6df
Clang: https://godbolt.org/z/rMM61PKKx
error: use of undeclared identifier 'IsAnyType'
I think the compiler gives this error for no reason, because "IsAnyType" has already been declared. Also, Microsoft's compiler compiles this code well.
The text was updated successfully, but these errors were encountered: