Patchwork [C++] PR 59123

login
register
mail settings
Submitter Paolo Carlini
Date Nov. 17, 2013, 10:37 a.m.
Message ID <52889C56.4050306@oracle.com>
Download mbox | patch
Permalink /patch/291818/
State New
Headers show

Comments

Paolo Carlini - Nov. 17, 2013, 10:37 a.m.
Hi,

C++11 7.1.5 seems very clear that redeclarations of *variables* 
differing in constexpr are fine (clang and icc agree). Tested x86_64-linux.

Thanks,
Paolo.

///////////////////
/cp
2013-11-17  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/59123
	* decl.c (validate_constexpr_redeclaration): Redeclarations of
	variables can differ in constexpr.

/testsuite
2013-11-17  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/59123
	* g++.dg/cpp0x/constexpr-redeclaration1.C: New.
	* g++.dg/cpp0x/constexpr-decl.C: Adjust.
Jason Merrill - Nov. 17, 2013, 6:27 p.m.
OK.

Jason

Patch

Index: cp/decl.c
===================================================================
--- cp/decl.c	(revision 204913)
+++ cp/decl.c	(working copy)
@@ -1216,10 +1216,12 @@  validate_constexpr_redeclaration (tree old_decl, t
       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);
+      return false;
     }
-  error ("redeclaration %qD differs in %<constexpr%>", new_decl);
-  error ("from previous declaration %q+D", old_decl);
-  return false;
+  return true;
 }
 
 #define GNU_INLINE_P(fn) (DECL_DECLARED_INLINE_P (fn)			\
Index: testsuite/g++.dg/cpp0x/constexpr-decl.C
===================================================================
--- testsuite/g++.dg/cpp0x/constexpr-decl.C	(revision 204913)
+++ testsuite/g++.dg/cpp0x/constexpr-decl.C	(working copy)
@@ -3,8 +3,7 @@ 
 
 struct S {
   static constexpr int size;	// { dg-error "must have an initializer" "must have" }
-  // { dg-error "previous declaration" "previous" { target *-*-* } 5 }
 };
 
 const int limit = 2 * S::size;
-constexpr int S::size = 256;	// { dg-error "" }
+constexpr int S::size = 256;
Index: testsuite/g++.dg/cpp0x/constexpr-redeclaration1.C
===================================================================
--- testsuite/g++.dg/cpp0x/constexpr-redeclaration1.C	(revision 0)
+++ testsuite/g++.dg/cpp0x/constexpr-redeclaration1.C	(working copy)
@@ -0,0 +1,10 @@ 
+// PR c++/59123
+// { dg-do compile { target c++11 } }
+
+// Fwd-declarations
+struct S;
+extern const S s;
+
+// (... later) definitions
+struct S {};
+constexpr S s {};