]> granicus.if.org Git - clang/commitdiff
When converting a template argument representing &array to an expression for a
authorRichard Smith <richard-llvm@metafoo.co.uk>
Sat, 28 Jan 2017 00:38:35 +0000 (00:38 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Sat, 28 Jan 2017 00:38:35 +0000 (00:38 +0000)
pointer typed template parameter, form &array rather than an array-to-pointer
decay on array.

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

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

index 6a53009523475f887e0039460ea237d6e113f65c..8f46ad056b70d4b4162d6ce80587f357c3a7e80b 100644 (file)
@@ -5830,8 +5830,9 @@ Sema::BuildExpressionFromDeclTemplateArgument(const TemplateArgument &Arg,
     if (RefExpr.isInvalid())
       return ExprError();
 
-    if (T->isFunctionType() || T->isArrayType()) {
-      // Decay functions and arrays.
+    if (!Context.hasSameUnqualifiedType(ParamType->getPointeeType(), T) &&
+        (T->isFunctionType() || T->isArrayType())) {
+      // Decay functions and arrays unless we're forming a pointer to array.
       RefExpr = DefaultFunctionArrayConversion(RefExpr.get());
       if (RefExpr.isInvalid())
         return ExprError();
index 5b72b8c6549a4ac1e4f5f811d1d985ee81f3d96f..8658fb006060e245d6358d16ea19ec7848af6f85 100644 (file)
@@ -455,3 +455,11 @@ namespace nondependent_default_arg_ordering {
     X<int *, &m> y; f(y); // expected-error {{ambiguous}}
   }
 }
+
+namespace pointer_to_char_array {
+  typedef char T[4];
+  template<T *P> struct A { void f(); };
+  template<T *P> void A<P>::f() {}
+  T foo = "foo";
+  void g() { A<&foo>().f(); }
+}