Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clang things lookup is ambiguous, gcc and edg don't #10765

Open
llvmbot opened this issue Jul 18, 2011 · 5 comments
Open

clang things lookup is ambiguous, gcc and edg don't #10765

llvmbot opened this issue Jul 18, 2011 · 5 comments
Labels
bugzilla Issues migrated from bugzilla c++ clang:frontend Language frontend issues, e.g. anything involving "Sema"

Comments

@llvmbot
Copy link
Collaborator

llvmbot commented Jul 18, 2011

Bugzilla Link 10393
Version unspecified
OS Linux
Reporter LLVM Bugzilla Contributor
CC @DougGregor,@efriedma-quic

Extended Description

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.

@llvmbot
Copy link
Collaborator Author

llvmbot commented Jul 18, 2011

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.

@llvmbot
Copy link
Collaborator Author

llvmbot commented Jul 18, 2011

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;
}

@efriedma-quic
Copy link
Collaborator

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.

@llvmbot
Copy link
Collaborator Author

llvmbot commented May 14, 2013

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);
    }

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 3, 2021
@Endilll Endilll added the clang:frontend Language frontend issues, e.g. anything involving "Sema" label Nov 3, 2023
@llvmbot
Copy link
Collaborator Author

llvmbot commented Nov 3, 2023

@llvm/issue-subscribers-clang-frontend

Author: None (llvmbot)

| | | | --- | --- | | Bugzilla Link | [10393](https://llvm.org/bz10393) | | Version | unspecified | | OS | Linux | | Reporter | LLVM Bugzilla Contributor | | CC | @DougGregor,@efriedma-quic |

Extended Description

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla c++ clang:frontend Language frontend issues, e.g. anything involving "Sema"
Projects
None yet
Development

No branches or pull requests

3 participants