Boost logo

Boost Users :

Subject: Re: [Boost-users] MSVC++ 2010 and BOOST_STATIC_ASSERT
From: Sunil Thomas (sgthomas27_at_[hidden])
Date: 2011-11-02 19:32:50


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_at_[hidden]>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_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net