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

            Bug ID: 63151
           Summary: Accessibility error when brace-constructing base class
                    with protected defaulted constructor and member
                    variable
           Product: gcc
           Version: 4.9.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: lukeallardyce at gmail dot com

struct Foo
{
protected:
  Foo() = default;
  int t;
};

struct Bar : public Foo
{
  Bar(): Foo{} { }
};



g++ -std=c++1y -c test.cpp

test.cpp: In constructor 'Bar::Bar()':
test.cpp:4:3: error: 'Foo::Foo()' is protected
   Foo() = default;
   ^
test.cpp:12:14: error: within this context
   Bar(): Foo{} { }


The problem seems to be an astral conjunction of the braces, the defaulted base
class constructor, and the presence of a member variable in the base class.
Removing any one of these gives no error:

class Foo
{
protected:
  Foo() {} // Fine
  int t;
};


class Foo
{
protected:
  Foo() = default; // Also fine
};


class Bar : public Foo
{
  Bar(): Foo() { } // Also fine
};



Tested on:

Linux (Arch):
  gcc version 4.9.1 (GCC)

OSX:
  gcc version 4.9.1 (MacPorts gcc49 4.9.1_0)

Windows:
  gcc version 4.9.0 (x86_64-win32-seh-rev2, Built by MinGW-W64 project)

Reply via email to