[Bug c++/65322] New: Narrowing conversion
wolfgang.roehrl@gi-de.com
gcc-bugzilla@gcc.gnu.org
Thu Mar 5 08:57:00 GMT 2015
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65322
Bug ID: 65322
Summary: Narrowing conversion
Product: gcc
Version: 4.8.3
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: wolfgang.roehrl@gi-de.com
Hi,
I would like to post a bug report for the GNU C/C++ compiler 4.8.3.
We use the compiler to generate code for a PowerPC processor.
Invokation line for the GNU C++ compiler:
ccppc -c -x c++ -std=c++11 -Wall -Werror -g -mcpu=8540 -meabi
-ftls-model=local-exec -msdata=sysv -fno-common -mspe -mabi=spe
-mfloat-gprs=double -mbig -mmultiple -mno-string -misel -mstrict-align
-fverbose-asm -fno-exceptions -fno-rtti -fgcse-sm -fno-section-anchors
-ftemplate-backtrace-limit=20 -G 8 -O3
-I<some include paths>
-D<some #define's>
X.CPP -oX.O
// file X.CPP
#include "atomic"
struct S
{
explicit S (bool b = true)
: m_counter{ b ? 1u : 0u }
{}
std::atomic<unsigned short> m_counter;
};
S x;
The compiler rejects this programm with the following message:
x.CPP: In constructor 'S::S(bool)':
x.CPP:6:30: error: narrowing conversion of '(b ? 1u : 0u)' from 'unsigned int'
to 'std::atomic<short unsigned int>::__integral_type
{aka short unsigned int}' inside { } [-Werror=narrowing]
: m_counter{ b ? 1u : 0u }
I think this is not standard conforming. See C++11 standard, 8.5.4/7:
"A narrowing conversion is an implicit conversion ... from an integer type or
unscoped enumeration type to an integer type that cannot represent all the
values of the original type, except where the source is a constant expression
and the actual value after conversion will fit into the target type and will
produce the original value when converted back to the original type."
Kind regards
W. Roehrl
More information about the Gcc-bugs
mailing list