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

            Bug ID: 85555
           Summary: Use of concepts gives access to private members.
           Product: gcc
           Version: 7.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: tobias.bruell at gmail dot com
  Target Milestone: ---

Created attachment 44033
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=44033&action=edit
Reproducer

In the following condensed example the unrelated use of concepts seems to be
giving access to the private non-static member functions of a class.

Compile with:
g++-7.3 -std=c++17 -fconcepts gcc_bug.cpp

----------------------------------------------------------------

/*
 * Uncommenting the following line and commenting the line after that
 * makes the program fail to compile (as it should).
 */
//template<typename Target>
template<typename Target, typename... Ts>
concept bool has_resize ()
{
  return requires (Target tgt)
  {
    { tgt.resize () };
  };
};

template<typename Target>
void resize (Target tgt)
{
  if constexpr (has_resize<Target> ())
  {
    tgt.resize ();
  }
}

class MyClass
{
  private:
    int foo (int i)
    {
      return i * 2;
    }
};

int main ()
{
  return MyClass {}.foo (7);
}

Reply via email to