MSVC++ 2010 and BOOST_STATIC_ASSERT

Hi all! I've noticed that MSVC++ 2010 has implemented static_assert (compile time checks); and probably as a result, the code that used to build fine in MSVC++ 2008 is now generating the following error. code: BOOST_STATIC_ASSERT(N==1) *error C2338: (N==1)* ** Appreciate if anyone who has resolved this error can share their experiences.. Thanks, --Thomas. **

AMDG On 11/01/2011 02:52 PM, Sunil Thomas wrote:
I've noticed that MSVC++ 2010 has implemented static_assert (compile time checks); and probably as a result, the code that used to build fine in MSVC++ 2008 is now generating the following error.
code:
BOOST_STATIC_ASSERT(N==1) *error C2338: (N==1)* **
Appreciate if anyone who has resolved this error can share their experiences..
This code is obviously not complete. The error indicates that N is not 1. You haven't provided any context. In Christ, Steven Watanabe

The condensed code that generates the error in the last e-mail is as follows: template<typename T = some_type, std::size_t N=3> my_class { public: my_class(const T& i0) { BOOST_STATIC_ASSERT(N==1); m_data[0]=i0; } private: T m_data[N]; } I realize that N defaults to 3 and all, but without making any sweeping changes, is there a way to force MSVC++ 2010 to just compile, considering this was compiling fine with MSVC++ 2008? Thanks, --Thomas. On Tue, Nov 1, 2011 at 4:20 PM, Steven Watanabe <watanabesj@gmail.com>wrote:
AMDG
On 11/01/2011 02:52 PM, Sunil Thomas wrote:
I've noticed that MSVC++ 2010 has implemented static_assert (compile time checks); and probably as a result, the code that used to build fine in MSVC++ 2008 is now generating the following error.
code:
BOOST_STATIC_ASSERT(N==1) *error C2338: (N==1)* **
Appreciate if anyone who has resolved this error can share their experiences..
This code is obviously not complete. The error indicates that N is not 1. You haven't provided any context.
In Christ, Steven Watanabe _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

Hi Thomas, On Tue, Nov 1, 2011 at 11:24 PM, Sunil Thomas <sgthomas27@gmail.com> wrote:
The condensed code that generates the error in the last e-mail is as follows: <snip code> I realize that N defaults to 3 and all, but without making any sweeping changes, is there a way to force MSVC++ 2010 to just compile, considering this was compiling fine with MSVC++ 2008?
Your code (with fairly simple modifications) worked fine for me in VC10 and g++4.X: #include <boost/static_assert.hpp> //Added typedef and 'class' keyword below. typedef int some_type; template<typename T = some_type, std::size_t N=3> class my_class { public: my_class(const T& i0) { BOOST_STATIC_ASSERT(N==1); m_data[0]=i0; } private: T m_data[N]; }; I suspect the error you're seeing might depend on how you instantiate my_class -- as Steven said, more context is necessary. If you can post a compilable example that exhibits the problem our advice will likely be more helpful. Nate

AMDG On 11/01/2011 10:24 PM, Sunil Thomas wrote:
The condensed code that generates the error in the last e-mail is as follows:
template<typename T = some_type, std::size_t N=3> my_class { public: my_class(const T& i0) { BOOST_STATIC_ASSERT(N==1); m_data[0]=i0; } private: T m_data[N]; }
I realize that N defaults to 3 and all, but without making any sweeping changes, is there a way to force MSVC++ 2010 to just compile, considering this was compiling fine with MSVC++ 2008?
The following code compiles fine with MSVC 2010. #include <cstddef> #include <boost/static_assert.hpp> template<class T = int, std::size_t N = 3> class C { public: C() {} C(const T& i0) { BOOST_STATIC_ASSERT(N == 1); m_data[0] = i0; } private: T m_data[N]; }; int main() { C<> c; } Can you provide a minimal *complete* test case that fails? In Christ, Steven Watanabe

