From: Paolo Carlini Date: Mon, 8 Apr 2013 18:09:35 +0000 (+0000) Subject: re PR c++/56871 ([c++11] Specialization of constexpr Templated Function) X-Git-Tag: releases/gcc-4.9.0~6606 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0c3f68a025fc9d41a615854c21c6f2363739c066;p=thirdparty%2Fgcc.git re PR c++/56871 ([c++11] Specialization of constexpr Templated Function) /cp 2013-04-08 Paolo Carlini PR c++/56871 * decl.c (validate_constexpr_redeclaration): Allow an explicit specialization to be different wrt the constexpr specifier. /testsuite 2013-04-08 Paolo Carlini PR c++/56871 * g++.dg/cpp0x/constexpr-specialization.C: New. From-SVN: r197597 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 1af1fd7467bc..8b9bf350c073 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2013-04-08 Paolo Carlini + + PR c++/56871 + * decl.c (validate_constexpr_redeclaration): Allow an explicit + specialization to be different wrt the constexpr specifier. + 2013-04-06 Jason Merrill * parser.c (cp_parser_std_attribute): Treat [[noreturn]] like GNU diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 70137f4a7fc3..01804d2cf682 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -1196,12 +1196,21 @@ validate_constexpr_redeclaration (tree old_decl, tree new_decl) if (DECL_DECLARED_CONSTEXPR_P (old_decl) == DECL_DECLARED_CONSTEXPR_P (new_decl)) return true; - if (TREE_CODE (old_decl) == FUNCTION_DECL && DECL_BUILT_IN (old_decl)) + if (TREE_CODE (old_decl) == FUNCTION_DECL) { - /* Hide a built-in declaration. */ - DECL_DECLARED_CONSTEXPR_P (old_decl) - = DECL_DECLARED_CONSTEXPR_P (new_decl); - return true; + if (DECL_BUILT_IN (old_decl)) + { + /* Hide a built-in declaration. */ + DECL_DECLARED_CONSTEXPR_P (old_decl) + = DECL_DECLARED_CONSTEXPR_P (new_decl); + return true; + } + /* 7.1.5 [dcl.constexpr] + Note: An explicit specialization can differ from the template + declaration with respect to the constexpr specifier. */ + if (! DECL_TEMPLATE_SPECIALIZATION (old_decl) + && DECL_TEMPLATE_SPECIALIZATION (new_decl)) + return true; } error ("redeclaration %qD differs in %", new_decl); error ("from previous declaration %q+D", old_decl); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index dcf0d580649b..9fdbdfc0ba18 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2013-04-08 Paolo Carlini + + PR c++/56871 + * g++.dg/cpp0x/constexpr-specialization.C: New. + 2013-04-08 Jakub Jelinek * gcc.c-torture/execute/pr56837.c: New test. diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-specialization.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-specialization.C new file mode 100644 index 000000000000..8003ed9e1332 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-specialization.C @@ -0,0 +1,12 @@ +// PR c++/56871 +// { dg-options "-std=c++11" } + +template constexpr int foo(T); +template<> int foo(int); +template<> int foo(int); // { dg-error "previous" } +template<> constexpr int foo(int); // { dg-error "redeclaration" } + +template int bar(T); +template<> constexpr int bar(int); +template<> constexpr int bar(int); // { dg-error "previous" } +template<> int bar(int); // { dg-error "redeclaration" }