2

We got hit by a bug that would have been found if C4311 had been active:

Compiler Warning (level 1) C4311 [VS.100]

'variable' : pointer truncation from 'type' to 'type'

This warning detects 64-bit portability issues. For example, if code is compiled on a 64-bit platform, the value of a pointer (64 bits) will be truncated if it is assigned to an int (32 bits).

This warning is only issued when /Wp64 is used. [so true] See /Wp64 for more information.

Unfortunately it seems (see below for background) that to get C4311 I must provide /Wp64to my x64 build -- which results in warning D9035: option 'Wp64' has been deprecated (...) for every project in my solution (extremely annoying).

So is there a way to either:

  • Enable C4311 without /Wp64 on VS2010?
  • or silence D9035?

Background

The MSDN docs for /Wp64 seem to be totally off for VS2010 in that C4311 is only ever active if you specify /Wp64 in the x64(!!) build.

/Wp64 (Detect 64-Bit Portability Issues) [VS.100]

By default, the /Wp64 compiler option is off in the Visual C++ 32-bit compiler and on in the Visual C++ 64-bit compiler. [seem to be wrong]

... Instead of using this option and keyword to detect 64-bit portability issues, use a Visual C++ compiler that targets a 64-bit platform. ... [nopes, doesn't work for me]

... you can just disable /Wp64 in your 32-bit compilations because the 64-bit compiler will detect all issues. ... [I'm fine with disabling for Win32, but the x64 compiler just won't catch any C42311 without me telling him /Wp64]

Another user confirms this @Why is /Wp64 deprecated?:

/Wp64 on 64-bit builds is extremely useful. The documentation (http://msdn.microsoft.com/en-us/library/vstudio/yt4xw8fh.aspx) claims that it is on by default in 64-bit builds, but this is not true. Compiler warnings C4311 and C4312 are only emitted if /Wp64 is explicitly set. Those two warnings indicate when a 32-bit value is put into a pointer, or vice-versa.


Note on VS2015:

  • There is no /Wp64 option anymore, it's been removed, not only deprecated.
  • The behavior is finally as expected - C4311 (e.g.) shown in 64bit build / not shown in 32bit build.
Community
  • 1
  • 1
Martin Ba
  • 37,187
  • 33
  • 183
  • 337
  • MSDN post: https://social.msdn.microsoft.com/Forums/en-US/b037e961-9b03-4ebe-adf1-c0d37cf48d4f/enabling-c4311-on-vs2010-x64-builds-without-use-of-wp64 – Martin Ba May 09 '16 at 21:06
  • Not alone: https://social.msdn.microsoft.com/Forums/en-US/f6ca2de2-be1e-48ba-b348-7b2261dc8692/x64-compiler-not-showing-wp64-warnings – Martin Ba May 09 '16 at 21:08

0 Answers0