public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/65322] New: Narrowing conversion
@ 2015-03-05  8:57 wolfgang.roehrl@gi-de.com
  2015-03-05 10:52 ` [Bug c++/65322] " redi at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: wolfgang.roehrl@gi-de.com @ 2015-03-05  8:57 UTC (permalink / raw)
  To: gcc-bugs

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


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2015-03-05 12:07 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-05  8:57 [Bug c++/65322] New: Narrowing conversion wolfgang.roehrl@gi-de.com
2015-03-05 10:52 ` [Bug c++/65322] " redi at gcc dot gnu.org
2015-03-05 10:54 ` redi at gcc dot gnu.org
2015-03-05 11:07 ` wolfgang.roehrl@gi-de.com
2015-03-05 11:56 ` redi at gcc dot gnu.org
2015-03-05 12:07 ` wolfgang.roehrl@gi-de.com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).