public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/64842] New: Implicitly defined constructor isn't constexpr
@ 2015-01-28 17:59 simendsjo at simendsjo dot me
2015-02-02 14:34 ` [Bug c++/64842] " ville.voutilainen at gmail dot com
2015-02-25 9:52 ` simendsjo at simendsjo dot me
0 siblings, 2 replies; 3+ messages in thread
From: simendsjo at simendsjo dot me @ 2015-01-28 17:59 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64842
Bug ID: 64842
Summary: Implicitly defined constructor isn't constexpr
Product: gcc
Version: 4.9.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: simendsjo at simendsjo dot me
The following short example is a (somewhat reduced) example from
Bjarne Stroustroups book Programming Principles and Practice using
C++ 2nd edition first print, section 8.5.9 on page 290.
I'm able to reproduce the behavior on shorter examples, but I'm
afraid to do so as I don't know enough C++ to know if I'm hiding
the actual error.
After mailing Stroustrup about the issue, he suggested I added
a bug report.
He noted that I should copy the following text in the bugreport:
12.8 Copying and moving class objects [class.copy]
A copy/move constructor that is defaulted and not defined as
deleted is implicitly defined if it is odrused (3.2) or when
it is explicitly defaulted after its first declaration.
[ Note: The copy/move constructor is implicitly defined even
if the implementation elided its odr-use (3.2, 12.2). —end
note ] If the implicitlydefined constructor would satisfy
the requirements of a constexpr constructor (7.1.5), the
implicitly-defined constructor is constexpr.
----
The code in question that fails to compile (a bit reduced from the
book example):
struct Point { double x, y; };
constexpr double xscale = 10;
constexpr double yscale = 0.8;
constexpr Point scale(Point p) { return
{xscale*p.x,yscale*p.y};}
int main() {
Point p2 {10,10};
constexpr Point p6 = scale(p2); // Error 'p2 not usable
in constant expression'
}
----
The compiler arguments used and the error it produces:
$ g++ -std=c++11 -c -o test.o test.cpp
test.cpp: In function ‘int main()’:
test.cpp:10:34: error: the value of ‘p2’ is not usable in a
constant expression
constexpr Point p6 = scale(p2); // Error 'p2 not usable
in constant expression'
^
test.cpp:9:11: note: ‘p2’ was not declared ‘constexpr’
Point p2 {10,10};
^
----
Versions used:
$ gcc --version
gcc (GCC) 4.9.2 20141224 (prerelease)
Copyright (C) 2014 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
$ g++ --version
g++ (GCC) 4.9.2 20141224 (prerelease)
Copyright (C) 2014 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
$ uname -a
Linux simendsjo-desktop 3.16.6-1-ck-bamboo #1 SMP PREEMPT Mon
Jan 5 20:15:19 CET 2015 x86_64 GNU/Linux
Let me know if you need more information in order to reproduce
this.
>From gcc-bugs-return-475291-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Wed Jan 28 18:00:35 2015
Return-Path: <gcc-bugs-return-475291-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 1289 invoked by alias); 28 Jan 2015 18:00:35 -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 1114 invoked by uid 48); 28 Jan 2015 18:00:31 -0000
From: "hjl.tools at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug lto/64837] lto plugun doesn't call ld_plugin_release_input_file
Date: Wed, 28 Jan 2015 18:00:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: lto
X-Bugzilla-Version: 5.0
X-Bugzilla-Keywords:
X-Bugzilla-Severity: normal
X-Bugzilla-Who: hjl.tools at gmail dot com
X-Bugzilla-Status: NEW
X-Bugzilla-Priority: P3
X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org
X-Bugzilla-Target-Milestone: 5.0
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields:
Message-ID: <bug-64837-4-3uwlu3ZurO@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-64837-4@http.gcc.gnu.org/bugzilla/>
References: <bug-64837-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-01/txt/msg03285.txt.bz2
Content-length: 195
https://gcc.gnu.org/bugzilla/show_bug.cgi?idd837
--- Comment #3 from H.J. Lu <hjl.tools at gmail dot com> ---
There is also a gold bug:
https://sourceware.org/bugzilla/show_bug.cgi?id\x17896
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c++/64842] Implicitly defined constructor isn't constexpr
2015-01-28 17:59 [Bug c++/64842] New: Implicitly defined constructor isn't constexpr simendsjo at simendsjo dot me
@ 2015-02-02 14:34 ` ville.voutilainen at gmail dot com
2015-02-25 9:52 ` simendsjo at simendsjo dot me
1 sibling, 0 replies; 3+ messages in thread
From: ville.voutilainen at gmail dot com @ 2015-02-02 14:34 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64842
Ville Voutilainen <ville.voutilainen at gmail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
CC| |ville.voutilainen at gmail dot com
Resolution|--- |INVALID
--- Comment #1 from Ville Voutilainen <ville.voutilainen at gmail dot com> ---
The constructors for Point are constexpr, but since p2 is not, passing
it as an argument for scale() means that the invocation of scale() will not
yield a constant expression. If you change the declaration of p2 to
be
constexpr Point p2 {10,10};
the code will work. Clang agrees with gcc.
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c++/64842] Implicitly defined constructor isn't constexpr
2015-01-28 17:59 [Bug c++/64842] New: Implicitly defined constructor isn't constexpr simendsjo at simendsjo dot me
2015-02-02 14:34 ` [Bug c++/64842] " ville.voutilainen at gmail dot com
@ 2015-02-25 9:52 ` simendsjo at simendsjo dot me
1 sibling, 0 replies; 3+ messages in thread
From: simendsjo at simendsjo dot me @ 2015-02-25 9:52 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64842
--- Comment #2 from simendsjo at simendsjo dot me ---
(In reply to Ville Voutilainen from comment #1)
> The constructors for Point are constexpr, but since p2 is not, passing
> it as an argument for scale() means that the invocation of scale() will not
> yield a constant expression. If you change the declaration of p2 to
> be
> constexpr Point p2 {10,10};
> the code will work. Clang agrees with gcc.
Then there are a couple of possibilities:
1. The spec is wrong
2. Bjarne Stroustrup misinterprets the spec
3. gcc and clang has the same bug
You're saying that 2. holds. In that case, send a mail to Stroustrup so he can
correct his book "Programming: Principles and Practice using C++".
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2015-02-25 8:43 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-28 17:59 [Bug c++/64842] New: Implicitly defined constructor isn't constexpr simendsjo at simendsjo dot me
2015-02-02 14:34 ` [Bug c++/64842] " ville.voutilainen at gmail dot com
2015-02-25 9:52 ` simendsjo at simendsjo dot me
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).