summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
authorChandler Carruth <chandlerc@gmail.com>2010-01-31 07:09:11 +0000
committerChandler Carruth <chandlerc@gmail.com>2010-01-31 07:09:11 +0000
commit9b1fa25432939fcb1ad6763dfca73a98c1eb230f (patch)
tree5bc9dccf2c3a22a2c1b5ad590f0dab1c960d3096 /clang
parent7f62def0f9d019493cdcaf014dc4c4774f9fa01a (diff)
downloadbcm5719-llvm-9b1fa25432939fcb1ad6763dfca73a98c1eb230f.tar.gz
bcm5719-llvm-9b1fa25432939fcb1ad6763dfca73a98c1eb230f.zip
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. llvm-svn: 94947
Diffstat (limited to 'clang')
-rw-r--r--clang/lib/Sema/SemaTemplateInstantiate.cpp16
-rw-r--r--clang/test/CXX/temp/temp.arg/temp.arg.nontype/p1.cpp10
2 files changed, 26 insertions, 0 deletions
diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index 2db0deb5098..3efb52e91bf 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -746,6 +746,22 @@ TemplateInstantiator::TransformDeclRefExpr(DeclRefExpr *E) {
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());
diff --git a/clang/test/CXX/temp/temp.arg/temp.arg.nontype/p1.cpp b/clang/test/CXX/temp/temp.arg/temp.arg.nontype/p1.cpp
new file mode 100644
index 00000000000..f9834dfed20
--- /dev/null
+++ b/clang/test/CXX/temp/temp.arg/temp.arg.nontype/p1.cpp
@@ -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;
+}
OpenPOWER on IntegriCloud