-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Clang Crash When Defining operator<< as a Friend Template Function of a Class Template since clang 20 #139052
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
Labels
clang:frontend
Language frontend issues, e.g. anything involving "Sema"
confirmed
Verified by a second party
crash-on-invalid
regression:20
Regression in 20 release
Comments
Reduced library-free example (Godbolt link): struct FakeStream {};
template <typename T>
class BinaryTree;
template <typename T>
FakeStream& operator<<(FakeStream& os, BinaryTree<T>& b);
template <typename T>
struct BinaryTree {
T* root{};
friend FakeStream& operator<< <T>(FakeStream& os, BinaryTree&) {
return os;
}
};
int main() {
FakeStream fakeout;
BinaryTree<int> a{};
fakeout << a;
} |
@llvm/issue-subscribers-clang-frontend Author: None (mariete1223)
Clang crashes during instantiation of a friend function template declared outside the class when used with BinaryTree<T>. The crash occurs in the function InstantiateFunctionDefinition in clang 20. **Haven´t been able to reduce code more**
Assertion
Stack dump
Program
To quickly reproduceit happens since clang 20 |
llvm-sync bot
pushed a commit
to arm/arm-toolchain
that referenced
this issue
May 14, 2025
…nd specializations (#139436) Since 346077a, we began using the primary template's lexical DeclContext for template arguments in order to properly instantiate a friend definition. There is a missed peculiar case, as in a friend template is specialized within a dependent context. In this scenario, the primary template is not a definition, whereas the specialization is. So the primary template's DeclContext doesn't provide anything meaningful for instantiation. Fixes llvm/llvm-project#139052
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
clang:frontend
Language frontend issues, e.g. anything involving "Sema"
confirmed
Verified by a second party
crash-on-invalid
regression:20
Regression in 20 release
Clang crashes during instantiation of a friend function template declared outside the class when used with BinaryTree. The crash occurs in the function InstantiateFunctionDefinition in clang 20. Haven´t been able to reduce code more
Assertion
Stack dump
Program
To quickly reproduce
it happens since clang 20
https://gcc.godbolt.org/z/WWWqdcbjj
The text was updated successfully, but these errors were encountered: