From dc601e3a099a6755cc91dd7ddc2061515120821d Mon Sep 17 00:00:00 2001 From: David Blaikie Date: Wed, 27 Feb 2013 22:10:40 +0000 Subject: [PATCH] PR15360: nullptr as a non-type template argument to a function type non-type template parameter llvm-svn: 176216 --- clang/lib/Sema/SemaTemplate.cpp | 19 ++++++++++--------- clang/test/SemaTemplate/temp_arg_nontype_cxx11.cpp | 10 ++++++++++ 2 files changed, 20 insertions(+), 9 deletions(-) create mode 100644 clang/test/SemaTemplate/temp_arg_nontype_cxx11.cpp diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp index 61fd826..4b766a9 100644 --- a/clang/lib/Sema/SemaTemplate.cpp +++ b/clang/lib/Sema/SemaTemplate.cpp @@ -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::BuildExpressionFromDeclTemplateArgument(const TemplateArgument &Arg, } 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/clang/test/SemaTemplate/temp_arg_nontype_cxx11.cpp b/clang/test/SemaTemplate/temp_arg_nontype_cxx11.cpp new file mode 100644 index 0000000..d773c64 --- /dev/null +++ b/clang/test/SemaTemplate/temp_arg_nontype_cxx11.cpp @@ -0,0 +1,10 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s + +namespace PR15360 { + template + 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(); // expected-note{{in instantiation of}} + f(); // expected-note{{in instantiation of}} + } +} -- 2.7.4