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
* [Bug c++/65322] Narrowing conversion
2015-03-05 8:57 [Bug c++/65322] New: Narrowing conversion wolfgang.roehrl@gi-de.com
@ 2015-03-05 10:52 ` redi at gcc dot gnu.org
2015-03-05 10:54 ` redi at gcc dot gnu.org
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: redi at gcc dot gnu.org @ 2015-03-05 10:52 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65322
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution|--- |INVALID
--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
"b ? 1u : 0u" is not a constant expression, it depends on the variable b so the
value is not known until run-time.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/65322] Narrowing conversion
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
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: redi at gcc dot gnu.org @ 2015-03-05 10:54 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65322
--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
N.B. to make the code compile just don't use braces for the initialization:
: m_counter( b ? 1u : 0u )
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/65322] Narrowing conversion
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
4 siblings, 0 replies; 6+ messages in thread
From: wolfgang.roehrl@gi-de.com @ 2015-03-05 11:07 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65322
--- Comment #3 from Wolfgang Roehrl <wolfgang.roehrl@gi-de.com> ---
Hi Jonathan,
of course you are true. (I was overhasty with my bug report.)
Now I changed my program to using a constexpr-ctor:
#include "atomic"
struct S
{
explicit constexpr S (bool b = true)
: m_counter{ b ? 1u : 0u }
{}
std::atomic<unsigned short> m_counter;
};
S x;
The compiler rejects this program too - is this correct?
Wolfgang
Von: "redi at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
An: wolfgang.roehrl@gi-de.com
Datum: 05.03.2015 11:54
Betreff: [Bug c++/65322] Narrowing conversion
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65322
--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
N.B. to make the code compile just don't use braces for the
initialization:
: m_counter( b ? 1u : 0u )
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/65322] Narrowing conversion
2015-03-05 8:57 [Bug c++/65322] New: Narrowing conversion wolfgang.roehrl@gi-de.com
` (2 preceding siblings ...)
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
4 siblings, 0 replies; 6+ messages in thread
From: redi at gcc dot gnu.org @ 2015-03-05 11:56 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65322
--- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Jonathan Wakely from comment #4)
> Just use m_counter( b ? 1u : 0u ) or m_counter{ short(b ? 1u : 0u) }
Oops, the second one should be m_counter{ (unsigned short)(b ? 1u : 0u) }
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/65322] Narrowing conversion
2015-03-05 8:57 [Bug c++/65322] New: Narrowing conversion wolfgang.roehrl@gi-de.com
` (3 preceding siblings ...)
2015-03-05 11:56 ` redi at gcc dot gnu.org
@ 2015-03-05 12:07 ` wolfgang.roehrl@gi-de.com
4 siblings, 0 replies; 6+ messages in thread
From: wolfgang.roehrl@gi-de.com @ 2015-03-05 12:07 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65322
--- Comment #6 from Wolfgang Roehrl <wolfgang.roehrl@gi-de.com> ---
Thank you and have a nice day!
Vorsitzender des Aufsichtsrats: Dr. Peter-Alexander Wacker
Geschäftsführer: Dr. Walter Schlebusch (Vorsitzender, CEO),
Stefan Auerbach, Hans Wolfgang Kunz, Ralf Wintergerst, Dr. Peter Zattler
(CFO)
Gesellschaftssitz: München, Handelsregister Amtsgericht München HRB 4619
* * * Welcome to the Connected Society * * *
Meet G&D at the Mobile World Congress 2015
March 2 - 5
Booth 7A41, Hall 7
>From gcc-bugs-return-479461-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Thu Mar 05 12:19:51 2015
Return-Path: <gcc-bugs-return-479461-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 72792 invoked by alias); 5 Mar 2015 12:19:51 -0000
Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm
Precedence: bulk
List-Id: <gcc-bugs.gcc.gnu.org>
List-Archive: <http://gcc.gnu.org/ml/gcc-bugs/>
List-Post: <mailto:gcc-bugs@gcc.gnu.org>
List-Help: <mailto:gcc-bugs-help@gcc.gnu.org>
Sender: gcc-bugs-owner@gcc.gnu.org
Delivered-To: mailing list gcc-bugs@gcc.gnu.org
Received: (qmail 72435 invoked by uid 48); 5 Mar 2015 12:19:47 -0000
From: "ebotcazou at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug ada/65319] FAIL: g++.dg/other/dump-ada-spec-3.C -std=gnu++98 (internal compiler error)
Date: Thu, 05 Mar 2015 12:19:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: ada
X-Bugzilla-Version: 5.0
X-Bugzilla-Keywords:
X-Bugzilla-Severity: normal
X-Bugzilla-Who: ebotcazou at gcc dot gnu.org
X-Bugzilla-Status: ASSIGNED
X-Bugzilla-Priority: P3
X-Bugzilla-Assigned-To: ebotcazou at gcc dot gnu.org
X-Bugzilla-Target-Milestone: ---
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields: bug_status cc assigned_to
Message-ID: <bug-65319-4-ZcNajWYnP0@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-65319-4@http.gcc.gnu.org/bugzilla/>
References: <bug-65319-4@http.gcc.gnu.org/bugzilla/>
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/msg00605.txt.bz2
Content-length: 461
https://gcc.gnu.org/bugzilla/show_bug.cgi?ide319
Eric Botcazou <ebotcazou at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |ASSIGNED
CC| |ebotcazou at gcc dot gnu.org
Assignee|unassigned at gcc dot gnu.org |ebotcazou at gcc dot gnu.org
^ 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).