public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/54002] New: [C++0x][constexpr] Initializing constexpr static member using constexpr static method fails
@ 2012-07-17 19:48 Martin.vGagern at gmx dot net
  2012-07-17 20:05 ` [Bug c++/54002] " redi at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: Martin.vGagern at gmx dot net @ 2012-07-17 19:48 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54002

             Bug #: 54002
           Summary: [C++0x][constexpr] Initializing constexpr static
                    member using constexpr static method fails
    Classification: Unclassified
           Product: gcc
           Version: 4.7.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: Martin.vGagern@gmx.net


I would expect the following code to work with -std=gnu++0x, but it does not:

class C1 {
  constexpr static int foo(int x) { return x + 1; }
  constexpr static int bar = foo(sizeof(int));
};

g++ 4.5 complains:
error: ‘static int C1::foo(int)’ cannot appear in a constant-expression
error: a function call cannot appear in a constant-expression

g++ 4.6 and 4.7 complain:
error: field initializer is not constant



Detailed analysis of this problem follows below.

As the function is declared to be constexpr, this surprises me. I took this to
Stack Overflow to get some insight:
http://stackoverflow.com/q/11522399/1468366

In his answer http://stackoverflow.com/a/11523155/1468366, Ben Voigt quoted
relevant parts from the spec. The most likely cause for this *not* being a
constant expression appears to be section 5.19 paragraph 2 item 3:
"an invocation of an undefined constexpr function […]"
qutoed from http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2011/n3242.pdf

But the definition is there, right in the class. Neither of us could find a
part in the specification which might cause the function to not be defined at
that point, particularly as the class is completely defined within the
initializer, according to section 9.2 paragraph 2.

In case there actually is some part of the spec which makes gccs current
behaviour the only correct one, then please consider this report here as a
request for a more useful error message, which might make the actual problem
known without having to read the specs for hours.

If, on the other hand, the specs allow code like the one above, as I believe
they do, then please try to make gcc accept that code as well.


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

* [Bug c++/54002] [C++0x][constexpr] Initializing constexpr static member using constexpr static method fails
  2012-07-17 19:48 [Bug c++/54002] New: [C++0x][constexpr] Initializing constexpr static member using constexpr static method fails Martin.vGagern at gmx dot net
@ 2012-07-17 20:05 ` redi at gcc dot gnu.org
  2012-07-17 20:06 ` redi at gcc dot gnu.org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: redi at gcc dot gnu.org @ 2012-07-17 20:05 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54002

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jason at gcc dot gnu.org

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-07-17 20:04:59 UTC ---
N.B. 4.5 doesn't implement constexpr (it parses the keyword and pretty much
ignores it) so that error is irrelevant

I think this might be because C1::foo can't be used in a constant expression
until C1 is complete. Jason?


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

* [Bug c++/54002] [C++0x][constexpr] Initializing constexpr static member using constexpr static method fails
  2012-07-17 19:48 [Bug c++/54002] New: [C++0x][constexpr] Initializing constexpr static member using constexpr static method fails Martin.vGagern at gmx dot net
  2012-07-17 20:05 ` [Bug c++/54002] " redi at gcc dot gnu.org
@ 2012-07-17 20:06 ` redi at gcc dot gnu.org
  2012-07-18  7:09 ` Martin.vGagern at gmx dot net
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: redi at gcc dot gnu.org @ 2012-07-17 20:06 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54002

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-07-17 20:06:07 UTC ---
See PR 52366, which makes this a dup of PR 52315


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

* [Bug c++/54002] [C++0x][constexpr] Initializing constexpr static member using constexpr static method fails
  2012-07-17 19:48 [Bug c++/54002] New: [C++0x][constexpr] Initializing constexpr static member using constexpr static method fails Martin.vGagern at gmx dot net
  2012-07-17 20:05 ` [Bug c++/54002] " redi at gcc dot gnu.org
  2012-07-17 20:06 ` redi at gcc dot gnu.org
@ 2012-07-18  7:09 ` Martin.vGagern at gmx dot net
  2014-08-29 15:54 ` [Bug c++/54002] [C++0x] " paolo.carlini at oracle dot com
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Martin.vGagern at gmx dot net @ 2012-07-18  7:09 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54002

