From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 99328 invoked by alias); 5 Mar 2015 08:57:04 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 99298 invoked by uid 48); 5 Mar 2015 08:57:00 -0000 From: "wolfgang.roehrl@gi-de.com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/65322] New: Narrowing conversion Date: Thu, 05 Mar 2015 08:57:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 4.8.3 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: wolfgang.roehrl@gi-de.com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2015-03/txt/msg00576.txt.bz2 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 -D X.CPP -oX.O // file X.CPP #include "atomic" struct S { explicit S (bool b = true) : m_counter{ b ? 1u : 0u } {} std::atomic 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::__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