Thanks Steve & Nate, What I am building is a library.. not a main application. My main application is in unit test libraries. But building the library itself is generating the error. The class and its implementation is defined entirely in the header, say, cinc.h and I forgot to include a typedef after the class definition: File cinc.h: ---------------------------------------- #include <boost/static_assert.hpp> template<class T = int, std::size_t N = 3> class C { public: C() {} C(const T& i0) { BOOST_STATIC_ASSERT(N == 1); m_data[0] = i0; } C(const T& i0, const T& i1) { BOOST_STATIC_ASSERT(N==2); m_data[0] = i0; m_data[1] = i1; } ... ... private: T m_data[N]; }; typedef C<> my_C; Then in a separate class source file, say, cimpl.cpp which includes the header above, the compilation fails with the C2338 error above. The implementation header looks as follows: cimpl.h ---------- #include <path/to/cinc.h> class C_IMPL { private: my_C m_c; public: C_IMPL(); C_IMPL(my_C& mc); func1(my_C& mc1, ...); func2(my_C& mc2, ...); ... ... }; cimpl.cpp just defines the functions and assumes that all my_C objects are infact based on N=3 definition above.. cimpl.cpp: (snippets) -------------- #include <path/to/cimpl.h> C_IMPL::C_IMPL(): m_c(0,0,0) { } C_IMPL::C_IMPL(my_C& mc): m_c(mc) { } ... ... Yet I get the error as pasted from the MS VC++ 2010, build output window: *ClCompile: some_file1.cpp some_file2.cpp C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xutility(2227): warning C4996: 'std::_Copy_impl': Function call with parameters that may be unsafe - this call relies on the caller to check that the passed values are correct. To disable this warning, use -D_SCL_SECURE_NO_WARNINGS. See documentation on how to use Visual C++ 'Checked Iterators' C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xutility(2212) : see declaration of 'std::_Copy_impl' <path/to>/some_include.hpp(88) : see reference to function template instantiation '_OutIt std::copy<const unsigned __int64*,unsigned __int64*>(_InIt,_InIt,_OutIt)' being compiled with [ _OutIt=unsigned __int64 *, _InIt=const unsigned __int64 * ] <path/to>/some_include.hpp(88) : while compiling class template member function 'blah<>::blah(const blah<> &)' <path/to>/some_include.hpp(71) : see reference to class template instantiation 'blah<>' being compiled cimpl.cpp <path/to>/cimpl.cpp(442): warning C4100: 'npos' : unreferenced formal parameter C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xutility(2227): warning C4996: 'std::_Copy_impl': Function call with parameters that may be unsafe - this call relies on the caller to check that the passed values are correct. To disable this warning, use -D_SCL_SECURE_NO_WARNINGS. See documentation on how to use Visual C++ 'Checked Iterators' C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xutility(2212) : see declaration of 'std::_Copy_impl' <path/to>/cinc.hpp(108) : see reference to function template instantiation '_OutIt std::copy<const unsigned __int64*,unsigned __int64*>(_InIt,_InIt,_OutIt)' being compiled with [ _OutIt=unsigned __int64 *, _InIt=const unsigned __int64 * ] <path/to>/cinc.hpp(108) : while compiling class template member function C<>::C(const C<> &)' <path/to>/cinc.hpp(45) : see reference to class template instantiation 'C<>' being compiled C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xutility(2801): warning C4996: 'std::_Fill_n': Function call with parameters that may be unsafe - this call relies on the caller to check that the passed values are correct. To disable this warning, use -D_SCL_SECURE_NO_WARNINGS. See documentation on how to use Visual C++ 'Checked Iterators' C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xutility(2787) : see declaration of 'std::_Fill_n' <path/to>/cinc.hpp(255) : see reference to function template instantiation 'void std::fill_n<unsigned __int64*,C<>::size_type,unsigned __int64>(_OutIt,_Diff,const _Ty &)' being compiled with [ _OutIt=unsigned __int64 *, _Diff=C<>::size_type, _Ty=unsigned __int64 ] <path/to>/cinc.hpp(255) : while compiling class template member function 'void C<>::assign(const unsigned __int64 &)' <path/to>/cinc.hpp(83): error C2338: N==1* I don't see myself doing anything different than what Steve did in his main.. and again, why was this building with MSVC++ 2008 (granted, that N defaults to 3 and all)? Anyways, hope this was more helpful. Thanks again, --Thomas. On Wed, Nov 2, 2011 at 9:51 AM, Steven Watanabe <watanabesj@gmail.com>wrote:
AMDG
On 11/01/2011 10:24 PM, Sunil Thomas wrote:
The condensed code that generates the error in the last e-mail is as follows:
template<typename T = some_type, std::size_t N=3> my_class { public: my_class(const T& i0) { BOOST_STATIC_ASSERT(N==1); m_data[0]=i0; } private: T m_data[N]; }
I realize that N defaults to 3 and all, but without making any sweeping changes, is there a way to force MSVC++ 2010 to just compile, considering this was compiling fine with MSVC++ 2008?
The following code compiles fine with MSVC 2010.
#include <cstddef> #include <boost/static_assert.hpp>
template<class T = int, std::size_t N = 3> class C { public: C() {} C(const T& i0) { BOOST_STATIC_ASSERT(N == 1); m_data[0] = i0; } private: T m_data[N]; };
int main() { C<> c; }
Can you provide a minimal *complete* test case that fails?
In Christ, Steven Watanabe _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

