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

[C++] "using namespace" in header file causes ambiguous reference #266

Closed
lawben opened this issue Apr 29, 2020 · 3 comments
Closed

[C++] "using namespace" in header file causes ambiguous reference #266

lawben opened this issue Apr 29, 2020 · 3 comments

Comments

@lawben
Copy link
Contributor

lawben commented Apr 29, 2020

There is a using namespace FASTER::core; statement in file_common.h, which causes an ambiguous references in unrelated files.

I am including FASTER as a CMake submodule (via add_subdirectory) together with other third party projects. However, both FASTER and another implement their own Thread class. As there is a using namspace FASTER::core; statement in a FASTER header, somewhere down the (compile-) line, GCC sees two Thread classes.

I get the following error when compiling the other project's files.

error: reference to ‘Thread’ is ambiguous  <-- This is in the tls_thread.h file below
   59 | std::unordered_map<std::thread::id, Thread::TlsList *> Thread::registry_;

...

third_party/faster/cc/src/device/../core/thread.h:19:7: note: candidates are: ‘class FASTER::core::Thread’
   19 | class Thread {

... 

epoch_reclaimer-src/tls_thread.h:25:7: note: ‘class Thread’
   25 | class Thread : public std::thread {

By renaming FASTER's version to FasterThread, the problem is resolved. However, that is probably not the right solution. I suggest removing the using namespace statement from the header file, as recommended by Sutter, and namespace all entries within the header file correctly.

  1. Don’t write namespace usings in a header file or before an #include

I'd be willing to create a PR for this, if you guys think this should be done.

@badrishc
Copy link
Contributor

badrishc commented May 1, 2020

I see. Sure, pease go ahead with a PR for this. Thx.

@badrishc
Copy link
Contributor

Just wanted to check on the status of this, thanks!

@lawben
Copy link
Contributor Author

lawben commented May 25, 2020

Sorry, I kinda forgot about this as I've been using a local workaround. I'll prepare the PR in the next few days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants