public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/96716] New: GCC reports "object is private" when it's accessed through proper accessor
@ 2020-08-19 20:36 vorfeed.canal at gmail dot com
  2020-08-20  8:06 ` [Bug c++/96716] " redi at gcc dot gnu.org
  2020-08-20  8:09 ` redi at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: vorfeed.canal at gmail dot com @ 2020-08-19 20:36 UTC (permalink / raw)
  To: gcc-bugs

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 )

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

* [Bug c++/96716] GCC reports "object is private" when it's accessed through proper accessor
  2020-08-19 20:36 [Bug c++/96716] New: GCC reports "object is private" when it's accessed through proper accessor vorfeed.canal at gmail dot com
@ 2020-08-20  8:06 ` redi at gcc dot gnu.org
  2020-08-20  8:09 ` redi at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: redi at gcc dot gnu.org @ 2020-08-20  8:06 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2020-08-20
     Ever confirmed|0                           |1
           Keywords|                            |rejects-valid

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Reduced:

struct string_view
{
  constexpr string_view(const char* p) : p(p) { }
  const char* p;
};

class Foo {
 public:
  constexpr string_view getfoo() const {
    return {&foo};
  }
 private:
  const char foo = 'c';
};

inline constexpr Foo foo;

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

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


pr96716.C: In instantiation of 'constexpr const string_view Bar<int>::bar':
pr96716.C:24:23:   required from here
pr96716.C:21:25: error: 'const char Foo::foo' is private within this context
   21 |   static constexpr auto bar = foo.getfoo();
      |                         ^~~
pr96716.C:13:14: note: declared private here
   13 |   const char foo = 'c';
      |              ^~~

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

* [Bug c++/96716] GCC reports "object is private" when it's accessed through proper accessor
  2020-08-19 20:36 [Bug c++/96716] New: GCC reports "object is private" when it's accessed through proper accessor vorfeed.canal at gmail dot com
  2020-08-20  8:06 ` [Bug c++/96716] " redi at gcc dot gnu.org
@ 2020-08-20  8:09 ` redi at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: redi at gcc dot gnu.org @ 2020-08-20  8:09 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Slightly further reduced:

struct string_view
{
  constexpr string_view(const char* p) : p(p) { }
  const char* p;
};

struct Foo {
  constexpr string_view getfoo() const {
    return {&foo};
  }
private:
  const char foo = 'c';
};

inline constexpr Foo foo;

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

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

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

end of thread, other threads:[~2020-08-20  8:09 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-19 20:36 [Bug c++/96716] New: GCC reports "object is private" when it's accessed through proper accessor vorfeed.canal at gmail dot com
2020-08-20  8:06 ` [Bug c++/96716] " redi at gcc dot gnu.org
2020-08-20  8:09 ` 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).