[PATCH] D115248: [Clang] Fix PR28101

PoYao Chang via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Mar 22 20:10:11 PDT 2022


rZhBoYao updated this revision to Diff 417475.
rZhBoYao added a comment.

Don't break template declarations.
re-clang-format


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,50 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -DCASE_1 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -DCASE_2 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -DCASE_3 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -DCASE_4 -std=c++17 %s
+
+// Don't crash.
+
+#ifdef CASE_1
+
+template <typename T> struct A {
+  A(void *) {}
+  T(A<T>){}; // expected-error{{member 'A' cannot have template arguments}}
+};
+
+A<int> instantiate() { return {nullptr}; }
+
+#elifdef CASE_2
+
+template <typename T> struct A {
+  A(void *) {}
+  T A<T>{}; // expected-error{{member 'A' cannot have template arguments}}
+};
+
+A<int> instantiate() { return {nullptr}; }
+
+#elifdef CASE_3
+
+template <typename T> struct S {};
+
+template <typename T> struct A {
+  A(void *) {}
+  T S<T>{}; // expected-error{{member 'S' cannot have template arguments}}
+};
+
+A<int> instantiate() { return {nullptr}; }
+
+#elifdef CASE_4
+
+template <typename T, template <typename> typename U> class A {
+public:
+  A(void *) {}
+  T(A<T, U<T>>) {} // expected-error{{member 'A' cannot have template arguments}}\
+  // expected-error{{expected ';' at end of declaration list}}
+};
+
+template <typename T> struct S {};
+
+A<int, S> foo() { return A<int, S>(nullptr); }
+
+#endif
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.setInvalidType();
     }
 
     if (SS.isSet() && !SS.isInvalid()) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D115248.417475.patch
Type: text/x-patch
Size: 1854 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220323/6af4fe54/attachment.bin>


More information about the cfe-commits mailing list