public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/49604] New: forward-declared enum in class scope is private in context of constexpr
@ 2011-07-01  3:21 b.r.longbons at gmail dot com
  2011-07-01  3:51 ` [Bug c++/49604] forward-declared enum's elements in class scope gets default access (class vs struct) pinskia at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: b.r.longbons at gmail dot com @ 2011-07-01  3:21 UTC (permalink / raw)
  To: gcc-bugs

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

           Summary: forward-declared enum in class scope is private in
                    context of constexpr
           Product: gcc
           Version: 4.6.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: b.r.longbons@gmail.com


Created attachment 24652
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=24652
Minimal testcase

If an enum is forward-declared as a public member of a class (but not a
struct), and the values are defined afterward, then the enum values cannot be
be used in the context of a constexpr:

enum-broken.cpp:9:26: error: 'Foo::impl_t Foo::X' is private
enum-broken.cpp:11:27: error: within this context

(see attachment)

Workaround:
Use 'struct' instead of 'class'.

What works:
It works fine if 'struct' is used instead of 'class'.
It works fine without the constexpr.
It works fine if the enum values are defined in the declaration.
It works find if the nested type is a struct with a static member.

Versions:
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-pc-linux-gnu/4.6.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /var/tmp/portage/sys-devel/gcc-4.6.0/work/gcc-4.6.0/configure
--prefix=/usr --bindir=/usr/x86_64-pc-linux-gnu/gcc-bin/4.6.0
--includedir=/usr/lib/gcc/x86_64-pc-linux-gnu/4.6.0/include
--datadir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.6.0
--mandir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.6.0/man
--infodir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.6.0/info
--with-gxx-include-dir=/usr/lib/gcc/x86_64-pc-linux-gnu/4.6.0/include/g++-v4
--host=x86_64-pc-linux-gnu --build=x86_64-pc-linux-gnu --disable-altivec
--disable-fixed-point --without-ppl --without-cloog --enable-lto --disable-nls
--with-system-zlib --disable-werror --enable-secureplt --enable-multilib
--enable-libmudflap --disable-libssp --enable-libgomp --enable-cld
--with-python-dir=/share/gcc-data/x86_64-pc-linux-gnu/4.6.0/python
--enable-checking=release --disable-libgcj --enable-languages=c,c++,fortran
--enable-shared --enable-threads=posix --enable-__cxa_atexit
--enable-clocale=gnu --with-bugurl=http://bugs.gentoo.org/
--with-pkgversion='Gentoo 4.6.0 p1.2, pie-0.4.5'
Thread model: posix
gcc version 4.6.0 (Gentoo 4.6.0 p1.2, pie-0.4.5) 


Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/x86_64-linux-gnu/gcc/x86_64-linux-gnu/4.6.1/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 4.6.1-1'
--with-bugurl=file:///usr/share/doc/gcc-4.6/README.Bugs
--enable-languages=c,c++,fortran,objc,obj-c++,go --prefix=/usr
--program-suffix=-4.6 --enable-shared --enable-multiarch
--with-multiarch-defaults=x86_64-linux-gnu --enable-linker-build-id
--with-system-zlib --libexecdir=/usr/lib/x86_64-linux-gnu
--without-included-gettext --enable-threads=posix
--with-gxx-include-dir=/usr/include/c++/4.6 --libdir=/usr/lib/x86_64-linux-gnu
--enable-nls --enable-clocale=gnu --enable-libstdcxx-debug
--enable-libstdcxx-time=yes --enable-plugin --enable-objc-gc
--with-arch-32=i586 --with-tune=generic --enable-checking=release
--build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.6.1 (Debian 4.6.1-1)


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

* [Bug c++/49604] forward-declared enum's elements in class scope gets default access (class vs struct)
  2011-07-01  3:21 [Bug c++/49604] New: forward-declared enum in class scope is private in context of constexpr b.r.longbons at gmail dot com
@ 2011-07-01  3:51 ` pinskia at gcc dot gnu.org
  2014-03-28 16:32 ` b.r.longbons at gmail dot com
  2014-10-16 11:21 ` redi at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2011-07-01  3:51 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|forward-declared enum in    |forward-declared enum's
                   |class scope is private in   |elements in class scope
                   |context of constexpr        |gets default access (class
                   |                            |vs struct)

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> 2011-07-01 03:51:29 UTC ---
>It works fine without the constexpr.

I have the same failure even without constexpr.

Here is a testcase which should fail but currently is accepted:
struct Foo
{
private:
    int val;
    enum impl_t : int;
public:
    Foo(impl_t v) : val(v) {}
};
enum Foo::impl_t : int { X };

Foo test = Foo::X;


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

* [Bug c++/49604] forward-declared enum's elements in class scope gets default access (class vs struct)
  2011-07-01  3:21 [Bug c++/49604] New: forward-declared enum in class scope is private in context of constexpr b.r.longbons at gmail dot com
  2011-07-01  3:51 ` [Bug c++/49604] forward-declared enum's elements in class scope gets default access (class vs struct) pinskia at gcc dot gnu.org
@ 2014-03-28 16:32 ` b.r.longbons at gmail dot com
  2014-10-16 11:21 ` redi at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: b.r.longbons at gmail dot com @ 2014-03-28 16:32 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Ben Longbons <b.r.longbons at gmail dot com> ---
Still an issue with 4.9 as of 2014-03-22


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

* [Bug c++/49604] forward-declared enum's elements in class scope gets default access (class vs struct)
  2011-07-01  3:21 [Bug c++/49604] New: forward-declared enum in class scope is private in context of constexpr b.r.longbons at gmail dot com
  2011-07-01  3:51 ` [Bug c++/49604] forward-declared enum's elements in class scope gets default access (class vs struct) pinskia at gcc dot gnu.org
  2014-03-28 16:32 ` b.r.longbons at gmail dot com
@ 2014-10-16 11:21 ` redi at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: redi at gcc dot gnu.org @ 2014-10-16 11:21 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |accepts-invalid,
                   |                            |rejects-valid
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2014-10-16
     Ever confirmed|0                           |1


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

end of thread, other threads:[~2014-10-16 11:21 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-07-01  3:21 [Bug c++/49604] New: forward-declared enum in class scope is private in context of constexpr b.r.longbons at gmail dot com
2011-07-01  3:51 ` [Bug c++/49604] forward-declared enum's elements in class scope gets default access (class vs struct) pinskia at gcc dot gnu.org
2014-03-28 16:32 ` b.r.longbons at gmail dot com
2014-10-16 11:21 ` redi 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).