[PATCH] D113245: [Sema] Mark explicit specialization declaration in a friend invalid

Yuanfang Chen via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Nov 5 00:22:04 PDT 2021


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 at +1{{cannot declare an explicit specialization in a friend}}
-  template <> friend void f<>(int);
+  template <> friend void f<>(int) {}
 
   // expected-error at +2{{template specialization declaration cannot be a friend}}
   // expected-error at +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 {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D113245.384976.patch
Type: text/x-patch
Size: 1151 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20211105/bb80dc1a/attachment.bin>


More information about the cfe-commits mailing list