开发者

Forcing VS2008 to issue a GCC warning similar to "warning: comparison between signed and unsigned integer expressions"

开发者 https://www.devze.com 2023-01-29 14:22 出处:网络
Along the same lines as to what was described in conversion to ‘size_t’ from ‘int’ may change the sign of the result - GCC , C, I would instead like to insure that the warning I receive under GCC

Along the same lines as to what was described in conversion to ‘size_t’ from ‘int’ may change the sign of the result - GCC , C, I would instead like to insure that the warning I receive under GCC 4.2.1 is also flagged under VS2008 SP1 under both 32-bit and 64-bit compilation, versus disabling warnings under GCC to suit VS2008.

For example, under GCC 4.2.1 under 64-bit conditions, we see the following as a warning under -Wall conditions:

#include <string.h>
bool foo()
{
    size_t len = 0;
    const char * someBuffer = "flubber";
    len = strlen(someBuffer);
    bool retval = false;
    for (int j = 0; j < len; j++) // <-- warning
    {
        if (someBuffer[j] != '0')
        {
            retval = true;
            break;
        }
    }
    return retval;
}

The GCC warning is:

warning: comparison between signed and unsigned integer expressions

But it is not flagged by the VS2008 SP1 64-bit compiler, no matter what types of pragmas I try and no matter what I enable using /W3 or /W4, or /w3some_warning_number or /w4some_warning_number, etc.

Now, I don't want to dumb down GCC's warning levels or disable the warning, since they had the warning i开发者_运维问答n there for very good reasons. So I would like the VS builds to fail in similar ways when /WX is enabled. Is this something I have to live with, or is there some warning that would do the trick on VS2008?

EDIT: The warning shows up for 32-bit builds but not using 64-bit builds, using the same set of compiler options, shown below:

/O2
/Ob2
/D "WIN32"
/D "_WINDOWS"
/D "NDEBUG"
/D "_CRT_SECURE_NO_WARNINGS"
/D "__WIN32__"
/D "_SCL_SECURE_NO_WARNINGS"
/D "_BIND_TO_CURRENT_MFC_VERSION"
/D "_BIND_TO_CURRENT_CRT_VERSION"
/D "WINVER=0x0502"
/D "_WIN32_WINNT=0x0502"
/D "_WIN32"
/D "_NT"
/D "_CRT_NONSTDC_NO_WARNINGS"
/D "_MBCS"
/FD
/EHsc
/MD
/W3
/WX
/TP
/Zm1000

EDIT #1: Seeing as this might be a Visual Studio idiosyncrasy, I posted to Visual C++ Developer Center - warning C4018: '<' : signed/unsigned mismatch is emitted for 32-bit but not 64-bit compilation under VS2008 SP1 on 64-bit Windows.

EDIT #2: I was directed to post to Microsoft Connect from within the Visual C++ Developer Center posting, and today (2011-01-11) Microsoft replied to my question and verified it as a compiler issue: They stated that the issue will added to the backlog to be fixed in a future release: Microsoft Connect - warning C4018: '<' : signed/unsigned mismatch is only emitted between like-sized types.


Something's gone wrong, that line of code should and will generate the desired "warning C4018: '<' : signed/unsigned mismatch".

Here's my test project compiler settings, if these help at all:

/Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_UNICODE" /D "UNICODE" /Gm /EHsc /RTC1 /MDd /Yu"stdafx.h" /Fp"Debug\testproj1.pch" /Fo"Debug\" /Fd"Debug\vc90.pdb" /W3 /nologo /c /ZI /TP /errorReport:prompt

EDIT: this as tested with 32-bit Visual Studio, but you're asking about 64-bit compile, so this info is not relevant to you, my pardon.


Answering my own question: See my EDIT #2 in the original question area. It is now recognized by Microsoft as a compiler issue.

0

精彩评论

暂无评论...
验证码 换一张
取 消