5

We're trying to use http://cpp-netlib.org and failing to compile it, because in one of its headers it has:

namespace network { namespace utils { struct thread_pool; } } 

and in another:

namespace network { namespace utils { typedef ::network::concurrency::thread_pool thread_pool; } } 

From what I understand from Forward declaration of a typedef in C++ and http://www.cplusplus.com/forum/beginner/75561 in C++ this is basically illegal - you just can't forward declare: "struct A;" and then try to "typedef X A;".

So, my question is, what on earth might they be compiling this with that allows it? Is this some new feature of C++11, since they are claiming to use the latest-greatest-of-C++11?

4
  • You are right, this looks broken. Commented Sep 27, 2013 at 14:59
  • This might be a better remark for them: cpp-netlib.org/#support Commented Sep 27, 2013 at 15:01
  • it is broken even in pre-c++11 Commented Sep 27, 2013 at 15:10
  • @stefaanv Well, since this code is actually trunk version from the cpp-netlib GitHub page, I guess it could be just work in progress Commented Sep 27, 2013 at 16:04

1 Answer 1

4

this is basically illegal

Yes, it is.

So, my question is, what on earth might they be compiling this with that allows it?

Perhaps, they never include both headers in the same translation unit. In that case most compilers won't be able to diagnose the error (which isn't required to be diagnosed); and there's a chance that you'll still end up with a working program. You're definitely in the world of undefined behaviour, though.

Is this some new feature of C++11?

No. You can do various interesting things with using to create aliases; but you still can't declare a type as both a class and a typedef.

Sign up to request clarification or add additional context in comments.

1 Comment

This is very unlikely to really work. The translation unit that sees the type will mangle names that use that type as ::network::utils::thread_pool, but the translation unit that sees the typedef will mangle with ::someother::namespace_::andtype, I doubt the linker would not barf at that

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.