[PATCH] D69481: [Sema] Fixes templated friend member assertion

Mark de Wever via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Oct 27 12:11:27 PDT 2019


Mordante created this revision.
Mordante added reviewers: rjmccall, rsmith, aaron.ballman.
Mordante added a project: clang.
Mordante added a subscriber: rtrieu.

Fixes https://bugs.llvm.org/show_bug.cgi?id=41792


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D69481

Files:
  clang/lib/Sema/SemaTemplate.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
@@ -3,7 +3,7 @@
 void f(T);
 
 template<typename T>
-struct A { };
+struct A { }; // expected-note{{template is declared here}}
 
 struct X {
   template<> friend void f<int>(int); // expected-error{{in a friend}}
@@ -12,3 +12,12 @@
   friend void f<float>(float); // okay
   friend class A<float>; // okay
 };
+
+struct PR41792 {
+  // expected-error at +1{{cannot declare an explicit specialization in a friend}}
+  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<>;
+};
Index: clang/lib/Sema/SemaTemplate.cpp
===================================================================
--- clang/lib/Sema/SemaTemplate.cpp
+++ clang/lib/Sema/SemaTemplate.cpp
@@ -2549,6 +2549,9 @@
 /// list.
 static bool
 DependsOnTemplateParameters(QualType T, TemplateParameterList *Params) {
+  if (!Params->size())
+    return false;
+
   DependencyChecker Checker(Params, /*IgnoreNonTypeDependent*/false);
   Checker.TraverseType(T);
   return Checker.Match;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D69481.226580.patch
Type: text/x-patch
Size: 1357 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20191027/9232c0e6/attachment.bin>


More information about the cfe-commits mailing list