https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78326
--- Comment #5 from mib.bugzilla at gmail dot com ---
Thanks so much. It would be great if this problem could be identified in the
compiler, could you create a bug report, or just add another remark if you want
me to create the bug report. Best regards.
Here's a further investigation showing an inconsistency around this issue:
If you compile this with –DNOTEMPLATE (making Derived a non template class)
then GNU will issue an access error.
But if Derived is a template class, then GNU incorrectly allows it.
/*
This shows the GNU inconsistency -- no diagnostic is issued if Derived is a
template class.
Clang, EDG, and Microsoft issue an error if Derived is a template or if it is
not.
sptxl15-478> g++6 -c -w tt.cpp
sptxl15-479> g++6 -c -w -DNOTEMPLATE tt.cpp
tt.cpp: In member function ‘void Derived::foo()’:
tt.cpp:15:17: error: ‘int Base::j’ is private within this context
int i = j;
^
tt.cpp:4:15: note: declared private here
static int j;
^
tt.cpp:15:17: error: ‘int Base::j’ is private within this context
int i = j;
^
tt.cpp:4:15: note: declared private here
static int j;
^
sptxl15-480>
*/
class Base
{
static int j;
};
#ifdef NOTEMPLATE
#else
template <typename T>
#endif
struct Derived : public Base
{
void foo()
{
int i = j;
}
};
int main() {
#ifdef NOTEMPLATE
Derived d;
#else
Derived<int> d;
#endif
d.foo();
return 0;
}