-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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] [C++20] regression in Clang 16 #60749
Comments
@llvm/issue-subscribers-clang-frontend |
@llvm/issue-subscribers-c-20 |
I can try to make reduced source |
Something looks amiss here to me, but it'd be helpful if we can devise a smaller reproducer than "use boost". |
That would be really helpful for us, thank you for the offer! |
The essence of the bug is something like this, https://godbolt.org/z/ePsa3z9qb template <class T, class... Ts>
concept AlwaysTrue = true;
template <class T>
class A {
template<class S, AlwaysTrue<void(int)> T2>
friend void f(S s, A<S> a, T2&& t);
};
template<class S, AlwaysTrue<void(int)> T2>
void f(S s, A<S> a, T2&& t) {
return;
}
void f2() {
A<int> a;
f(1, a, 3);
} This might be reduced further a bit, I think. We don't reconcile the friend declaration with the definition: we think they're separate functions and then the call is ambiguous. |
Urgh... I looked at #58896 at one point, and couldn't make heads/tails of it at the time. |
Reduced further https://godbolt.org/z/9Ys4G7nWf template <class T>
concept True = true;
template <class T>
class A {
template<True T2>
friend void f(A<T2>);
};
template<True T2>
void f(A<T2>) { return; }
void f2() {
f(A<int>{});
} Interestingly changing |
Okay, I guess reduction is no longer needed 😄 During the process I noticed that Boost 1.71 does not trigger the bug, I guess they moved to concepts somewhere between 1.72 and 1.81. |
So I waited for cvise to complete, here is the result constexpr bool a = 1;
template <typename...>
concept b = a;
enum c {};
template <class> struct A {
template <class h, b<void(int)> g> friend void d(c, A<h> &, g &&);
};
template <class h, b<void(int)> g> void d(c, A<h> &, g &&);
c e;
void f() {
A<int> j;
d(e, j, 0);
} which gives
Looks like the same idea as in your snippet but I am not an expert 🙂 |
@erichkeane - I think this is similar to something you had to do in your deferred concepts patch. From what I could gather, when we compare signatures, There's a code path there that adjusts the depth, but it's called only for template instantiations, not when we coalesce the still uninstantiated template declarations. Any idea for a quick fix here? |
Yeah, I wouldn't be surprised, the 'making the depths equal' thing probably needs to be done if you can calculate it here. I don't have a good idea of a quick fix, we MIGHT have to do something similar, we did some work at one point for partial specializations, though again, I'm not sure if that just needs to be applied here. I originally compared the size given by the getInstantiationArgs function to calculate the depth, but a followup patch by another contributor having to do with partial specializations changed that. |
Now looking at the two, I don't believe these are particularly related? |
So since this is a C++20 only-issue, I don't think this ends up needing to be 'blocking' for the 16.0 release, so I'm opting to not make it do so. |
Dear all, could this issue kindly be considered soon? It breaks building boost in c++20 mode, and boost is quite an essential library :-( :-( |
So all the reductions no work in trunk, just not the initial example. So this once again needs reduction to see what the issue is. The problem is no longer with the beast library (its with basic_string being defined multiple times, and format being non-consteval, so the original problem is fixed. So we need a reduction on those other two errors. |
Clang packages in apt repo are still 16.0.1, I've built 16.0.2 and it still shows same error so the fix is only in 17 branch at the moment. Will build trunk and run reduction with it then. |
Here is the reduced test case for template <typename> struct a;
template <typename... b>
concept c = a<b...>::e;
using d = int;
template <class, bool> struct f { template <c<void(d)>> auto i(); };
template <class g, bool h> template <c<void(d)>> auto f<g, h>::i() {} Clang trunk produces
while Clang 16 does not report errors |
@alexander-shaposhnikov : Another out-of-line concepts bug for you to consider. |
@erichkeane the examples from the comments above seem to compile with https://reviews.llvm.org/D146178 |
Cool, please put this on your list to 'close' when we commit that patch! |
I've bisected the fix of original problem to be 60bee9f — how to ensure it is backported to 16 release? |
Fixed in 60bee9f |
The changes in that commit are large/non-obvious enough that it might not be backported to 16.x (we are conservative about what fixes we backport because we want each point release to be more stable than the last). We usually want those to "bake" a little longer in the tree. That said, if @erichkeane and @alexander-shaposhnikov think this fix is highly likely to be correct and not cause other problems, it is certainly worth considering it. |
As I understand 60bee9f together with https://reviews.llvm.org/D146178 completely fixes compilation of original code so either both should be backported or maybe none at all.
Reasonable, but in current state Clang 16 can't compile valid code from Boost while Clang 15 can. If fixes would not be backported, can you advise how Boost devs can hotfix it on their side? |
After looking at the patch, I think it's safe enough to backport. |
60bee9f was reverted because it causes a number of regressions. The author and I are working through them on D146178, but the changes are significant and there are still a few large hurdles to go through before we can approve D146178. I do NOT think this is safe to backport. While I'm sympathetic to breaking boost like this, this is a part of concepts support, which is still experimental. |
Also, re-opening bug, since the original patch that fixed it was reverted. |
@klemens-morgenstern FYI, seems that something needs to be done from Boost side if we want boostorg/beast#2648 fixed. |
CE links above work with trunk, seems to be fixed. |
Hi, I believe I encountered a regression with Clang 16 and Boost: https://godbolt.org/z/nzePcnGjj
Clang 15 with
--std=c++20
compiles this code fine, Clang 16 with--std=c++17
works fine too but Clang 16 with--std=c++20
reports ambiguous symbol in a place where I can't see any ambiguity:in source code it looks like this:
So the first one is declaration but Clang treats it as implementation?
The text was updated successfully, but these errors were encountered: