diff mbox

[C++] PR 55080 (" -pedantic produces error: floating-point literal cannot appear in a constant-expression")

Message ID 972ff6d2-d6ba-5b0b-f6fd-a541543eb197@oracle.com
State New
Headers show

Commit Message

Paolo Carlini Nov. 17, 2016, 3:33 p.m. UTC
... oops, forgot about parser->non_integral_constant_expression_p. The 
version below, which I'm currently regtesting again, seems more correct.

Thanks,
Paolo.

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

Comments

Jason Merrill Nov. 17, 2016, 5:14 p.m. UTC | #1
How about changing cp_parser_non_integral_constant_expression to issue
a pedwarn instead of error for NIC_FLOAT?

Jason
diff mbox

Patch

Index: cp/parser.c
===================================================================
--- cp/parser.c	(revision 242540)
+++ cp/parser.c	(working copy)
@@ -4841,7 +4841,13 @@  cp_parser_primary_expression (cp_parser *parser,
 	     checked at that point.  If we are not within a cast, then
 	     this code is invalid.  */
 	  if (!cast_p)
-	    cp_parser_non_integral_constant_expression (parser, NIC_FLOAT);
+	    {
+	      parser->non_integral_constant_expression_p = true;
+	      if (!parser->allow_non_integral_constant_expression_p)
+		pedwarn (input_location, OPT_Wpedantic,
+			 "ISO C++ forbids using a floating-point literal "
+			 "in a constant-expression");
+	    }
 	}
       return cp_expr (token->u.value, token->location);
 
Index: testsuite/g++.dg/parse/pr55080.C
===================================================================
--- testsuite/g++.dg/parse/pr55080.C	(revision 0)
+++ testsuite/g++.dg/parse/pr55080.C	(working copy)
@@ -0,0 +1,6 @@ 
+// PR c++/55080
+// { dg-options "-std=c++98 -pedantic" }
+
+class B {
+ static const int c = 3.1415926; // { dg-warning "constant-expression" }
+};