diff mbox

[C++] PR 58888

Message ID 526F9766.8040203@oracle.com
State New
Headers show

Commit Message

Paolo Carlini Oct. 29, 2013, 11:09 a.m. UTC
Hi,

On 10/28/2013 07:05 PM, Jason Merrill wrote:
> My question is, why do we need that whole block for massaging VAR_DECL 
> initializers? That all ought to be handled properly by cp_finish_decl. 
> Does removing everything after
>
>> else if (!VAR_P (value))
>> gcc_unreachable ();
> work?
In fact, it works great, excellent. I only have to tweak a bit 
g++.dg/other/warning1.C, which, for some reason, used dg-warnings, 
whereas in fact we have been matching errors (we are removing the "field 
initializer is not constant" error and replacing it with "(1.0e+0f / 
0.0f)’ is not a constant expression" etc)

Tested x86_64-linux.

Thanks,
Paolo.

/////////////////////

Comments

Jason Merrill Oct. 29, 2013, 2:47 p.m. UTC | #1
OK.

Jason
diff mbox

Patch

Index: cp/decl2.c
===================================================================
--- cp/decl2.c	(revision 204152)
+++ cp/decl2.c	(working copy)
@@ -955,26 +955,6 @@  grokfield (const cp_declarator *declarator,
 	/* C++11 NSDMI, keep going.  */;
       else if (!VAR_P (value))
 	gcc_unreachable ();
-      else if (!processing_template_decl)
-	{
-	  if (TREE_CODE (init) == CONSTRUCTOR)
-	    init = digest_init (TREE_TYPE (value), init, tf_warning_or_error);
-	  init = maybe_constant_init (init);
-
-	  if (init != error_mark_node && !TREE_CONSTANT (init))
-	    {
-	      /* We can allow references to things that are effectively
-		 static, since references are initialized with the
-		 address.  */
-	      if (TREE_CODE (TREE_TYPE (value)) != REFERENCE_TYPE
-		  || (TREE_STATIC (init) == 0
-		      && (!DECL_P (init) || DECL_EXTERNAL (init) == 0)))
-		{
-		  error ("field initializer is not constant");
-		  init = error_mark_node;
-		}
-	    }
-	}
     }
 
   if (processing_template_decl && VAR_OR_FUNCTION_DECL_P (value))
Index: testsuite/g++.dg/cpp0x/auto40.C
===================================================================
--- testsuite/g++.dg/cpp0x/auto40.C	(revision 0)
+++ testsuite/g++.dg/cpp0x/auto40.C	(working copy)
@@ -0,0 +1,11 @@ 
+// PR c++/58888
+// { dg-do compile { target c++11 } }
+
+#include <initializer_list>
+
+struct A
+{
+  static constexpr auto b{1.0};
+};
+
+constexpr decltype(A::b) A::b;
Index: testsuite/g++.dg/other/warning1.C
===================================================================
--- testsuite/g++.dg/other/warning1.C	(revision 204152)
+++ testsuite/g++.dg/other/warning1.C	(working copy)
@@ -7,8 +7,8 @@  extern "C" int printf(const char *, ...);
 
 struct S
 {
-  static const float inf = 1.0f / 0.0f; // { dg-warning "1.0|float|initializ" }
-  static const float nan = 0.0f / 0.0f; // { dg-warning "0.0|float|initializ" }
+  static const float inf = 1.0f / 0.0f; // { dg-error "1.0|float|initializ" }
+  static const float nan = 0.0f / 0.0f; // { dg-error "0.0|float|initializ" }
 };
 
 int main()