rZhBoYao updated this revision to Diff 417648. rZhBoYao edited the summary of this revision. rZhBoYao set the repository for this revision to rG LLVM Github Monorepo. rZhBoYao added a comment.
Added an entry in release notes. Waiting for CI... Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D115248/new/ https://reviews.llvm.org/D115248 Files: clang/docs/ReleaseNotes.rst clang/lib/Sema/SemaDeclCXX.cpp clang/test/SemaCXX/PR28101.cpp Index: clang/test/SemaCXX/PR28101.cpp =================================================================== --- /dev/null +++ clang/test/SemaCXX/PR28101.cpp @@ -0,0 +1,36 @@ +// 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}} + +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}} +}; +// Don't crash. +B<int> instantiate2() { return {nullptr}; } // expected-note{{in instantiation of template class 'B<int>' requested here}} + +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}} Index: clang/lib/Sema/SemaDeclCXX.cpp =================================================================== --- clang/lib/Sema/SemaDeclCXX.cpp +++ 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()) { Index: clang/docs/ReleaseNotes.rst =================================================================== --- clang/docs/ReleaseNotes.rst +++ clang/docs/ReleaseNotes.rst @@ -69,6 +69,9 @@ like ``auto&`` or ``auto**`` were added. These constraints are now checked. This fixes `Issue 53911 <https://github.com/llvm/llvm-project/issues/53911>`_ and `Issue 54443 <https://github.com/llvm/llvm-project/issues/54443>`_. +- Previously invalid member variables with template parameters would crash clang. + Now fixed by setting identifiers for them. + This fixes `Issue 28475 (PR28101) <https://github.com/llvm/llvm-project/issues/28475>`_. Improvements to Clang's diagnostics ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Index: clang/test/SemaCXX/PR28101.cpp =================================================================== --- /dev/null +++ clang/test/SemaCXX/PR28101.cpp @@ -0,0 +1,36 @@ +// 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}} + +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}} +}; +// Don't crash. +B<int> instantiate2() { return {nullptr}; } // expected-note{{in instantiation of template class 'B<int>' requested here}} + +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}} Index: clang/lib/Sema/SemaDeclCXX.cpp =================================================================== --- clang/lib/Sema/SemaDeclCXX.cpp +++ 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()) { Index: clang/docs/ReleaseNotes.rst =================================================================== --- clang/docs/ReleaseNotes.rst +++ clang/docs/ReleaseNotes.rst @@ -69,6 +69,9 @@ like ``auto&`` or ``auto**`` were added. These constraints are now checked. This fixes `Issue 53911 <https://github.com/llvm/llvm-project/issues/53911>`_ and `Issue 54443 <https://github.com/llvm/llvm-project/issues/54443>`_. +- Previously invalid member variables with template parameters would crash clang. + Now fixed by setting identifiers for them. + This fixes `Issue 28475 (PR28101) <https://github.com/llvm/llvm-project/issues/28475>`_. Improvements to Clang's diagnostics ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits