diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -69,6 +69,9 @@ like ``auto&`` or ``auto**`` were added. These constraints are now checked. This fixes `Issue 53911 `_ and `Issue 54443 `_. +- Previously invalid member variables with template parameters would crash clang. + Now fixed by setting identifiers for them. + This fixes `Issue 28475 (PR28101) `_. Improvements to Clang's diagnostics ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp --- a/clang/lib/Sema/SemaDeclCXX.cpp +++ b/clang/lib/Sema/SemaDeclCXX.cpp @@ -3427,6 +3427,7 @@ << SourceRange(D.getName().TemplateId->LAngleLoc, D.getName().TemplateId->RAngleLoc) << D.getName().TemplateId->LAngleLoc; + D.SetIdentifier(Name.getAsIdentifierInfo(), Loc); } if (SS.isSet() && !SS.isInvalid()) { diff --git a/clang/test/SemaCXX/PR28101.cpp b/clang/test/SemaCXX/PR28101.cpp new file mode 100644 --- /dev/null +++ b/clang/test/SemaCXX/PR28101.cpp @@ -0,0 +1,36 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++17 %s + +template struct A { + A(void *) {} + T(A){}; // expected-error{{member 'A' cannot have template arguments}}\ + // expected-error2{{member 'A' has the same name as its class}} +}; +// Don't crash. +A instantiate1() { return {nullptr}; } // expected-note{{in instantiation of template class 'A' requested here}} + +template struct B { + B(void *) {} + T B{}; // expected-error{{member 'B' cannot have template arguments}}\ + // expected-error2{{member 'B' has the same name as its class}} +}; +// Don't crash. +B instantiate2() { return {nullptr}; } // expected-note{{in instantiation of template class 'B' requested here}} + +template struct S {}; + +template struct C { + C(void *) {} + T S{}; // expected-error{{member 'S' cannot have template arguments}} +}; +// Don't crash. +C instantiate3() { return {nullptr}; } + +template typename U> class D { +public: + D(void *) {} + T(D>) {} // 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 instantiate4() { return D(nullptr); } // expected-note{{in instantiation of template class 'D' requested here}}