AMDG On 11/02/2011 04:32 PM, Sunil Thomas wrote:
Thanks Steve & Nate,
What I am building is a library.. not a main application. My main application is in unit test libraries. But building the library itself is generating the error. The class and its implementation is defined entirely in the header, say, cinc.h and I forgot to include a typedef after the class definition:
<snip> <path/to>/cinc.hpp(255) : while compiling class template member function 'void C<>::assign(const unsigned __int64 &)' <path/to>/cinc.hpp(83): error C2338: N==1*
You've snipped something important. I don't see a definition of assign in your code. Figure out how and why assign is called with 1 argument and that should explain why your code doesn't compile.
I don't see myself doing anything different than what Steve did in his main.. and again, why was this building with MSVC++ 2008 (granted, that N defaults to 3 and all)? Anyways, hope this was more helpful.
In Christ, Steven Watanabe

Thanks Steven, Didn't mean to snip that out.. I overlooked it as just a warning. So here is the updated code. #include <boost/static_assert.hpp> template<class T = int, std::size_t N = 3> class C { public: C() {assign(0)} C(const T& i0) { BOOST_STATIC_ASSERT(N == 1); m_data[0] = i0; } C(const T& i0, const T& i1) { BOOST_STATIC_ASSERT(N==2); m_data[0] = i0; m_data[1] = i1; } const_iterator begin() const {return m_data;} const_iterator end() const {return m_data + N;} void assign(const T& value) {std::fill_n(begin(), size(), value);} static size_t size() {return N;} ... ... private: T m_data[N]; }; typedef C<> my_C; Apologies... but I am unable to see what the MS VC++ 2010 compiler doesn't like about this.. Thanks for pointing this out, --Sunil. On Wed, Nov 2, 2011 at 5:36 PM, Steven Watanabe <watanabesj@gmail.com>wrote:
AMDG
On 11/02/2011 04:32 PM, Sunil Thomas wrote:
Thanks Steve & Nate,
What I am building is a library.. not a main application. My main application is in unit test libraries. But building the library itself is generating the error. The class and its implementation is defined entirely in the header, say, cinc.h and I forgot to include a typedef after the class definition:
<snip> <path/to>/cinc.hpp(255) : while compiling class template member function 'void C<>::assign(const unsigned __int64 &)' <path/to>/cinc.hpp(83): error C2338: N==1*
You've snipped something important. I don't see a definition of assign in your code. Figure out how and why assign is called with 1 argument and that should explain why your code doesn't compile.
I don't see myself doing anything different than what Steve did in
his
main.. and again, why was this building with MSVC++ 2008 (granted, that N defaults to 3 and all)? Anyways, hope this was more helpful.
In Christ, Steven Watanabe _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (3)
-
Nathan Crookston
-
Steven Watanabe
-
Sunil Thomas