http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52257

             Bug #: 52257
           Summary: [C++11] switch cases accept floating point constants
    Classification: Unclassified
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: daniel.krueg...@googlemail.com


gcc 4.7.0 20120211 (experimental) accepts the following program, when using
-std=c++11 (with or without -Wall -pedantic):

int main()
{
  int i = 3;
  switch (i) {
    case 2: ;
    case 3.7: ;
  }
}

The program is correctly rejected when compiling w/o -std=c++11.

Nonetheless, a C++11 compiler has to reject this code. We have [stmt.switch]
p2:

"[..] Any statement within the switch statement can be labeled with one or more
case labels as follows:

case constant-expression :

where the constant-expression shall be a converted constant expression (5.19)
of the promoted type of the switch condition.[..]"

According to [expr.const] p3 we have:

"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)."

This clearly excludes floating-integral conversions from 4.9 [conv.fpint].

Reply via email to