[PATCH] D115248: [Clang] Fix PR28101
PoYao Chang via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Mar 23 09:39:27 PDT 2022
This revision was automatically updated to reflect the committed changes.
Closed by commit rG355f1c75aa66: [Clang] Fix PR28101 (authored by rZhBoYao).
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
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D115248.417664.patch
Type: text/x-patch
Size: 2807 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220323/b6e3f7f7/attachment.bin>
More information about the cfe-commits
mailing list