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

            Bug ID: 96716
           Summary: GCC reports "object is private" when it's accessed
                    through proper accessor
           Product: gcc
           Version: 10.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: vorfeed.canal at gmail dot com
  Target Milestone: ---

The following program doesn't work ( https://godbolt.org/z/87cr44 ):

#include <array>
#include <string_view>

class Foo {
 public:
  auto constexpr  getfoo() const -> std::string_view {
    return {foo.data(), 2};
  }
 private:
  const std::array<char, 3> foo = {'a', 'b', '\0'};
};

inline constexpr Foo foo;

template <typename>
class Bar {
 public:
  static constexpr auto bar = foo.getfoo();
};

auto& baz = Bar<int>::bar;

Error message:
<source>: In instantiation of 'constexpr const std::basic_string_view<char>
Bar<int>::bar':

<source>:21:23:   required from here

<source>:18:25: error: 'const std::array<char, 3> Foo::foo' is private within
this context

   18 |   static constexpr auto bar = foo.getfoo();

      |                         ^~~

<source>:10:29: note: declared private here

   10 |   const std::array<char, 3> foo = {'a', 'b', '\0'};

      |                             ^~~

Compiler returned: 1

All other compilers work fine ( https://godbolt.org/z/WvfrPf )

Reply via email to