Bug 6936 - member "using" binds wrong
Summary: member "using" binds wrong
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 3.1.1
: P3 normal
Target Milestone: 4.7.0
Assignee: fabien
URL:
Keywords: monitored, rejects-valid
Depends on:
Blocks: c++-lookup, c++-name-lookup
  Show dependency treegraph
 
Reported: 2002-06-05 09:46 UTC by ncm
Modified: 2012-01-03 09:59 UTC (History)
8 users (show)

See Also:
Host: i686-pc-linux-gnu
Target: i686-pc-linux-gnu
Build: i686-pc-linux-gnu
Known to work:
Known to fail: 4.5.1, 4.6.0
Last reconfirmed: 2011-10-09 21:39:27


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description ncm 2002-06-05 09:46:00 UTC
A member "using" declaration fails to override an inherited matching name.
As a result, in the example below, the compiler reports a type error.

The access-adjustment ("private:") adds a further wrinkle.  According
to the current standard, it should be ignored, and seems to be now, but
if the using-declaration really becomes enough of a declaration to hide
the inherited ``void i()'', it had better not become enough of a 
declaration to be private, too.

Release:
3.1.1 20020515 (prerelease)

Environment:
System: Linux ipc 2.4.19-pre4 #3 SMP Fri Mar 29 02:57:10 EST 2002 i686 unknown
Architecture: i686
host: i686-pc-linux-gnu
build: i686-pc-linux-gnu
target: i686-pc-linux-gnu
configured with: ../gcc-3.1/configure --enable-languages=c,c++ --enable-threads=posix --prefix=/ncm/gnu-3.1 --enable-concept-checks

How-To-Repeat:
$ cat /tmp/a.cc
struct Baser { enum { j, i }; };
struct Base : Baser { static void j() {} static void i() {} };
struct Derv : Base  {
  using Baser::j;
private:
  using Baser::i;
};
int k = Derv::j;
int l = Derv::i;

$ g++ -v -c /tmp/a.cc
Reading specs from /ncm/gnu-3.1/lib/gcc-lib/i686-pc-linux-gnu/3.1.1/specs
Configured with: ../gcc-3.1/configure --enable-languages=c,c++ --enable-threads=posix --prefix=/ncm/gnu-3.1 --enable-concept-checks
Thread model: posix
gcc version 3.1.1 20020515 (prerelease)
 /ncm/gnu-3.1/lib/gcc-lib/i686-pc-linux-gnu/3.1.1/cc1plus -v -D__GNUC__=3 -D__GNUC_MINOR__=1 -D__GNUC_PATCHLEVEL__=1 -D__ELF__ -Dunix -D__gnu_linux__ -Dlinux -D__ELF__ -D__unix__ -D__gnu_linux__ -D__linux__ -D__unix -D__linux -Asystem=posix -D__NO_INLINE__ -D__STDC_HOSTED__=1 -D_GNU_SOURCE -Acpu=i386 -Amachine=i386 -Di386 -D__i386 -D__i386__ -D__tune_i686__ -D__tune_pentiumpro__ /tmp/a.cc -D__GNUG__=3 -D__DEPRECATED -D__EXCEPTIONS -D__GXX_ABI_VERSION=100 -quiet -dumpbase a.cc -version -o /tmp/ccIMt85B.s
GNU CPP version 3.1.1 20020515 (prerelease) (cpplib) (i386 Linux/ELF)
GNU C++ version 3.1.1 20020515 (prerelease) (i686-pc-linux-gnu)
        compiled by GNU C version 3.1 20020422 (prerelease).
ignoring nonexistent directory "/ncm/gnu-3.1/i686-pc-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /ncm/gnu-3.1/include/g++-v3
 /ncm/gnu-3.1/include/g++-v3/i686-pc-linux-gnu
 /ncm/gnu-3.1/include/g++-v3/backward
 /usr/local/include
 /ncm/gnu-3.1/include
 /ncm/gnu-3.1/lib/gcc-lib/i686-pc-linux-gnu/3.1.1/include
 /usr/include
