Bug 67074 - Name lookup ambiguity between namespace and its alias
Summary: Name lookup ambiguity between namespace and its alias
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: unknown
: P3 normal
Target Milestone: ---
Assignee: Nathan Sidwell
URL:
Keywords: rejects-valid
Depends on:
Blocks: c++-lookup, c++-name-lookup
  Show dependency treegraph
 
Reported: 2015-07-30 23:40 UTC by Anders Granlund
Modified: 2017-06-21 13:16 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2015-07-31 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Anders Granlund 2015-07-30 23:40:05 UTC
Test case:

  namespace P{ namespace X { static int i = 1; } }
  namespace Q { namespace X = P::X; }
  using namespace P;
  using namespace Q;
  int main() { X::i; }

Command line:

  g++ prog.cc -std=c++14 -pedantic-errors

This results in name-lookup ambiguity errors when looking up X in main. This is not a name-lookup ambiguity since the two names founds denotes the same entity.

I tried this with gcc HEAD 6.0.0 20150730 here:

  http://melpon.org/wandbox/permlink/6IBZhBmgDMkq6Eho
Comment 1 Anders Granlund 2015-07-31 00:12:51 UTC
I have reported the same bug in clang also:

https://llvm.org/bugs/show_bug.cgi?id=24324

Richard Smith confirmed it and added this additional test case:

And likewise:

  namespace N {}
  namespace N = N;

If a namespace alias really just binds a name to an existing namespace, the above should be valid, because all declarations of name N in the TU refer to the same entity.
Comment 2 Nathan Sidwell 2017-06-20 12:53:44 UTC
Author: nathan
Date: Tue Jun 20 12:53:11 2017
New Revision: 249408

URL: https://gcc.gnu.org/viewcvs?rev=249408&root=gcc&view=rev
Log:
	PR c++/67074 - namespace aliases
	* decl.c (duplicate_decls): Don't error here on mismatched
	namespace alias.
	* name-lookup.c (name_lookup::add_value): Matching namespaces are
	not ambiguous.
	(diagnose_name_conflict): Namespaces are never redeclarations.
	(update_binding): An alias can match a real namespace.

	PR c++/67074
	* g++.dg/lookup/pr67074.C: New.
	* g++.dg/parse/namespace-alias-1.C: Adjust.

Added:
    trunk/gcc/testsuite/g++.dg/lookup/pr67074.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/decl.c
    trunk/gcc/cp/name-lookup.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/g++.dg/parse/namespace-alias-1.C
Comment 3 Nathan Sidwell 2017-06-21 13:16:55 UTC
Fixed r249408.