
"Bertrand Augereau" <bertrand@eugensystems.com> wrote
The following snippet doesn't compile on MSVC8.0 if stdafx.h (the precompiled header) includes "boost\typeof\typeof.hpp", and works if not... (The project is otherwise a default-settings console app)
#include "stdafx.h" #include "boost\typeof\typeof.hpp"
#include BOOST_TYPEOF_INCREMENT_REGISTRATION_GROUP()
class Class {};
BOOST_TYPEOF_REGISTER_TYPE(Class)
int _tmain(int argc, _TCHAR* argv[]) { return 0; }
and it dumps these (quite meaningless) errors: error C2143: syntax error : missing ';' before '<' error C2059: syntax error : '<' error C2065: 'V' : undeclared identifier error C2143: syntax error : missing ';' before '{' error C2447: '{' : missing function header (old-style formal list?) error C2143: syntax error : missing ';' before '<' error C2059: syntax error : '<' error C2143: syntax error : missing ';' before '{' error C2447: '{' : missing function header (old-style formal list?)
This is the same problem that was worked around (by re-defining unnamed namespace) some time ago. The main template is defined inside unnamed namespace, and this definition is put into PCH. The template is specialized outside PCH. Since this is done in another TU, the unnamed namespace is different, and the system can't match the template and the specialization. The workaround works for VC71 and, I am pretty sure it worked for VC80 beta. Unfortunately it doesn't seem to work for VC80 express :( I believe this is a bug in the compiler, since the use of PCH should be transparent. The fact that PCH is created when another TU is compiled is an implementation detail, and should not prevent legal C++ code from being compiled (anybody knows if it's possible to report bugs to Microsoft?). Meanwhile, the only solution that I can see, is to get rid of the unnamed namespace. This could increase number of contexts where ODR violation happens. The compilers may or may not care. It's possible to make it configurable by indroducing some define, like BOOST_TYPEOF_SUPRESS_UNNAMED_NAMESPACE or similar. OTOH, getting rid of unnamed namespace could make it possible for the users to avoid ODR violations altogether (if they want to), by always registering types in the same order. This, of course, would be done at the expence of introducing a dependency bottleneck :( Thoughts? Regards, Arkadiy