If there is an ambiguity with the namespace resolution, the 3.4/4.0 compiler
error message is very unclear while it was much better in 3.3 (and even 2.95):

% cat ns.cpp
namespace NsOut { namespace NsIn { struct Foo { }; } }

namespace NsIn { struct Foo { }; }

using namespace NsOut;

void foo(NsIn::Foo *);
% g++-3.3 -fsyntax-only -c ns.cpp
ns.cpp:7: error: use of `NsIn' is ambiguous
ns.cpp:3: error:   first declared as `NsIn' here
ns.cpp:1: error:   also declared as `NsOut::NsIn' here
ns.cpp:7: error: syntax error before `::' token

[ok so far]

% g++-3.4 -fsyntax-only -c ns.cpp
ns.cpp:7: error: `NsIn' has not been declared
ns.cpp:7: error: variable or field `foo' declared void
ns.cpp:7: error: `Foo' was not declared in this scope
ns.cpp:7: error: expected primary-expression before ')' token

[why "has not been declared"?]

% g++-4.0 -fsyntax-only -c ns.cpp
ns.cpp:7: error: 'NsIn' has not been declared
ns.cpp:7: error: variable or field 'foo' declared void
ns.cpp:7: error: 'Foo' was not declared in this scope
ns.cpp:7: error: expected primary-expression before ')' token

[same again]

The same problem occurs with a namespace alias, i.e. if you replace the line 3
of ns.cpp with "namespace NsIn = NsOut::NsIn;". While it's quite clear in this
example, it took a lot of time to find what the problem was in the real
program.


Tested with

gcc version 3.3.6 (Debian 1:3.3.6-10)
gcc version 3.4.5 (Debian 3.4.5-1)
gcc version 4.0.3 20051201 (prerelease) (Debian 4.0.2-5)


-- 
           Summary: confusing error message for ambiguous namespaces
                    declarations
           Product: gcc
           Version: 4.0.3
            Status: UNCONFIRMED
          Severity: minor
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: vz-gcc at zeitlins dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26329

Reply via email to