title: Invalid integer constant expression
body: <p>In this code:  </p>
  
  <pre><code>// CompileTimeWarnings.cpp : Defines the entry point for the console application.
  //
  
  #include "stdafx.h"
  #include &lt;type_traits&gt;
  using namespace std;
  #define __STR1__(x) #x
  
  #define __LOC__ __FILE__ "("__STR1__(__LINE__)") : warning : "
  
  // collisions.cpp
  
  template&lt;class T, class T1&gt;
  struct mismatch
  {
      //enum {value = is_signed&lt;T&gt;::value &amp;&amp; is_signed&lt;T1&gt;::value};
      static const bool value; //= is_signed&lt;T&gt;::value &amp;&amp; is_signed&lt;T1&gt;::value;
  };
  
  template&lt;class T, class T1&gt;
  bool mismatch&lt;T,T1&gt;::value = is_signed&lt;T&gt;::value &amp;&amp; is_signed&lt;T1&gt;::value;
  
  template&lt;class T&gt;
  struct Int
  {
  };
  
  template&lt;class T, class T1&gt;
  int operator+(Int&lt;T&gt; t, Int&lt;T1&gt; t1)
  {
  #if int(mismatch&lt;T,T1&gt;::value)
  #pragma message(__LOC__"Need to do 3D collision testing")
  #endif
      return 0;
  }
  
  int _tmain(int argc, _TCHAR* argv[])
  {
  Int&lt;int&gt; a;
  Int&lt;signed&gt; b;
  b + a;
      return 0;
  }
  </code></pre>
  
  <p>I'm getting following err msg:<br>
  C1017: Invalid integer constant expression.<br>
  Why? And how to solve it?</p>
  
  <p><strong>Edited</strong></p>
  
  <pre><code>#include "stdafx.h"
  #include &lt;type_traits&gt;
  #include &lt;iostream&gt;
  
  using namespace std;
  
  template&lt;class T&gt;
  struct Int
  {
  };
  
  template&lt;class T, class T1&gt;
  struct Mismatch
  {
      static const bool value = (!is_signed&lt;T&gt;::value &amp;&amp; is_signed&lt;T1&gt;::value) || 
                                  (is_signed&lt;T&gt;::value &amp;&amp; !is_signed&lt;T1&gt;::value);
  };
  
  
  
  template&lt;bool b&gt; struct Need_to_do_3D_collision_testing
  { 
      static void f()
      { static const char value=256; }
  };
  
  template&lt;&gt; struct Need_to_do_3D_collision_testing&lt;true&gt;
  {
      static void f() { } 
  };
  
  template&lt;class T, class T1&gt; int operator+(Int&lt;T&gt; t, Int&lt;T1&gt; t1) 
  {
  Need_to_do_3D_collision_testing&lt;!Mismatch&lt;T,T1&gt;::value&gt;::f();
  return 0;
  } 
  
  
  
  
  
  
  int _tmain(int argc, _TCHAR* argv[])
  {
      Int&lt;char&gt; a;
      Int&lt;unsigned char&gt; b;
      b + a;
      return 0;
  }
  </code></pre>
  
  <p>I'm getting following warnings:<br>
  Warning 1   warning C4305: 'initializing' : truncation from 'int' to 'const char'<br>
  Warning 2   warning C4309: 'initializing' : truncation of constant value<br>
  but not the warning with struct name. So it doesn't work for me as it should.<br>
  <strong>Edit_2</strong>  Warning level /wall - highest<br>
  Warning 1   warning C4820: '_wfinddata64i32_t' : '4' bytes padding added after data member '_wfinddata64i32_t::attrib'<br>
  Warning 2   warning C4820: '_wfinddata64i32_t' : '4' bytes padding added after data member '_wfinddata64i32_t::name'<br>
  Warning 3   warning C4820: '_wfinddata64_t' : '4' bytes padding added after data member '_wfinddata64_t::attrib'<br>
  Warning 4   warning C4820: '_stat32' : '2' bytes padding added after data member '_stat32::st_gid'<br>
  Warning 5   warning C4820: 'stat' : '2' bytes padding added after data member 'stat::st_gid'<br>
  Warning 6   warning C4820: '_stat32i64' : '2' bytes padding added after data member '_stat32i64::st_gid'<br>
  Warning 7   warning C4820: '_stat32i64' : '4' bytes padding added after data member '_stat32i64::st_rdev'
  Warning 8   warning C4820: '_stat32i64' : '4' bytes padding added after data member '_stat32i64::st_ctime'<br>
  Warning 9   warning C4820: '_stat64i32' : '2' bytes padding added after data member '_stat64i32::st_gid'<br>
  Warning 10  warning C4820: '_stat64' : '2' bytes padding added after data member '_stat64::st_gid'<br>
  Warning 11  warning C4820: '_stat64' : '4' bytes padding added after data member '_stat64::st_rdev'  Warning    12  warning C4986: 'operator new[]': exception specification does not match previous declaration<br>
  Warning 13  warning C4986: 'operator delete[]': exception specification does not match previous declaration<br>
  Warning 14  warning C4820: 'type_info' : '3' bytes padding added after data member 'type_info::_M_d_name'  Warning  15  warning C4305: 'initializing' : truncation from 'int' to 'const char'    Warning    16  warning C4309: 'initializing' : truncation of constant value<br>
  Warning 17  warning C4710: 'std::_Exception_ptr std::_Exception_ptr::_Current_exception(void)' : function not inlined<br>
  Warning 18  warning C4710: 'std::string std::locale::name(void) const' : function not inlined<br>
  Warning 19  warning C4710: 'std::locale std::ios_base::getloc(void) const' : function not inlined<br>
  Warning 20  warning C4710: 'std::string std::numpunct&lt;_Elem>::do_grouping(void) const' : function not inlined<br>
   Warning    21  warning C4710: 'std::basic_string&lt;_Elem,_Traits,_Ax> std::numpunct&lt;_Elem>::do_falsename(void) const' : function not inlined<br>
  Warning 22  warning C4710: 'std::basic_string&lt;_Elem,_Traits,_Ax> std::numpunct&lt;_Elem>::do_truename(void) const' : function not inlined<br>
  Warning 23  warning C4710: 'std::string std::numpunct&lt;_Elem>::do_grouping(void) const' : function not inlined<br>
  Warning 24  warning C4710: 'std::basic_string&lt;_Elem,_Traits,_Ax> std::numpunct&lt;_Elem>::do_falsename(void) const' : function not inlined<br>
  Warning 25  warning C4710: 'std::basic_string&lt;_Elem,_Traits,_Ax> std::numpunct&lt;_Elem>::do_truename(void) const' : function not inlined<br>
  Warning 26  warning C4710: 'std::basic_string&lt;_Elem,_Traits,_Ax> std::numpunct&lt;_Elem>::falsename(void) const' : function not inlined<br>
  Warning 27  warning C4710: 'std::basic_string&lt;_Elem,_Traits,_Ax> std::numpunct&lt;_Elem>::truename(void) const' : function not inlined<br>
  Warning 28  warning C4710: 'std::basic_string&lt;_Elem,_Traits,_Ax> std::numpunct&lt;_Elem>::falsename(void) const' : function not inlined<br>
  Warning 29  warning C4710: 'std::basic_string&lt;_Elem,_Traits,_Ax> std::numpunct&lt;_Elem>::truename(void) const' : function not inlined<br>
  Warning 30  warning C4710: 'std::string std::numpunct&lt;_Elem>::grouping(void) const' : function not inlined<br>
  Warning 31  warning C4710: 'std::string std::numpunct&lt;_Elem>::grouping(void) const' : function not inlined      </p>