]> granicus.if.org Git - clang/commitdiff
Fix assertion failure for a cv-qualified array as a non-type template
authorRichard Smith <richard-llvm@metafoo.co.uk>
Fri, 11 Oct 2019 01:29:53 +0000 (01:29 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Fri, 11 Oct 2019 01:29:53 +0000 (01:29 +0000)
parameter type.

We were both failing to decay the array type to a pointer and failing to
remove the top-level cv-qualifications. Fix this by decaying array
parameters even if the parameter type is dependent.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@374496 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaTemplate.cpp
test/SemaTemplate/temp_arg_nontype.cpp

index 62dc17254c7109a93d920cd4d41247c2ca9c3b71..284962f3e07cab0ba78759daa9c5cc7dc3b9a06b 100644 (file)
@@ -1099,9 +1099,6 @@ QualType Sema::CheckNonTypeTemplateParameterType(QualType T,
       T->isMemberPointerType() ||
       //   -- std::nullptr_t.
       T->isNullPtrType() ||
-      // If T is a dependent type, we can't do the check now, so we
-      // assume that it is well-formed.
-      T->isDependentType() ||
       // Allow use of auto in template parameter declarations.
       T->isUndeducedType()) {
     // C++ [temp.param]p5: The top-level cv-qualifiers on the template-parameter
@@ -1114,9 +1111,18 @@ QualType Sema::CheckNonTypeTemplateParameterType(QualType T,
   //   A non-type template-parameter of type "array of T" or
   //   "function returning T" is adjusted to be of type "pointer to
   //   T" or "pointer to function returning T", respectively.
-  else if (T->isArrayType() || T->isFunctionType())
+  if (T->isArrayType() || T->isFunctionType())
     return Context.getDecayedType(T);
 
+  // If T is a dependent type, we can't do the check now, so we
+  // assume that it is well-formed. Note that stripping off the
+  // qualifiers here is not really correct if T turns out to be
+  // an array type, but we'll recompute the type everywhere it's
+  // used during instantiation, so that should be OK. (Using the
+  // qualified type is equally wrong.)
+  if (T->isDependentType())
+    return T.getUnqualifiedType();
+
   Diag(Loc, diag::err_template_nontype_parm_bad_type)
     << T;
 
index 06eb5e0d784953744986010273681139bb4dfd73..330a954e0ddd9c6255d1f88a406e689d454c73d4 100644 (file)
@@ -493,3 +493,16 @@ namespace instantiation_dependent {
   template<typename T, int (*)[sizeof(sizeof(int))]> int &g(...);
   int &rg = g<struct incomplete, &arr>(0);
 }
+
+namespace complete_array_from_incomplete {
+  template <typename T, const char* const A[static_cast<int>(T::kNum)]>
+  class Base {};
+  template <class T, const char* const A[]>
+  class Derived : public Base<T, A> {};
+
+  struct T {
+    static const int kNum = 3;
+  };
+  extern const char *const kStrs[3] = {};
+  Derived<T, kStrs> d;
+}