PR15360: nullptr as a non-type template argument to a function type non-type template parameter
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@176216 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaTemplate.cpp b/lib/Sema/SemaTemplate.cpp
index 61fd826..4b766a9 100644
--- a/lib/Sema/SemaTemplate.cpp
+++ b/lib/Sema/SemaTemplate.cpp
@@ -4495,6 +4495,16 @@
Sema::BuildExpressionFromDeclTemplateArgument(const TemplateArgument &Arg,
QualType ParamType,
SourceLocation Loc) {
+ // C++ [temp.param]p8:
+ //
+ // 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.
+ if (ParamType->isArrayType())
+ ParamType = Context.getArrayDecayedType(ParamType);
+ else if (ParamType->isFunctionType())
+ ParamType = Context.getPointerType(ParamType);
+
// For a NULL non-type template argument, return nullptr casted to the
// parameter's type.
if (Arg.getKind() == TemplateArgument::NullPtr) {
@@ -4560,15 +4570,6 @@
}
QualType T = VD->getType().getNonReferenceType();
- // C++ [temp.param]p8:
- //
- // 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.
- if (ParamType->isArrayType())
- ParamType = Context.getArrayDecayedType(ParamType);
- else if (ParamType->isFunctionType())
- ParamType = Context.getPointerType(ParamType);
if (ParamType->isPointerType()) {
// When the non-type template parameter is a pointer, take the
diff --git a/test/SemaTemplate/temp_arg_nontype_cxx11.cpp b/test/SemaTemplate/temp_arg_nontype_cxx11.cpp
new file mode 100644
index 0000000..d773c64
--- /dev/null
+++ b/test/SemaTemplate/temp_arg_nontype_cxx11.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
+
+namespace PR15360 {
+ template<typename R, typename U, R F>
+ U f() { return &F; } // expected-error{{cannot take the address of an rvalue of type 'int (*)(int)'}} expected-error{{cannot take the address of an rvalue of type 'int *'}}
+ void test() {
+ f<int(int), int(*)(int), nullptr>(); // expected-note{{in instantiation of}}
+ f<int[3], int*, nullptr>(); // expected-note{{in instantiation of}}
+ }
+}