| Summary: | GCC reports "object is private" when it's accessed through proper accessor | ||
|---|---|---|---|
| Product: | gcc | Reporter: | Vorfeed Canal <vorfeed.canal> |
| Component: | c++ | Assignee: | Not yet assigned to anyone <unassigned> |
| Status: | RESOLVED DUPLICATE | ||
| Severity: | normal | CC: | ppalka, StevenSun2021, ts826848, webrown.cpp |
| Priority: | P3 | Keywords: | rejects-valid |
| Version: | 10.2.1 | ||
| Target Milestone: | --- | ||
| See Also: |
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109576 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121707 |
||
| Host: | Target: | ||
| Build: | Known to work: | ||
| Known to fail: | Last reconfirmed: | 2020-08-20 00:00:00 | |
| Bug Depends on: | |||
| Bug Blocks: | 55004 | ||
|
Description
Vorfeed Canal
2020-08-19 20:36:21 UTC
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';
| ^~~
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;
|