public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/52315] New: [C++11] constexpr object of nested class
@ 2012-02-20 11:05 oleg.endo@t-online.de
  2012-02-20 13:43 ` [Bug c++/52315] " daniel.kruegler at googlemail dot com
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: oleg.endo@t-online.de @ 2012-02-20 11:05 UTC (permalink / raw)
  To: gcc-bugs

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

             Bug #: 52315
           Summary: [C++11] constexpr object of nested class
    Classification: Unclassified
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: oleg.endo@t-online.de


I'm not sure whether this is valid/invalid C++11, but it seems a little weird. 
The following works as expected:

struct B
{
  constexpr B (unsigned v) noexcept : val (v) { }
  constexpr unsigned value (void) const noexcept { return val; }

  unsigned val;
};

struct A
{
  int stuff[B (16).value ()];
};


But moving struct B inside of struct A ...

struct A
{
  struct B
  {
    constexpr B (unsigned v) noexcept : val (v) { }
    constexpr unsigned value (void) const noexcept { return val; }

    unsigned val;
  };

  int stuff[ B (16).value () ];
};

... results in error: size of array 'stuff' is not an integral
constant-expression



Using built-in specs.
COLLECT_GCC=sh-elf-gcc
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/sh-elf/4.7.0/lto-wrapper
Target: sh-elf
Configured with: ../gcc-trunk/configure --target=sh-elf --prefix=/usr/local
--enable-languages=c,c++ --enable-multilib --disable-libssp --disable-nls
--disable-werror --enable-lto --with-newlib --with-gnu-as --with-gnu-ld
--with-system-zlib
Thread model: single
gcc version 4.7.0 20120220 (experimental) (GCC)


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

* [Bug c++/52315] [C++11] constexpr object of nested class
  2012-02-20 11:05 [Bug c++/52315] New: [C++11] constexpr object of nested class oleg.endo@t-online.de
@ 2012-02-20 13:43 ` daniel.kruegler at googlemail dot com
  2012-02-20 15:08 ` redi at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: daniel.kruegler at googlemail dot com @ 2012-02-20 13:43 UTC (permalink / raw)
  To: gcc-bugs

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

Daniel Krügler <daniel.kruegler at googlemail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |daniel.kruegler at
                   |                            |googlemail dot com

--- Comment #1 from Daniel Krügler <daniel.kruegler at googlemail dot com> 2012-02-20 13:27:46 UTC ---
The code looks ok to me: A::B is considered complete after the "};".


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

* [Bug c++/52315] [C++11] constexpr object of nested class
  2012-02-20 11:05 [Bug c++/52315] New: [C++11] constexpr object of nested class oleg.endo@t-online.de
  2012-02-20 13:43 ` [Bug c++/52315] " daniel.kruegler at googlemail dot com
@ 2012-02-20 15:08 ` redi at gcc dot gnu.org
  2012-02-20 23:00 ` jason at gcc dot gnu.org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: redi at gcc dot gnu.org @ 2012-02-20 15:08 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2012-02-20
                 CC|                            |jason at gcc dot gnu.org
     Ever Confirmed|0                           |1

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-02-20 14:53:36 UTC ---
I can't see any reason it's not valid either, but I note that clang has exactly
the same behaviour.  Let's ask Jason.


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

* [Bug c++/52315] [C++11] constexpr object of nested class
  2012-02-20 11:05 [Bug c++/52315] New: [C++11] constexpr object of nested class oleg.endo@t-online.de
  2012-02-20 13:43 ` [Bug c++/52315] " daniel.kruegler at googlemail dot com
  2012-02-20 15:08 ` redi at gcc dot gnu.org
@ 2012-02-20 23:00 ` jason at gcc dot gnu.org
  2012-02-20 23:35 ` jakub at gcc dot gnu.org
  2012-03-13 11:30 ` paolo.carlini at oracle dot com
  4 siblings, 0 replies; 6+ messages in thread
From: jason at gcc dot gnu.org @ 2012-02-20 23:00 UTC (permalink / raw)
  To: gcc-bugs

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

Jason Merrill <jason at gcc dot gnu.org> changed:

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

--- Comment #3 from Jason Merrill <jason at gcc dot gnu.org> 2012-02-20 22:44:01 UTC ---
3.3.7: 1) The potential scope of a name declared in a class consists not only
of the declarative region following the name’s point of declaration, but also
of all function bodies, brace-or-equal-initializers of non-static data members,
and default arguments in that class (including such things in nested classes).

So within B::value, A::stuff is in scope, so we need to wait until A is
complete to parse B::value, so B::value can't be used in constant expressions
in A.


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

* [Bug c++/52315] [C++11] constexpr object of nested class
  2012-02-20 11:05 [Bug c++/52315] New: [C++11] constexpr object of nested class oleg.endo@t-online.de
                   ` (2 preceding siblings ...)
  2012-02-20 23:00 ` jason at gcc dot gnu.org
@ 2012-02-20 23:35 ` jakub at gcc dot gnu.org
  2012-03-13 11:30 ` paolo.carlini at oracle dot com
  4 siblings, 0 replies; 6+ messages in thread
From: jakub at gcc dot gnu.org @ 2012-02-20 23:35 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

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

--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> 2012-02-20 22:59:43 UTC ---
Shouldn't testcases like this be added to the testsuite anyway, with the
expected error?


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

* [Bug c++/52315] [C++11] constexpr object of nested class
  2012-02-20 11:05 [Bug c++/52315] New: [C++11] constexpr object of nested class oleg.endo@t-online.de
                   ` (3 preceding siblings ...)
  2012-02-20 23:35 ` jakub at gcc dot gnu.org
@ 2012-03-13 11:30 ` paolo.carlini at oracle dot com
  4 siblings, 0 replies; 6+ messages in thread
From: paolo.carlini at oracle dot com @ 2012-03-13 11:30 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |trashyankes at wp dot pl

--- Comment #5 from Paolo Carlini <paolo.carlini at oracle dot com> 2012-03-13 11:30:29 UTC ---
*** Bug 52366 has been marked as a duplicate of this bug. ***


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

end of thread, other threads:[~2012-03-13 11:30 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-02-20 11:05 [Bug c++/52315] New: [C++11] constexpr object of nested class oleg.endo@t-online.de
2012-02-20 13:43 ` [Bug c++/52315] " daniel.kruegler at googlemail dot com
2012-02-20 15:08 ` redi at gcc dot gnu.org
2012-02-20 23:00 ` jason at gcc dot gnu.org
2012-02-20 23:35 ` jakub at gcc dot gnu.org
2012-03-13 11:30 ` paolo.carlini at oracle dot 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).