r176216 - PR15360: nullptr as a non-type template argument to a function type non-type template parameter
David Blaikie
dblaikie at gmail.com
Wed Feb 27 14:10:41 PST 2013
Author: dblaikie
Date: Wed Feb 27 16:10:40 2013
New Revision: 176216
URL: http://llvm.org/viewvc/llvm-project?rev=176216&view=rev
Log:
PR15360: nullptr as a non-type template argument to a function type non-type template parameter
Added:
cfe/trunk/test/SemaTemplate/temp_arg_nontype_cxx11.cpp
Modified:
cfe/trunk/lib/Sema/SemaTemplate.cpp
Modified: cfe/trunk/lib/Sema/SemaTemplate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplate.cpp?rev=176216&r1=176215&r2=176216&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplate.cpp Wed Feb 27 16:10:40 2013
@@ -4495,6 +4495,16 @@ ExprResult
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 @@ Sema::BuildExpressionFromDeclTemplateArg
}
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
Added: cfe/trunk/test/SemaTemplate/temp_arg_nontype_cxx11.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/temp_arg_nontype_cxx11.cpp?rev=176216&view=auto
==============================================================================
--- cfe/trunk/test/SemaTemplate/temp_arg_nontype_cxx11.cpp (added)
+++ cfe/trunk/test/SemaTemplate/temp_arg_nontype_cxx11.cpp Wed Feb 27 16:10:40 2013
@@ -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}}
+ }
+}
More information about the cfe-commits
mailing list