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-16 regression] Declaration of a constrained friend class inside of a class template causes compile error #61763
Comments
@llvm/issue-subscribers-clang-frontend |
Confirmed, looks like we had a similar issue but it no longer reproduces: #50643 I think the friend is messing up this particular case. |
@erichkeane Looks like babdef2 probably fixed the first case but not this one. |
Right, there is work being done on trunk, there is a review up on phab (which I cannot seem to find!) that redoes how a lot of this works, but @zygoloid had a bunch of comments, so we're waiting on him to review. |
The given example can be worked around by adding a forward declaration of template<typename T>
concept ok = true;
struct outer {
template<typename T>
requires ok<T>
struct foo {};
};
template<typename U>
struct bar {
template<typename T>
requires ok<T>
friend struct outer::foo;
};
bar<int> x;
|
This issue appears to prevent Clang from compiling parts of ranges in libstdc++. In particular, there's a constrained friend declaration in zip_transform_view that causes issues. I tried massaging libstdc++'s implementation, and unfortunately the forward declaration workaround does not seem to work here. |
So the problem here is that we're doing no work to try to make these two 'equal' despite their different depths because we aren't including the associated declaration. This is because we're using the We probably have to try harder there to figure out what the correct declaration these are associated with are. |
MSVCSTL makes some private parts public to workaround this issue: |
One of the more difficult problems in |
An ALTERNATIVE is to find a way to implement |
I ended up deciding that we could figure out how to do the substitution with just the decl-context, so I submitted a patch to support that in this case. WE might end up having a few other cases like this we have to deal with in the future, but this ends up fixing both repros in this issue. |
…69244) Out of line class template declaration specializations aren't created at the time they have their template arguments checked, so we previously weren't doing any amount of work to substitute the constraints before comparison. This resulted in the out of line definition's difference in 'depth' causing the constraints to compare differently. This patch corrects that. Additionally, it handles ClassTemplateDecl when collecting template arguments. Fixes: #61763
Clang 16 and further reject this program with the following error message:
Clang versions 11-15 work as expected, though.
Compiler Explorer link: https://godbolt.org/z/erGavP1za.
GCC also had a similar bug at some point: 93467.
The text was updated successfully, but these errors were encountered: