[PATCH] D115248: [Clang] Fix PR28101
PoYao Chang via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Mar 23 08:30:57 PDT 2022
rZhBoYao updated this revision to Diff 417632.
rZhBoYao marked 3 inline comments as done.
rZhBoYao added a comment.
This passes check-clang-semacxx on my machine.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D115248/new/
https://reviews.llvm.org/D115248
Files:
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()) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D115248.417632.patch
Type: text/x-patch
Size: 2088 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220323/bd4c1df8/attachment.bin>
More information about the cfe-commits
mailing list