BOOST_STATIC_ASSERT has different behavior on different platforms
Hi, BOOST_STATIC_ASSERT has different behavior on different platforms Boost 1.34 -------- File foo01. cpp -------- #include <boost/static_assert.hpp> struct Foo { int m_value; Foo(); }; Foo::Foo() { BOOST_STATIC_ASSERT(sizeof(this->m_value) == 4); } int main() { Foo f; return 0; } --------------------------------- No compilation errors on UNIX compilers HP: aCC: HP C/aC++ B3910B A.06.25.01 [May 16 2010] Sun: C++ 5.9 SunOS_sparc Patch 124863-01 2007/07/25 AIX: IBM XL C/C++ Enterprise Edition V8.0 for AIX; Version: 08.00.0000.0014 Linux: Intel(R) C++ Intel(R) 64 Compiler, Version 11.0 There are compilation errors on Windows compiler Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 14.00.50727.762 for 80x86 foo01.cpp foo01.cpp(11) : error C2355: 'this' : can only be referenced inside non-static member functions foo01.cpp(11) : error C2227: left of '->m_value' must point to class/struct/union/generic type foo01.cpp(11) : error C2027: use of undefined type 'boost::STATIC_ASSERTION_FAILURE' C:\ADJUST\3rdParties\boost_1_34_0\boost/static_assert.hpp(34) : see declaration of 'boost::STATIC_ASSERTION_FAILURE' Regards, Alex Vinokur This message and the information contained herein is proprietary and confidential and subject to the Amdocs policy statement, you may review at http://www.amdocs.com/email_disclaimer.asp
On 2010-07-27-Tue 06:32, Alexander Vinokur wrote:
BOOST_STATIC_ASSERT has different behavior on different platforms ... Foo::Foo() { BOOST_STATIC_ASSERT(sizeof(this->m_value) == 4); } ... There are compilation errors on Windows compiler
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 14.00.50727.762 for 80x86
foo01.cpp(11) : error C2355: 'this' : can only be referenced inside non-static member functions
I think this is caused by a compiler bug, which was reported by Eric Niebler, two years ago: Microsoft Visual Studio bug report 331418, "Erroneous error C2355: 'this' : can only be referenced inside non-static member functions", http://connect.microsoft.com/VisualStudio/feedback/details/331418/erroneous-... Workaround: Foo::Foo() { Foo & self = *this; BOOST_STATIC_ASSERT(sizeof(self.m_value) == 4); } HTH, Niels -- Niels Dekker http://www.xs4all.nl/~nd/dekkerware Scientific programmer at LKEB, Leiden University Medical Center
participants (2)
-
Alexander Vinokur
-
Niels Dekker - address until 2010-10-10