diff mbox

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

Message ID 51cce2fd-b737-78bc-3821-205713db1015@oracle.com
State New
Headers show

Commit Message

Paolo Carlini Nov. 17, 2016, 11:40 a.m. UTC
Hi,

this rather old issue points out that, for the snippet below in the 
legacy -std=c++98 and -pedantic, we issue an hard error instead of a 
pedwarn - what we normally do, as clarified by Manuel. I guess we could 
imagine further clean-ups in this area but something as simple as the 
below seems correct to me and pretty conservative.

Tested x86_64-linux.

Thanks, Paolo.

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

	PR c++/55080
	* parser.c (cp_parser_primary_expression): Issue a pedwarn instead
	of an error floating-point literals in a constant-expression.

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

	PR c++/55080
	* g++.dg/parse/pr55080.C: New.
diff mbox

Patch

Index: cp/parser.c
===================================================================
--- cp/parser.c	(revision 242540)
+++ cp/parser.c	(working copy)
@@ -4840,8 +4840,10 @@  cp_parser_primary_expression (cp_parser *parser,
 	     cast is to an integral or enumeration type will be
 	     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);
+	  if (!cast_p && !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" }
+};