Boost logo

Boost :

From: Okko Willeboordse (trash_at_[hidden])
Date: 2008-05-19 06:44:14


Hi all,

Boost 1.35 triggers msvc 7.1 & 8.0 to export a local type named
CRITICAL_SECTION declared in detail/lwm_win32_cs.hpp into the
global namespace.
This causes 'ambiguous identifier' compiler errors upon attempts to
use (the global Windows type) CRITICAL_SECTION.

Please refer to;
[boost.pool] Workaround for a msvc 7.1 & 8.0 bug surfaced in the boost
1.35 release
4/8/2008 3:52 PM
and;
Changeset link: http://svn.boost.org/trac/boost/changeset/44480

Above fixes problems caused by usage of CRITICAL_SECTION in Boost itself
namely in pool/detail/mutex.hpp.
However usage of CRITICAL_SECTION outside Boost still gives problems.

For example;

#include <boost/archive/text_iarchive.hpp>
typedef int CRITICAL_SECTION;
CRITICAL_SECTION cs;

or (real live case);

#include <boost/archive/text_iarchive.hpp>
#include <atlcore.h>

Results in 'ambiguous identifier' compiler errors.

I attached a patch of detail/lwm_win32_cs.hpp that fixes this.

Note that;
1. a real solution to the problem would be to alter Boost such
that the VS compiler bug is no longer triggered.
2. more local types, other then CRITICAL_SECTION, may have the same
problem.

Kind regards,

Okko Willeboordse

Index: lwm_win32_cs.hpp
===================================================================
--- lwm_win32_cs.hpp (revision 45417)
+++ lwm_win32_cs.hpp (working copy)
@@ -17,8 +17,15 @@
 // http://www.boost.org/LICENSE_1_0.txt)
 //
 
+// 'CRITICAL_SECTION' type has been renamed here due to a MSVC 7.0, 7.1 & 8.0
+// bug causing this local type to be exported into the global namespace, later
+// causing 'ambiguous identifier' compiler errors if anyone attempts to use the
+// global Windows CRITICAL_SECTION type without using its fully qualified name
+// '::CRITICAL_SECTION'.
+
 #ifdef BOOST_USE_WINDOWS_H
 # include <windows.h>
+typedef CRITICAL_SECTION CRITICAL_SECTION_RENAMED_TO_AVOID_VS_BUG;
 #endif
 
 namespace boost
@@ -29,7 +36,7 @@
 
 #ifndef BOOST_USE_WINDOWS_H
 
-struct CRITICAL_SECTION
+struct CRITICAL_SECTION_RENAMED_TO_AVOID_VS_BUG
 {
     struct critical_section_debug * DebugInfo;
     long LockCount;
@@ -43,10 +50,10 @@
 #endif
 };
 
-extern "C" __declspec(dllimport) void __stdcall InitializeCriticalSection(CRITICAL_SECTION *);
-extern "C" __declspec(dllimport) void __stdcall EnterCriticalSection(CRITICAL_SECTION *);
-extern "C" __declspec(dllimport) void __stdcall LeaveCriticalSection(CRITICAL_SECTION *);
-extern "C" __declspec(dllimport) void __stdcall DeleteCriticalSection(CRITICAL_SECTION *);
+extern "C" __declspec(dllimport) void __stdcall InitializeCriticalSection(CRITICAL_SECTION_RENAMED_TO_AVOID_VS_BUG *);
+extern "C" __declspec(dllimport) void __stdcall EnterCriticalSection(CRITICAL_SECTION_RENAMED_TO_AVOID_VS_BUG *);
+extern "C" __declspec(dllimport) void __stdcall LeaveCriticalSection(CRITICAL_SECTION_RENAMED_TO_AVOID_VS_BUG *);
+extern "C" __declspec(dllimport) void __stdcall DeleteCriticalSection(CRITICAL_SECTION_RENAMED_TO_AVOID_VS_BUG *);
 
 #endif // #ifndef BOOST_USE_WINDOWS_H
 
@@ -54,7 +61,7 @@
 {
 private:
 
- CRITICAL_SECTION cs_;
+ CRITICAL_SECTION_RENAMED_TO_AVOID_VS_BUG cs_;
 
     lightweight_mutex(lightweight_mutex const &);
     lightweight_mutex & operator=(lightweight_mutex const &);


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk