]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c++/56871 ([c++11] Specialization of constexpr Templated Function)
authorPaolo Carlini <paolo.carlini@oracle.com>
Mon, 8 Apr 2013 18:09:35 +0000 (18:09 +0000)
committerPaolo Carlini <paolo@gcc.gnu.org>
Mon, 8 Apr 2013 18:09:35 +0000 (18:09 +0000)
/cp
2013-04-08  Paolo Carlini  <paolo.carlini@oracle.com>

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  <paolo.carlini@oracle.com>

PR c++/56871
* g++.dg/cpp0x/constexpr-specialization.C: New.

From-SVN: r197597

gcc/cp/ChangeLog
gcc/cp/decl.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/constexpr-specialization.C [new file with mode: 0644]

index 1af1fd7467bc9475163ba0e9d80c73a503412086..8b9bf350c0733fa435623f6686828505c43d4050 100644 (file)
@@ -1,3 +1,9 @@
+2013-04-08  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/56871
+       * decl.c (validate_constexpr_redeclaration): Allow an explicit
+       specialization to be different wrt the constexpr specifier.
+
 2013-04-06  Jason Merrill  <jason@redhat.com>
 
        * parser.c (cp_parser_std_attribute): Treat [[noreturn]] like GNU
index 70137f4a7fc3b79024c598c939089438b6095a7e..01804d2cf682391e8824e58a4032467a87db3721 100644 (file)
@@ -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 %<constexpr%>", new_decl);
   error ("from previous declaration %q+D", old_decl);
index dcf0d580649b74111a1bf31234240c32a0274bf2..9fdbdfc0ba18201c6d616efe4c2ee0645418889e 100644 (file)
@@ -1,3 +1,8 @@
+2013-04-08  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/56871
+       * g++.dg/cpp0x/constexpr-specialization.C: New.
+
 2013-04-08  Jakub Jelinek  <jakub@redhat.com>
 
        * 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 (file)
index 0000000..8003ed9
--- /dev/null
@@ -0,0 +1,12 @@
+// PR c++/56871
+// { dg-options "-std=c++11" }
+
+template<typename T> constexpr int foo(T);
+template<> int foo(int);
+template<> int foo(int);            // { dg-error "previous" }
+template<> constexpr int foo(int);  // { dg-error "redeclaration" }
+
+template<typename T> int bar(T);
+template<> constexpr int bar(int);
+template<> constexpr int bar(int);  // { dg-error "previous" }
+template<> int bar(int);            // { dg-error "redeclaration" }