LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 10393 - clang things lookup is ambiguous, gcc and edg don't
Summary: clang things lookup is ambiguous, gcc and edg don't
Status: NEW
Alias: None
Product: clang
Classification: Unclassified
Component: C++ (show other bugs)
Version: unspecified
Hardware: PC Linux
: P normal
Assignee: Unassigned Clang Bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-07-18 12:57 PDT by Rafael Ávila de Espíndola
Modified: 2013-05-14 16:49 PDT (History)
4 users (show)

See Also:
Fixed By Commit(s):


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Rafael Ávila de Espíndola 2011-07-18 12:57:10 PDT
gcc and edg accept:

namespace mozilla {
  struct Proxy;
}
using mozilla::Proxy;
struct Proxy  {
};
Proxy mProxy;


clang rejects:

 error: reference to 'Proxy' is ambiguous

That code looks really strange, but both gcc and edg accept it.
Comment 1 Rafael Ávila de Espíndola 2011-07-18 13:31:33 PDT
I tested a variation:

namespace mozilla {
  struct Proxy;
}
struct Proxy  {
};
using mozilla::Proxy;
Proxy mProxy;

and both gcc and edg refuse to accept mProxy complaining about a definition with incomplete type.
Comment 2 Rafael Ávila de Espíndola 2011-07-18 13:56:18 PDT
one "last" test both gcc and edg accept. It shows that they are merging the declaration and definition:

namespace mozilla {
  struct Proxy;
}
using mozilla::Proxy;
struct Proxy  {
  int a;
};
mozilla::Proxy mProxy;
int f() {
  return mProxy.a;
}
Comment 3 Eli Friedman 2011-07-18 16:08:00 PDT
The relevant bit of code (in SemaDecl.cpp):

    if (TagDecl *PrevTagDecl = dyn_cast<TagDecl>(PrevDecl)) {
      // If this is a use of a previous tag, or if the tag is already declared
      // in the same scope (so that the definition/declaration completes or
      // rementions the tag), reuse the decl.
      if (TUK == TUK_Reference || TUK == TUK_Friend ||
          isDeclInScope(PrevDecl, SearchDC, S, isExplicitSpecialization)) {

This code makes us not treat the second declaration of Proxy as a redeclaration even though lookup finds the previous declaration.  Not sure what the right predicate is.
Comment 4 Ali 2013-05-14 16:49:13 PDT
another testcase:

/* g++ accepts this but clang dignoses:
   error3.cpp:18:5: 
   error: call to 'f' is ambiguous
*/

namespace A {
	extern "C" int f(int i = 5) { return i + 2; }
}
namespace B {
	extern "C" int f(int i = 5);
}
using A::f;
using B::f;
int main(void) {
/* extern "C" should conceptually nullify overloading 
 * so why does clang consider this function ambiguous?
 */
    f(3);
}