[cfe-commits] r94947 - in /cfe/trunk: lib/Sema/SemaTemplateInstantiate.cpp test/CXX/temp/temp.arg/temp.arg.nontype/p1.cpp

Chandler Carruth chandlerc at gmail.com
Sat Jan 30 23:09:12 PST 2010


Author: chandlerc
Date: Sun Jan 31 01:09:11 2010
New Revision: 94947

URL: http://llvm.org/viewvc/llvm-project?rev=94947&view=rev
Log:
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.

Added:
    cfe/trunk/test/CXX/temp/temp.arg/temp.arg.nontype/p1.cpp
Modified:
    cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp

Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp?rev=94947&r1=94946&r2=94947&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp Sun Jan 31 01:09:11 2010
@@ -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());

Added: cfe/trunk/test/CXX/temp/temp.arg/temp.arg.nontype/p1.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/temp/temp.arg/temp.arg.nontype/p1.cpp?rev=94947&view=auto

==============================================================================
--- cfe/trunk/test/CXX/temp/temp.arg/temp.arg.nontype/p1.cpp (added)
+++ cfe/trunk/test/CXX/temp/temp.arg/temp.arg.nontype/p1.cpp Sun Jan 31 01:09:11 2010
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+template <const int* p> struct X { };
+
+int i = 42;
+int* iptr = &i;
+void test() {
+  X<&i> x1;
+  X<iptr> x2;
+}





More information about the cfe-commits mailing list