Bug 39786 - [4.3/4.4 Regression] Qualified name lookup through different numbers of using directives
Summary: [4.3/4.4 Regression] Qualified name lookup through different numbers of using...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.3.2
: P2 normal
Target Milestone: 4.4.3
Assignee: Jason Merrill
URL:
Keywords: accepts-invalid, rejects-valid, wrong-code
Depends on:
Blocks:
 
Reported: 2009-04-16 19:09 UTC by Hubert Tong
Modified: 2009-11-03 22:09 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work: 3.3.6 4.5.0
Known to fail: 4.1.2 4.3.2 4.4.0
Last reconfirmed: 2009-11-03 20:45:45


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Hubert Tong 2009-04-16 19:09:37 UTC
It appears that qualified name lookup fails to find the correct candidate set
for overload resolution in the test case below.

For the following test case, the symptom is rejects-valid; however, it is simple
to produce variants for wrong-code and accepts-invalid.

The Comeau online compiler compiles the test case successfully.

ISO/IEC 14882:2003 Sub-clause 3.4.3.2 [namespace.qual] paragraph 2:
===
Given X::m (where X is a user-declared namespace), or given ::m (where X is the global namespace), let
S be the set of all declarations of m in X and in the transitive closure of all namespaces nominated by
using-directives in X and its used namespaces, except that using-directives are ignored in any namespace,
including X, directly containing one or more declarations of m.  No namespace is searched more than once
in the lookup of a name.  If S is the empty set, the program is ill-formed.  Otherwise, if S has exactly one
member, or if the context of the reference is a using-declaration (7.3.3), S is the required set of declarations
of m.  Otherwise if the use of m is not one that allows a unique declaration to be chosen from S, the program
is ill-formed.
===

We are looking for `f' from the global namespace.  The global namespace does not directly contain a declaration
of `f'.  There are two namespaces nominated by using-directives in the global namespace, ::A and ::B.

There are no using-directives in ::A.  ::B does not directly contain a declaration of `f'.  There is a using-
directive in ::B nominating ::B::C.  There are no using-directives in ::B::C.

S is { ::A::f(char *), ::B::C::f(int) } and overload resolution on the call `::f(0)' should pick ::B::C::f(int).

### Self-contained source (namelookup.C):
namespace A {
    char (*f(char *p))[13] { return 0; }
}

namespace B {
    namespace C {
        char (*f(int p))[42] { return 0; }
    }
    using namespace C;
}

using namespace B;
using namespace A;

char x[sizeof *::f(0) == 42 ? 1 : -1];


### Command to reproduce:
g++ -c namelookup.C


### Compiler output:
namelookup.C:15: error: size of array x is negative


### g++ -v output:
Using built-in specs.
Target: powerpc64-suse-linux
Configured with: ../configure --prefix=/usr --infodir=/usr/share/info --mandir=/usr/share/man --libdir=/usr/lib64 --libexecdir=/usr/lib64 --enable-languages=c,c++,objc,fortran,obj-c++,java --enable-checking=release --with-gxx-include-dir=/usr/include/c++/4.3 --enable-ssp --disable-libssp --with-bugurl=http://bugs.opensuse.org/ --with-pkgversion='SUSE Linux' --disable-libgcj --disable-libmudflap --with-slibdir=/lib64 --with-system-zlib --enable-__cxa_atexit --enable-libstdcxx-allocator=new --disable-libstdcxx-pch --enable-version-specific-runtime-libs --program-suffix=-4.3 --enable-linux-futex --without-system-libunwind --with-cpu=power4 --enable-secureplt --with-long-double-128 --build=powerpc64-suse-linux
Thread model: posix
gcc version 4.3.2 [gcc-4_3-branch revision 141291] (SUSE Linux)
Comment 1 Richard Biener 2009-04-17 09:14:10 UTC
Confirmed.  The code was accepted with 3.3.6
Comment 2 Richard Biener 2009-08-04 12:30:06 UTC
GCC 4.3.4 is being released, adjusting target milestone.
Comment 3 Jason Merrill 2009-11-03 20:45:45 UTC
This test now passes with 4.5, presumably because of

2009-10-28  Jason Merrill  <jason@redhat.com>

        Core issue 812, 861
        * name-lookup.c (set_decl_namespace): Deal properly with inline
        namespaces.
        (qualified_lookup_using_namespace): Overhaul.
        * pt.c (print_candidates): Handle getting an OVERLOAD.

I suppose I could apply the qualified_lookup_using_namespace hunk to 4.3 and 4.4.
Comment 4 Jason Merrill 2009-11-03 20:52:47 UTC
Subject: Bug 39786

Author: jason
Date: Tue Nov  3 20:52:30 2009
New Revision: 153865

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=153865
Log:
	PR c++/39786
	* g++.dg/lookup/using22.C: New.

Added:
    trunk/gcc/testsuite/g++.dg/lookup/using22.C
Modified:
    trunk/gcc/testsuite/ChangeLog

Comment 5 Jason Merrill 2009-11-03 21:34:12 UTC
Subject: Bug 39786

Author: jason
Date: Tue Nov  3 21:33:55 2009
New Revision: 153872

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=153872
Log:
	PR c++/41876
	* parser.c (cp_parser_exception_declaration): Pass true to
	is_condition parm of cp_parser_type_specifier_seq.
	(cp_parser_omp_for_loop): Likewise.

	PR c++/39786, Core issue 812, 861
	* name-lookup.c (qualified_lookup_using_namespace): Overhaul.


Added:
    branches/gcc-4_4-branch/gcc/testsuite/g++.dg/cpp0x/inline-ns3.C
      - copied unchanged from r153682, trunk/gcc/testsuite/g++.dg/cpp0x/inline-ns3.C
    branches/gcc-4_4-branch/gcc/testsuite/g++.dg/lookup/using22.C
      - copied unchanged from r153865, trunk/gcc/testsuite/g++.dg/lookup/using22.C
    branches/gcc-4_4-branch/gcc/testsuite/g++.dg/parse/eh-decl.C
      - copied unchanged from r153864, trunk/gcc/testsuite/g++.dg/parse/eh-decl.C
Modified:
    branches/gcc-4_4-branch/gcc/cp/ChangeLog
    branches/gcc-4_4-branch/gcc/cp/name-lookup.c
    branches/gcc-4_4-branch/gcc/cp/parser.c
    branches/gcc-4_4-branch/gcc/testsuite/ChangeLog
    branches/gcc-4_4-branch/gcc/testsuite/g++.dg/lookup/using16.C

Comment 6 Jason Merrill 2009-11-03 22:09:03 UTC
Fixed fer 4.4.3, 4.5.0.  I'm not comfortable applying the fix to 4.3 as it might have unintended side-effects.