locked
Compile warning level RRS feed

  • Question

  • Dear all,

    Can VC++ trigger compile warning msg when hitting the following conditions related to MFC:

    CString _str;

    if (_str = L"abc") //<--- (should be ==)
    {...}

    if we use some basic type like int or string(STL) to define for the above conditions, VC compiler can trigger warning msg(warning C4706: assignment within conditional expression) under level 4 warning, but not for MFC CString.

    Thanks and regards,

    Wallace Chan

    P.S: We're using VC++ 2003

    Tuesday, March 31, 2015 7:56 AM

Answers

  • "Can VC++ trigger compile warning msg when hitting the following conditions related to MFC: ... P.S: We're using VC++ 2003"

    Well, if you're stuck with 2003 then the simpler answer is "no". Though I'd follow David Lowndes advice and create a bug on Connect. But do not mention that you're using 2003 because they may close the bug without looking at it, 2003 is no longer supported.

    "It's interesting that std::string gives rise to an error in this situation (I get a C2451 error with VS2015 CTP), so it'd be neat if CString did similar."

    The error is generated because std::string has no conversion that can produce a bool. This was always an error. On the other hand CString has a conversion to char* which gets hijacked to produce a bool.

    • Marked as answer by Shu 2017 Wednesday, April 8, 2015 7:13 AM
    Tuesday, March 31, 2015 11:27 AM

All replies

  • Can VC++ trigger compile warning msg when hitting the following conditions related to MFC:

    It would appear not.

    CString _str;
    if (_str = L"abc") //<--- (should be ==)
    {...}
    if we use some basic type like int or string(STL) to define for the above conditions, VC compiler can trigger warning msg(warning C4706: assignment within conditional expression) under level 4 warning, but not for MFC CString.

    It's interesting that std::string gives rise to an error in this
    situation (I get a C2451 error with VS2015 CTP), so it'd be neat if
    CString did similar.

    Can you file a bug/suggestion for this on MS connect
    https://connect.microsoft.com/visualStudio/. Post a link back here to
    your report so anyone who sees this can easily find it and vote for
    it.

    Dave

    Tuesday, March 31, 2015 10:54 AM
  • "Can VC++ trigger compile warning msg when hitting the following conditions related to MFC: ... P.S: We're using VC++ 2003"

    Well, if you're stuck with 2003 then the simpler answer is "no". Though I'd follow David Lowndes advice and create a bug on Connect. But do not mention that you're using 2003 because they may close the bug without looking at it, 2003 is no longer supported.

    "It's interesting that std::string gives rise to an error in this situation (I get a C2451 error with VS2015 CTP), so it'd be neat if CString did similar."

    The error is generated because std::string has no conversion that can produce a bool. This was always an error. On the other hand CString has a conversion to char* which gets hijacked to produce a bool.

    • Marked as answer by Shu 2017 Wednesday, April 8, 2015 7:13 AM
    Tuesday, March 31, 2015 11:27 AM
  • "Can VC++ trigger compile warning msg when hitting the following conditions related to MFC: ... P.S: We're using VC++ 2003"
    Well, if you're stuck with 2003 then the simpler answer is "no". Though I'd follow David Lowndes advice and create a bug on Connect. But do not mention that you're using 2003 because they may close the bug without looking at it, 2003 is no longer supported.

    Yes, mention it as VS2015 CTP - that's what I've used.

    The error is generated because std::string has no conversion that can produce a bool. This was always an error. On the other hand CString has a conversion to char* which gets hijacked to produce a bool.

    Thanks for pointing that out Mike.

    Dave

    Tuesday, March 31, 2015 12:46 PM