Given file `ptest.cpp': class A {int i;}; class B : public A {B() {A::i=0;}}; I get (with quotes replaced with ASCII and some bijective directory simplification) $ g++ -v ptest.cpp Reading specs from /opt/local/gcc402/bin/../lib/gcc/i686-pc-linux-gnu/4.0.2/specs Target: i686-pc-linux-gnu Configured with: /opt/build/gcc-4.0.2/configure --with-included-gettext --enable-libgcj --enable-__cxa_atexit --with-gmp=/usr/packages/libgmp41 --with-mpfr=/usr/packages/libmpfr22 --with-gmp-ldflags=-Wl,-rpath,/usr/packages/libgmp41/lib --with-mpfr-ldflags=-Wl,-rpath,/usr/packages/libmpfr22/lib --enable-languages=ada,c,c++,f95,java --datadir=/usr/packages/gcc402/share --with-gnu-as --with-as=/usr/packages/gcc402/i686-pc-linux-gnu/bin/as --with-gnu-ld --with-ld=/usr/packages/gcc402/i686-pc-linux-gnu/bin/ld --with-local-prefix=/usr/packages/gcc402 --with-gxx-include-dir=/usr/packages/gcc402/include/c++ --prefix=/usr/packages/gcc402 Thread model: posix gcc version 4.0.2 (TWW) /opt/local/gcc402/bin/../libexec/gcc/i686-pc-linux-gnu/4.0.2/cc1plus -quiet -v -iprefix /opt/local/gcc402/bin/../lib/gcc/i686-pc-linux-gnu/4.0.2/ -D_GNU_SOURCE ptest.cpp -quiet -dumpbase ptest.cpp -mtune=pentiumpro -auxbase ptest -version -o /tmp/cccHYSJN.s ignoring nonexistent directory "/opt/local/gcc402/bin/../lib/gcc/i686-pc-linux-gnu/4.0.2/../../../../i686-pc-linux-gnu/include" ignoring duplicate directory "/usr/packages/gcc402/lib/gcc/i686-pc-linux-gnu/4.0.2/include" ignoring nonexistent directory "/usr/packages/gcc402/lib/gcc/i686-pc-linux-gnu/4.0.2/../../../../i686-pc-linux-gnu/include" #include "..." search starts here: #include <...> search starts here: /opt/local/gcc402/bin/../lib/gcc/i686-pc-linux-gnu/4.0.2/include /usr/packages/gcc402/include/c++ /usr/packages/gcc402/include/c++/i686-pc-linux-gnu /usr/packages/gcc402/include/c++/backward /usr/packages/gcc402/include /usr/include End of search list. GNU C++ version 4.0.2 (TWW) (i686-pc-linux-gnu) compiled by GNU C version 4.0.2 (TWW). GGC heuristics: --param ggc-min-expand=98 --param ggc-min-heapsize=128115 ptest.cpp: In constructor `B::B()': ptest.cpp:1: error: `int A::i' is private ptest.cpp:2: error: within this context ptest.cpp:1: error: `int A::i' is private ptest.cpp:2: error: within this context The error is quite accurate, but it's given twice! The error is only printed once if "A::" is omitted from the file.
Related to PR 19375. Confirmed, a regression.
I'll look into this.
I thought it would simply be a matter of using TREE_NO_WARNING ... until I realized this was not a warning but an error. Anyway, following the method of the fix for PR19375, I bootstrapped and tested this patch below, but since this is a language issue and my understanding of C++ is non-existing, I'm unassigning myself from this PR. Index: semantics.c =================================================================== --- semantics.c (revision 117672) +++ semantics.c (working copy) @@ -1559,8 +1559,12 @@ finish_qualified_id_expr (tree qualifyin transformation, as there is no "this" pointer. */ ; else if (TREE_CODE (expr) == FIELD_DECL) - expr = finish_non_static_data_member (expr, current_class_ref, - qualifying_class); + { + push_deferring_access_checks (dk_no_check); + expr = finish_non_static_data_member (expr, current_class_ref, + qualifying_class); + pop_deferring_access_checks (); + } else if (BASELINK_P (expr) && !processing_template_decl) { tree fns;
won't fix in GCC-4.0.x. Adjusting milestone.
Subject: Bug 29048 Author: jason Date: Tue Feb 12 17:26:34 2008 New Revision: 132261 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=132261 Log: PR c++/29048 * semantics.c (finish_qualified_id_expr): Avoid duplicate access check here, too. Modified: trunk/gcc/cp/ChangeLog trunk/gcc/cp/semantics.c
Subject: Bug 29048 Author: jason Date: Tue Feb 12 19:25:28 2008 New Revision: 132265 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=132265 Log: PR c++/29048 * semantics.c (finish_qualified_id_expr): Avoid duplicate access check here, too. Added: trunk/gcc/testsuite/g++.dg/lookup/duperr1.C
Fixed for 4.3.0, not worth fixing on earlier release branches.