--- Comment #3 from Martin von Gagern <Martin.vGagern at gmx dot net> 2012-07-18 07:09:02 UTC ---
(In reply to comment #2)
> See PR 52366, which makes this a dup of PR 52315

I agree that this is a duplicate of PR 52366. And although I'm still not
convinced that this is really the same requirement as the one in PR 52315, I'm
inclined to believe it nevertheless. Should PR 52366 be un-duped, like PR 52366
comment 4 requested out, then this here should still be duped to PR 52366
instead of PR 52315, so I suggest duping it there in the first place.


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

* [Bug c++/54002] [C++0x] Initializing constexpr static member using constexpr static method fails
  2012-07-17 19:48 [Bug c++/54002] New: [C++0x][constexpr] Initializing constexpr static member using constexpr static method fails Martin.vGagern at gmx dot net
                   ` (2 preceding siblings ...)
  2012-07-18  7:09 ` Martin.vGagern at gmx dot net
@ 2014-08-29 15:54 ` paolo.carlini at oracle dot com
  2014-08-29 15:59 ` paolo.carlini at oracle dot com
  2014-08-29 15:59 ` paolo at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: paolo.carlini at oracle dot com @ 2014-08-29 15:54 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=54002

--- Comment #4 from Paolo Carlini <paolo.carlini at oracle dot com> ---
I'm adding the testcase to the testsuite and closing the bug.


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

* [Bug c++/54002] [C++0x] Initializing constexpr static member using constexpr static method fails
  2012-07-17 19:48 [Bug c++/54002] New: [C++0x][constexpr] Initializing constexpr static member using constexpr static method fails Martin.vGagern at gmx dot net
                   ` (4 preceding siblings ...)
  2014-08-29 15:59 ` paolo.carlini at oracle dot com
@ 2014-08-29 15:59 ` paolo at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: paolo at gcc dot gnu.org @ 2014-08-29 15:59 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=54002

--- Comment #5 from paolo at gcc dot gnu.org <paolo at gcc dot gnu.org> ---
Author: paolo
Date: Fri Aug 29 15:58:26 2014
New Revision: 214734

URL: https://gcc.gnu.org/viewcvs?rev=214734&root=gcc&view=rev
Log:
2014-08-29  Paolo Carlini  <paolo.carlini@oracle.com>

    PR c++/54002
    * g++.dg/cpp0x/constexpr-54002.C: New.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/constexpr-54002.C
Modified:
    trunk/gcc/testsuite/ChangeLog


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

* [Bug c++/54002] [C++0x] Initializing constexpr static member using constexpr static method fails
  2012-07-17 19:48 [Bug c++/54002] New: [C++0x][constexpr] Initializing constexpr static member using constexpr static method fails Martin.vGagern at gmx dot net
                   ` (3 preceding siblings ...)
  2014-08-29 15:54 ` [Bug c++/54002] [C++0x] " paolo.carlini at oracle dot com
@ 2014-08-29 15:59 ` paolo.carlini at oracle dot com
  2014-08-29 15:59 ` paolo at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: paolo.carlini at oracle dot com @ 2014-08-29 15:59 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=54002

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |INVALID

--- Comment #6 from Paolo Carlini <paolo.carlini at oracle dot com> ---
Done.


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

end of thread, other threads:[~2014-08-29 15:59 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-07-17 19:48 [Bug c++/54002] New: [C++0x][constexpr] Initializing constexpr static member using constexpr static method fails Martin.vGagern at gmx dot net
2012-07-17 20:05 ` [Bug c++/54002] " redi at gcc dot gnu.org
2012-07-17 20:06 ` redi at gcc dot gnu.org
2012-07-18  7:09 ` Martin.vGagern at gmx dot net
2014-08-29 15:54 ` [Bug c++/54002] [C++0x] " paolo.carlini at oracle dot com
2014-08-29 15:59 ` paolo.carlini at oracle dot com
2014-08-29 15:59 ` paolo at gcc dot gnu.org

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).