Bug 51912 - [C++11] G++ accepts floating point case labels
Summary: [C++11] G++ accepts floating point case labels
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.7.0
: P3 normal
Target Milestone: 4.9.0
Assignee: Paolo Carlini
URL:
Keywords: accepts-invalid
: 52257 (view as bug list)
Depends on:
Blocks:
 
Reported: 2012-01-20 06:30 UTC by Jason Merrill
Modified: 2013-08-14 21:44 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2012-02-15 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jason Merrill 2012-01-20 06:30:52 UTC
5.19:  A converted constant expression of type T is a literal constant expression, implicitly converted to type T, where the implicit conversion (if any) is permitted in a literal constant expression and the implicit conversion sequence contains only user-defined  conversions, lvalue-to-rvalue conversions (4.1), integral promotions (4.5), and integral conversions (4.7) other than narrowing conversions (8.5.4). [ Note: such expressions may be used as case expressions (6.4.2), ....

So a floating point literal is not a valid case expression, since converting it to the switch type would require a non-integral conversion.

void f(int i)
{
  switch (i)
    {
    case 1.0:;
    }
}
Comment 1 Paolo Carlini 2012-02-15 16:20:55 UTC
*** Bug 52257 has been marked as a duplicate of this bug. ***
Comment 2 Paolo Carlini 2012-05-29 13:58:21 UTC
Jason, I'm thinking that this should be doable rather easily by adding a new LOOKUP_NO_NON_INTEGRAL mask and passing it down to standard_conversion from  case_conversion via perform_implicit_conversion_flags.

Then standard_conversion can exclude all such non-integral conversions, eg, for this specific testcase, return NULL from line #1332 because fcode == REALTYPE && (flags & LOOKUP_NO_NON_INTEGRAL)).

Makes sense?
Comment 3 Paolo Carlini 2013-08-14 18:01:45 UTC
Mine.
Comment 4 Paolo Carlini 2013-08-14 21:44:47 UTC
Fixed for 4.9.0.