End of search list.
/tmp/a.cc:8: invalid conversion from `void (*)()' to `int'
/tmp/a.cc:9: invalid conversion from `void (*)()' to `int'
Comment 1 Kriang Lerdsuwanakij 2002-10-27 07:16:56 UTC
State-Changed-From-To: open->analyzed
State-Changed-Why: Confirmed.
Comment 2 Wolfgang Bangerth 2011-10-09 13:38:29 UTC
Still happens with gcc4.5.1. Note that it doesn't matter which of
the variables are accessed since it's a name lookup problem and
name lookup happens before access control checking.
Comment 3 fabien 2011-10-09 13:54:21 UTC
(In reply to comment #2)
> Still happens with gcc4.5.1. 

... And on 4.6, 4.7 as well.
Comment 4 Jason Merrill 2011-11-14 17:56:01 UTC
Author: jason
Date: Mon Nov 14 17:55:57 2011
New Revision: 181359

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=181359
Log:
	PR c++/6936
	PR c++/25994
	PR c++/26256
	PR c++/30195
	* search.c (lookup_field_1): Look through USING_DECL.
	(lookup_field_r): Call lookup_fnfields_slot instead of
	lookup_fnfields_1.
	* semantics.c (finish_member_declaration): Remove the check that
	prevents USING_DECLs from being verified by
	pushdecl_class_level. Call add_method for using declarations that
	designates functions if the using declaration is in a template
	class. Set DECL_IGNORED_P on class-scope using declarations.
	* typeck.c (build_class_member_access_expr): Handle USING_DECLs.
	* class.c (check_field_decls): Keep using declarations.
	(add_method): Remove two diagnostics about conflicting using
	declarations.
	* parser.c (cp_parser_nonclass_name): Handle USING_DECLs.
	* decl.c (start_enum): Call xref_tag whenever possible.
	* cp-tree.h (strip_using_decl): Declare, and reident the previous
	function.
	* name-lookup.c (strip_using_decl): New function.
	(supplement_binding_1): Call strip_using_decl on decl and
	bval. Perform most of the checks with USING_DECLs stripped.  Also
	check that the target decl and the target bval does not refer to
	the same declaration. Allow pushing an enum multiple times in a
	template class. Adjustment to diagnose using redeclarations. Call
	diagnose_name_conflict.
	(push_class_level_binding): Call strip_using_decl on decl and
	bval. Perform most of the checks with USING_DECLs stripped. Return
	true if both decl and bval refer to USING_DECLs and are dependent.
	(diagnose_name_conflict): New function.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/forw_enum10.C
    trunk/gcc/testsuite/g++.dg/debug/using4.C
    trunk/gcc/testsuite/g++.dg/debug/using5.C
    trunk/gcc/testsuite/g++.dg/lookup/pr6936.C
    trunk/gcc/testsuite/g++.dg/lookup/using24.C
    trunk/gcc/testsuite/g++.dg/lookup/using25.C
    trunk/gcc/testsuite/g++.dg/lookup/using26.C
    trunk/gcc/testsuite/g++.dg/lookup/using27.C
    trunk/gcc/testsuite/g++.dg/lookup/using28.C
    trunk/gcc/testsuite/g++.dg/lookup/using29.C
    trunk/gcc/testsuite/g++.dg/lookup/using30.C
    trunk/gcc/testsuite/g++.dg/lookup/using31.C
    trunk/gcc/testsuite/g++.dg/lookup/using32.C
    trunk/gcc/testsuite/g++.dg/lookup/using33.C
    trunk/gcc/testsuite/g++.dg/lookup/using34.C
    trunk/gcc/testsuite/g++.dg/lookup/using35.C
    trunk/gcc/testsuite/g++.dg/lookup/using36.C
    trunk/gcc/testsuite/g++.dg/lookup/using37.C
    trunk/gcc/testsuite/g++.dg/lookup/using38.C
    trunk/gcc/testsuite/g++.dg/lookup/using39.C
    trunk/gcc/testsuite/g++.dg/lookup/using40.C
    trunk/gcc/testsuite/g++.dg/lookup/using41.C
    trunk/gcc/testsuite/g++.dg/lookup/using42.C
    trunk/gcc/testsuite/g++.dg/lookup/using44.C
    trunk/gcc/testsuite/g++.dg/lookup/using45.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/class.c
    trunk/gcc/cp/cp-tree.h
    trunk/gcc/cp/decl.c
    trunk/gcc/cp/name-lookup.c
    trunk/gcc/cp/parser.c
    trunk/gcc/cp/search.c
    trunk/gcc/cp/semantics.c
    trunk/gcc/cp/typeck.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/g++.dg/abi/mangle41.C
    trunk/gcc/testsuite/g++.dg/inherit/using4.C
    trunk/gcc/testsuite/g++.dg/lookup/name-clash9.C
    trunk/gcc/testsuite/g++.dg/parse/ctor5.C
    trunk/gcc/testsuite/g++.dg/template/static4.C
    trunk/gcc/testsuite/g++.dg/template/typedef1.C
    trunk/gcc/testsuite/g++.dg/template/using2.C
    trunk/gcc/testsuite/g++.old-deja/g++.brendan/misc14.C
    trunk/gcc/testsuite/g++.old-deja/g++.bugs/900127_02.C
    trunk/gcc/testsuite/g++.old-deja/g++.jason/scoping16.C
    trunk/gcc/testsuite/g++.old-deja/g++.other/anon7.C
    trunk/gcc/testsuite/g++.old-deja/g++.other/redecl1.C
    trunk/gcc/testsuite/g++.old-deja/g++.other/typedef7.C
    trunk/gcc/testsuite/g++.old-deja/g++.other/using1.C
Comment 5 fabien 2011-11-16 08:28:28 UTC
Fixed.