Bug 58740 - incorrect access check of static base class member in derived template class
Summary: incorrect access check of static base class member in derived template class
Status: RESOLVED DUPLICATE of bug 41437
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.8.1
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: accepts-invalid
Depends on:
Blocks:
 
Reported: 2013-10-15 20:46 UTC by Lewis Hyatt
Modified: 2021-08-27 18:15 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work: 11.1.0
Known to fail: 10.1.0, 8.1.0
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Lewis Hyatt 2013-10-15 20:46:31 UTC
///////////////
class A {
    static int p;
};
int A::p = 0;
template<int=0>
struct B : A {
    B() {(void)p;}
};
int main() {
    B<>();
}
///////////////

This should fail to compile as A::p is private, but gcc accepts it.

$ g++ -v t.cpp
Using built-in specs.
COLLECT_GCC=/usr/local/gcc48/bin/g++
COLLECT_LTO_WRAPPER=/usr/local/gcc-4.8.1/libexec/gcc/x86_64-unknown-linux-gnu/4.8.1/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ./configure --enable-threads=posix --enable-__cxa_atexit --prefix=/usr/local/gcc-4.8.1
Thread model: posix
gcc version 4.8.1 (GCC)
COLLECT_GCC_OPTIONS='-v' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
 /usr/local/gcc-4.8.1/libexec/gcc/x86_64-unknown-linux-gnu/4.8.1/cc1plus -quiet -v -D_GNU_SOURCE t.cpp -quiet -dumpbase t.cpp -mtune=generic -march=x86-64 -auxbase t -version -o /tmp/ccwT0oUt.s
GNU C++ (GCC) version 4.8.1 (x86_64-unknown-linux-gnu)
	compiled by GNU C version 4.8.1, GMP version 4.3.2, MPFR version 2.4.2-p1, MPC version 0.8.1
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory "/usr/local/gcc-4.8.1/lib/gcc/x86_64-unknown-linux-gnu/4.8.1/../../../../x86_64-unknown-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/gcc-4.8.1/lib/gcc/x86_64-unknown-linux-gnu/4.8.1/../../../../include/c++/4.8.1
 /usr/local/gcc-4.8.1/lib/gcc/x86_64-unknown-linux-gnu/4.8.1/../../../../include/c++/4.8.1/x86_64-unknown-linux-gnu
 /usr/local/gcc-4.8.1/lib/gcc/x86_64-unknown-linux-gnu/4.8.1/../../../../include/c++/4.8.1/backward
 /usr/local/gcc-4.8.1/lib/gcc/x86_64-unknown-linux-gnu/4.8.1/include
 /usr/local/include
 /usr/local/gcc-4.8.1/include
 /usr/local/gcc-4.8.1/lib/gcc/x86_64-unknown-linux-gnu/4.8.1/include-fixed
 /usr/include
End of search list.
GNU C++ (GCC) version 4.8.1 (x86_64-unknown-linux-gnu)
	compiled by GNU C version 4.8.1, GMP version 4.3.2, MPFR version 2.4.2-p1, MPC version 0.8.1
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 9381368e685e312c931bb6a2db2d568c
COLLECT_GCC_OPTIONS='-v' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
 as -v --64 -o /tmp/cciB1xZN.o /tmp/ccwT0oUt.s
GNU assembler version 2.20.1 (x86_64-linux-gnu) using BFD version (GNU Binutils for Ubuntu) 2.20.1-system.20100303
COMPILER_PATH=/usr/local/gcc-4.8.1/libexec/gcc/x86_64-unknown-linux-gnu/4.8.1/:/usr/local/gcc-4.8.1/libexec/gcc/x86_64-unknown-linux-gnu/4.8.1/:/usr/local/gcc-4.8.1/libexec/gcc/x86_64-unknown-linux-gnu/:/usr/local/gcc-4.8.1/lib/gcc/x86_64-unknown-linux-gnu/4.8.1/:/usr/local/gcc-4.8.1/lib/gcc/x86_64-unknown-linux-gnu/
LIBRARY_PATH=/usr/local/gcc-4.8.1/lib/gcc/x86_64-unknown-linux-gnu/4.8.1/:/usr/local/gcc-4.8.1/lib/gcc/x86_64-unknown-linux-gnu/4.8.1/../../../../lib64/:/lib/../lib64/:/usr/lib/../lib64/:/usr/local/gcc-4.8.1/lib/gcc/x86_64-unknown-linux-gnu/4.8.1/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
 /usr/local/gcc-4.8.1/libexec/gcc/x86_64-unknown-linux-gnu/4.8.1/collect2 --eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 /usr/lib/../lib64/crt1.o /usr/lib/../lib64/crti.o /usr/local/gcc-4.8.1/lib/gcc/x86_64-unknown-linux-gnu/4.8.1/crtbegin.o -L/usr/local/gcc-4.8.1/lib/gcc/x86_64-unknown-linux-gnu/4.8.1 -L/usr/local/gcc-4.8.1/lib/gcc/x86_64-unknown-linux-gnu/4.8.1/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/usr/local/gcc-4.8.1/lib/gcc/x86_64-unknown-linux-gnu/4.8.1/../../.. /tmp/cciB1xZN.o -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /usr/local/gcc-4.8.1/lib/gcc/x86_64-unknown-linux-gnu/4.8.1/crtend.o /usr/lib/../lib64/crtn.o
Comment 1 Jonathan Wakely 2013-10-15 21:22:09 UTC
There are loads opf existing bugs regarding the lack of access checking in templates, this is almost certainly a dup of one of them
Comment 2 Barry Revzin 2015-07-08 16:54:16 UTC
For what it's worth, this still compiles in 5.1.
Comment 3 Andrew Pinski 2021-08-27 18:15:45 UTC
Dup of bug 41437 and fixed for GCC 11+.

*** This bug has been marked as a duplicate of bug 41437 ***