Please use GitHub pull requests for new patches. Phabricator shutdown timeline
Changeset View
Standalone View
clang/test/SemaCXX/PR28101.cpp
- This file was added.
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++17 %s | |||||
template <typename T> struct A { | |||||
A(void *) {} | |||||
T(A<T>){}; // expected-error{{member 'A' cannot have template arguments}}\ | |||||
// expected-error2{{member 'A' has the same name as its class}} | |||||
}; | |||||
// Don't crash. | |||||
A<int> instantiate1() { return {nullptr}; } // expected-note{{in instantiation of template class 'A<int>' requested here}} | |||||
erichkeane: This isn't necessary, the compiler in verify mode should see all errors. I see above at most 2… | |||||
Instantiation of each of the 4 classes could crash on its own, so I thought I'd separate them into 4 invocations. rZhBoYao: Instantiation of each of the 4 classes could crash on its own, so I thought I'd separate them… | |||||
They shouldn't crash afterwards, right? So this shouldn't be a problem. erichkeane: They shouldn't crash afterwards, right? So this shouldn't be a problem. | |||||
template <typename T> struct B { | |||||
B(void *) {} | |||||
T B<T>{}; // expected-error{{member 'B' cannot have template arguments}}\ | |||||
// expected-error2{{member 'B' has the same name as its class}} | |||||
Not Done ReplyInline ActionsThis second error here is strange, I don't see it as particularly useful here. I see gcc at least gives the full name (int A<int>::A), perhaps that makes this more useful? erichkeane: This second error here is strange, I don't see it as particularly useful here.
I see gcc at… | |||||
}; | |||||
// Don't crash. | |||||
B<int> instantiate2() { return {nullptr}; } // expected-note{{in instantiation of template class 'B<int>' requested here}} | |||||
How come there are no notes in this test that say 'in instantiation of...'? I would expect those in at least some of these cases, right? erichkeane: How come there are no notes in this test that say 'in instantiation of...'? I would expect… | |||||
Because it was caught before instantiation and when instantiating the FieldDecl is gone after calling D.setInvalidType();. If I set the identifier for the FieldDecl and let CheckCompletedCXXClass handle the "has the same name as its class" error, there will be the "in instantiation of..." note. rZhBoYao: Because it was caught before instantiation and when instantiating the FieldDecl is gone after… | |||||
I think we definitely need to do so there, the instantiation trace not being here makes this a much less useful diagnostic. erichkeane: I think we definitely need to do so there, the instantiation trace not being here makes this a… | |||||
template <typename T> struct S {}; | |||||
template <typename T> struct C { | |||||
C(void *) {} | |||||
T S<T>{}; // expected-error{{member 'S' cannot have template arguments}} | |||||
}; | |||||
// Don't crash. | |||||
C<int> instantiate3() { return {nullptr}; } | |||||
template <typename T, template <typename> typename U> class D { | |||||
public: | |||||
D(void *) {} | |||||
T(D<T, U<T>>) {} // expected-error{{member 'D' cannot have template arguments}}\ | |||||
// expected-error{{expected ';' at end of declaration list}}\ | |||||
// expected-error2{{member 'D' has the same name as its class}} | |||||
}; | |||||
// Don't crash. | |||||
D<int, S> instantiate4() { return D<int, S>(nullptr); } // expected-note{{in instantiation of template class 'D<int, S>' requested here}} |
This isn't necessary, the compiler in verify mode should see all errors. I see above at most 2 invocations of the compiler as necessary.