[Bug c++/72780] New: public `using` directive exposes protected base-class constructor

kyle.strand at beckman dot com gcc-bugzilla@gcc.gnu.org
Wed Aug 3 00:43:00 GMT 2016


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

            Bug ID: 72780
           Summary: public `using` directive exposes protected base-class
                    constructor
           Product: gcc
           Version: 5.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: kyle.strand at beckman dot com
  Target Milestone: ---

In the code below, the protected constructors of `Base` and `MyCrtp` should
both be inaccessible and therefore trigger access errors in `main`. However,
the CRTP base-class constructor call does NOT trigger an error in GCC.

class Base {
  protected:
    Base(int) {}
};

class Derived : public Base {
  public:
    using Base::Base;
};

template <typename DERIVED>
class MyCrtp {
  protected:
    template <typename T>
      MyCrtp(T&&) { }
};

class Implementer : public MyCrtp<Implementer> {
  using BASE = MyCrtp<Implementer>;
  public:
    using BASE::MyCrtp;
};

int main()
{
  Derived d(3);     // Compile error with GCC and Clang
  Implementer i(3); // GCC gives NO error
}


More information about the Gcc-bugs mailing list