diff mbox

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

Message ID a35ea4e7-79a1-15a5-9f71-d9aea316cf72@oracle.com
State New
Headers show

Commit Message

Paolo Carlini Nov. 17, 2016, 8:25 p.m. UTC
Hi,

On 17/11/2016 18:14, Jason Merrill wrote:
> How about changing cp_parser_non_integral_constant_expression to issue
> a pedwarn instead of error for NIC_FLOAT?
Indeed. And a relevant observation is that we don't pass NIC_FLOAT from 
anywhere else in the parser, please correct me if I'm wrong. The below 
is finishing testing, all good so far.

Thanks,
Paolo.

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

Comments

Jason Merrill Nov. 17, 2016, 8:29 p.m. UTC | #1
OK.

On Thu, Nov 17, 2016 at 3:25 PM, Paolo Carlini <paolo.carlini@oracle.com> wrote:
> Hi,
>
> On 17/11/2016 18:14, Jason Merrill wrote:
>>
>> How about changing cp_parser_non_integral_constant_expression to issue
>> a pedwarn instead of error for NIC_FLOAT?
>
> Indeed. And a relevant observation is that we don't pass NIC_FLOAT from
> anywhere else in the parser, please correct me if I'm wrong. The below is
> finishing testing, all good so far.
>
> Thanks,
> Paolo.
>
> ////////////////
diff mbox

Patch

Index: cp/parser.c
===================================================================
--- cp/parser.c	(revision 242540)
+++ cp/parser.c	(working copy)
@@ -3028,8 +3028,9 @@  cp_parser_non_integral_constant_expression (cp_par
 	  switch (thing)
 	    {
   	      case NIC_FLOAT:
-		error ("floating-point literal "
-		       "cannot appear in a constant-expression");
+		pedwarn (input_location, OPT_Wpedantic,
+			 "ISO C++ forbids using a floating-point literal "
+			 "in a constant-expression");
 		return true;
 	      case NIC_CAST:
 		error ("a cast to a type other than an integral or "
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" }
+};