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

             Bug #: 55783
           Summary: Warnings instead of compiler errors for narrowing
                    conversions within list-initializations
    Classification: Unclassified
           Product: gcc
           Version: 4.7.2
            Status: UNCONFIRMED
          Severity: major
          Priority: P3
         Component: c++
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: da...@stellarscience.com


Created attachment 29023
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=29023
Erroneous C++ 2011 program that has a narrowing conversion error.

Narrowing conversions for initializer lists are producing warnings instead of
errors in -std=c++11 mode. See standard 8.5.4 item 3:

  If a narrowing conversion (see below) is required to convert any of the
  arguments, the program is ill-formed.


and item 7:

  A narrowing conversion is an implicit conversion...

  from long double to double or float, or from double to float, except where
the source is a constant
  expression and the actual value after conversion is within the range of
values that can be represented
  (even if it cannot be represented exactly)

Compiling the attached program has the following output with -std=c++11:

test.cpp: In function ‘void f(double)’:
test.cpp:3:26: warning: narrowing conversion of ‘d’ from ‘double’ to ‘float’
inside { } [-Wnarrowing]
test.cpp:3:26: warning: narrowing conversion of ‘d’ from ‘double’ to ‘float’
inside { } [-Wnarrowing]
test.cpp:3:26: warning: narrowing conversion of ‘d’ from ‘double’ to ‘float’
inside { } [-Wnarrowing]

Reply via email to