Handle instantiation of templates with non-type arguments expressed with an
explicit '&' by introducing an address-of operator prior to checking the
argument's type.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@94947 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaTemplateInstantiate.cpp b/lib/Sema/SemaTemplateInstantiate.cpp
index 2db0deb..3efb52e 100644
--- a/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/lib/Sema/SemaTemplateInstantiate.cpp
@@ -746,6 +746,22 @@
                                                 move(RefExpr));
           }
         }
+        if (NTTP->getType()->isPointerType() &&
+            !VD->getType()->isPointerType()) {
+          // If the template argument is expected to be a pointer and value
+          // isn't inherently of pointer type, then it is specified with '&...'
+          // to indicate its address should be used. Build an expression to
+          // take the address of the argument.
+          OwningExprResult RefExpr
+            = SemaRef.BuildDeclRefExpr(VD, VD->getType().getNonReferenceType(),
+                                       E->getLocation());
+          if (RefExpr.isInvalid())
+            return SemaRef.ExprError();
+
+          return SemaRef.CreateBuiltinUnaryOp(E->getLocation(),
+                                              UnaryOperator::AddrOf,
+                                              move(RefExpr));
+        }
 
         return SemaRef.BuildDeclRefExpr(VD, VD->getType().getNonReferenceType(),
                                         E->getLocation());