From: Nathan Sidwell Date: Tue, 9 Jan 2001 11:37:07 +0000 (+0000) Subject: class.c (handle_using_decl): Reject using of constructor name of sourcing class. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=186c0fbe03c0b420d7164796a7e19688f1fa0ceb;p=gcc.git class.c (handle_using_decl): Reject using of constructor name of sourcing class. cp: * class.c (handle_using_decl): Reject using of constructor name of sourcing class. Allow injecting of a method with same name as nested class. Fixup error messages. testsuite: * g++.old_deja/g++.pt/using8.C: New test. From-SVN: r38831 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 4c84be0b506..fe4ee2032c0 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2001-01-09 Nathan Sidwell + + * class.c (handle_using_decl): Reject using of constructor name + of sourcing class. Allow injecting of a method with same name as + nested class. Fixup error messages. + 2001-01-09 Joseph S. Myers * decl2.c (lang_decode_option): Handle -Wformat=2. diff --git a/gcc/cp/class.c b/gcc/cp/class.c index 8b04aa3014a..ada9779ec93 100644 --- a/gcc/cp/class.c +++ b/gcc/cp/class.c @@ -1527,7 +1527,13 @@ handle_using_decl (using_decl, t) if (name == constructor_name (ctype) || name == constructor_name_full (ctype)) { - cp_error_at ("using-declaration for constructor", using_decl); + cp_error_at ("`%D' names constructor", using_decl); + return; + } + if (name == constructor_name (t) + || name == constructor_name_full (t)) + { + cp_error_at ("`%D' invalid in `%T'", using_decl, t); return; } @@ -1567,16 +1573,16 @@ handle_using_decl (using_decl, t) the same name already present in the current class. */; else { - cp_error ("`%D' invalid in `%#T'", using_decl, t); + cp_error_at ("`%D' invalid in `%#T'", using_decl, t); cp_error_at (" because of local method `%#D' with same name", OVL_CURRENT (old_value)); return; } } - else + else if (!DECL_ARTIFICIAL (old_value)) { - cp_error ("`%D' invalid in `%#T'", using_decl, t); - cp_error_at (" because of local field `%#D' with same name", old_value); + cp_error_at ("`%D' invalid in `%#T'", using_decl, t); + cp_error_at (" because of local member `%#D' with same name", old_value); return; } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 5eac7717f7e..c47778d31f9 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2001-01-09 Nathan Sidwell + + * g++.old_deja/g++.pt/using8.C: New test. + 2001-01-09 Joseph S. Myers * gcc.dg/format/attr-2.c, gcc.dg/format/attr-3.c: New tests. diff --git a/gcc/testsuite/g++.old-deja/g++.other/using8.C b/gcc/testsuite/g++.old-deja/g++.other/using8.C new file mode 100644 index 00000000000..1dc29de1cb0 --- /dev/null +++ b/gcc/testsuite/g++.old-deja/g++.other/using8.C @@ -0,0 +1,43 @@ +// Build don't link: + +// Copyright (C) 2000 Free Software Foundation, Inc. +// Contributed by Nathan Sidwell 14 Nov 2000 + +// We rejected using decls bringing in functions from a base which would hide a +// nested class of the same name, but only if we had no functions by that name +// already. Also, we failed to find that using declaration during lookup. Also +// we failed to reject using declarations which matched the constructor name. + +struct A +{ + int f (); + void D (); +}; + +struct A2 { + typedef int f; +}; + +struct B : A +{ + using A::f; + struct f {}; +}; + +struct C : A +{ + using A::f; + int f (int); + struct f {}; +}; + +void foo (B *bp, C* cp) +{ + bp->f (); + cp->f (); +} + +struct D : A +{ + using A::D; // ERROR - names constructor +};