ychen created this revision.
ychen added reviewers: rsmith, Mordante.
ychen requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Down the path, if there is a implicit instantiation, this may trigger
the assertion "Member specialization must be an explicit specialization"
in `clang::FunctionDecl::setFunctionTemplateSpecialization`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D113245

Files:
  clang/lib/Sema/SemaDecl.cpp
  clang/test/CXX/temp/temp.spec/temp.expl.spec/p20.cpp


Index: clang/test/CXX/temp/temp.spec/temp.expl.spec/p20.cpp
===================================================================
--- clang/test/CXX/temp/temp.spec/temp.expl.spec/p20.cpp
+++ clang/test/CXX/temp/temp.spec/temp.expl.spec/p20.cpp
@@ -13,11 +13,16 @@
   friend class A<float>; // okay
 };
 
+template<typename T>
 struct PR41792 {
   // expected-error@+1{{cannot declare an explicit specialization in a friend}}
-  template <> friend void f<>(int);
+  template <> friend void f<>(int) {}
 
   // expected-error@+2{{template specialization declaration cannot be a 
friend}}
   // expected-error@+1{{too few template arguments for class template 'A'}}
   template <> friend class A<>;
 };
+
+void foo(void) {
+    PR41792<int> a;
+}
Index: clang/lib/Sema/SemaDecl.cpp
===================================================================
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -9188,6 +9188,7 @@
             << Name << RemoveRange
             << FixItHint::CreateRemoval(RemoveRange)
             << FixItHint::CreateInsertion(InsertLoc, "<>");
+          NewFD->setInvalidDecl();
         }
       }
     } else {


Index: clang/test/CXX/temp/temp.spec/temp.expl.spec/p20.cpp
===================================================================
--- clang/test/CXX/temp/temp.spec/temp.expl.spec/p20.cpp
+++ clang/test/CXX/temp/temp.spec/temp.expl.spec/p20.cpp
@@ -13,11 +13,16 @@
   friend class A<float>; // okay
 };
 
+template<typename T>
 struct PR41792 {
   // expected-error@+1{{cannot declare an explicit specialization in a friend}}
-  template <> friend void f<>(int);
+  template <> friend void f<>(int) {}
 
   // expected-error@+2{{template specialization declaration cannot be a friend}}
   // expected-error@+1{{too few template arguments for class template 'A'}}
   template <> friend class A<>;
 };
+
+void foo(void) {
+    PR41792<int> a;
+}
Index: clang/lib/Sema/SemaDecl.cpp
===================================================================
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -9188,6 +9188,7 @@
             << Name << RemoveRange
             << FixItHint::CreateRemoval(RemoveRange)
             << FixItHint::CreateInsertion(InsertLoc, "<>");
+          NewFD->setInvalidDecl();
         }
       }
     } else {
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
  • [PATCH] D113245: [Sema] Mark... Yuanfang Chen via Phabricator via cfe-commits

Reply via email to