MSVC sillywarnings -- more?

Discussion in 'C++' started by Alf P. Steinbach, Feb 23, 2010.

  1. I just added MSVC sillywarnings to this list as I encountered them.

    Are there more that should be added?

    Note: "unreferenced" warnings are handled by other explicit mechanism.


    <code>
    // Copyright (c) Alf P. Steinbach, 2010.
    // #include <progrock/cppx/compiler_specific/msvc/no_sillywarnings_please.h>

    #ifndef PROGROCK_CPPX_COMPILERSPECIFIC_MSVC_NOSILLYWARNINGSPLEASE_H
    #define PROGROCK_CPPX_COMPILERSPECIFIC_MSVC_NOSILLYWARNINGSPLEASE_H


    #ifndef _MSC_VER
    # error This file is specific to the MSVC (Microsoft Visual C++) compiler.
    #endif

    #pragma warning( disable: 4061 ) // enum value is not *explicitly* handled in
    switch
    #pragma warning( disable: 4217 ) // member template isn't copy constructor
    #pragma warning( disable: 4250 ) // inherits (implements) some member via
    dominance
    #pragma warning( disable: 4347 ) // "behavior change", function called
    instead of template
    #pragma warning( disable: 4355 ) // "'this': used in member initializer list
    #pragma warning( disable: 4505 ) // unreferenced function has been removed
    #pragma warning( disable: 4510 ) // default constructor could not be generated
    #pragma warning( disable: 4511 ) // copy constructor could not be generated
    #pragma warning( disable: 4512 ) // assignment operator could not be generated
    #pragma warning( disable: 4513 ) // destructor could not be generated
    #pragma warning( disable: 4623 ) // default constructor could not be generated
    #pragma warning( disable: 4624 ) // destructor could not be generated
    #pragma warning( disable: 4625 ) // copy constructor could not be generated
    #pragma warning( disable: 4626 ) // assignment operator could not be generated
    #pragma warning( disable: 4640 ) // a local static object is not thread-safe
    #pragma warning( disable: 4670 ) // a base class of an exception class is
    inaccessible for catch
    #pragma warning( disable: 4672 ) // a base class of an exception class is
    ambiguous for catch
    #pragma warning( disable: 4673 ) // a base class of an exception class is
    inaccessible for catch
    #pragma warning( disable: 4675 ) // resolved overload was found by
    argument-dependent lookup
    #pragma warning( disable: 4702 ) // unreachable code, e.g. in <list> header.
    #pragma warning( disable: 4710 ) // call was not inlined
    #pragma warning( disable: 4711 ) // call was inlined
    #pragma warning( disable: 4820 ) // some padding was added
    #pragma warning( disable: 4917 ) // a GUID can only be associated with a
    class, interface or namespace

    // The following are real warnings but are generated by almost all MS headers,
    including
    // standard library headers, so it's impractical to leave them on.
    #pragma warning( disable: 4619 ) // there is no warning number 'XXXX'
    #pragma warning( disable: 4668 ) // XXX is not defined as a preprocessor macro


    #endif
    </code>


    Cheers,

    - Alf
     
    Alf P. Steinbach, Feb 23, 2010
    #1
    1. Advertising

  2. Alf P. Steinbach

    red floyd Guest

    On Feb 23, 2:02 am, "Alf P. Steinbach" <> wrote:
    > I just added MSVC sillywarnings to this list as I encountered them.
    >
    > Are there more that should be added?
    >


    > #ifndef _MSC_VER
    > #   error This file is specific to the MSVC (Microsoft Visual C++) compiler.
    > #endif


    Is there a reason you #error if it isn't MSVC? Why not just bypass
    all the #pragmas
    for non-VC code?
     
    red floyd, Feb 23, 2010
    #2
    1. Advertising

  3. Alf P. Steinbach

    Noah Roberts Guest

    In article <hm093t$974$-september.org>,
    says...
    >
    > I just added MSVC sillywarnings to this list as I encountered them.
    >
    > Are there more that should be added?
    >
    > Note: "unreferenced" warnings are handled by other explicit mechanism.
    >
    >
    > <code>
    > // Copyright (c) Alf P. Steinbach, 2010.
    > // #include <progrock/cppx/compiler_specific/msvc/no_sillywarnings_please.h>
    >
    > #ifndef PROGROCK_CPPX_COMPILERSPECIFIC_MSVC_NOSILLYWARNINGSPLEASE_H
    > #define PROGROCK_CPPX_COMPILERSPECIFIC_MSVC_NOSILLYWARNINGSPLEASE_H


    I'd add the macro's that ruin the stupid deprecation warnings:
    #define _CRT_SECURE_NO_DEPRECATE

    There's also 4099 - type name first seen using 'struct' now seen using
    'class' - or visa versa.



    --
    http://crazyeddiecpp.blogspot.com
     
    Noah Roberts, Feb 23, 2010
    #3
  4. * red floyd:
    > On Feb 23, 2:02 am, "Alf P. Steinbach" <> wrote:
    >> I just added MSVC sillywarnings to this list as I encountered them.
    >>
    >> Are there more that should be added?
    >>

    >
    >> #ifndef _MSC_VER
    >> # error This file is specific to the MSVC (Microsoft Visual C++) compiler.
    >> #endif

    >
    > Is there a reason you #error if it isn't MSVC? Why not just bypass
    > all the #pragmas
    > for non-VC code?


    I feel the code gets too complex if different compilers and OS'es and versions
    of libraries etc. are supported in the same file.

    As I recall some files in Boost mix this up, special-casing this and that via
    preprocessor directives in the middle of files, and anyway I felt I'd had enough
    of that.

    Practically it cannot be avoided to make the decision somewhere, but I feel it's
    more clean if that decision is separated from implementation of functionality.


    Cheers,

    - Alf
     
    Alf P. Steinbach, Feb 23, 2010
    #4
  5. Alf P. Steinbach

    Noah Roberts Guest

    In article <hm093t$974$-september.org>,
    says...
    >
    > I just added MSVC sillywarnings to this list as I encountered them.
    >
    > Are there more that should be added?
    >
    > Note: "unreferenced" warnings are handled by other explicit mechanism.


    > #pragma warning( disable: 4505 ) // unreferenced function has been
    > removed


    I'm actually having trouble with a program that generates this warning,
    and it's the first time I've ever seen the warning. See my thread on MI
    & clone().

    --
    http://crazyeddiecpp.blogspot.com
     
    Noah Roberts, Feb 23, 2010
    #5
  6. Alf P. Steinbach

    Krice Guest

    On 23 helmi, 12:02, "Alf P. Steinbach" <> wrote:
    > Are there more that should be added?


    Warning for silly programmers.
     
    Krice, Feb 24, 2010
    #6
  7. * Alf P. Steinbach:
    > I just added MSVC sillywarnings to this list as I encountered them.
    >
    > Are there more that should be added?
    >
    > Note: "unreferenced" warnings are handled by other explicit mechanism.


    I've now added the following:

    4127 // conditional expression is constant
    4661 // Juha Nieminen| a member of the template class is not defined
    4099 // Noah Roberts| first seen using 'struct' now seen using 'class'
    4251 // Paavo Helde| needs to have dll-interface to be used by clients
    4275 // Paavo Helde| exported class derived from non-exported class

    So, for those who perhaps want the list so as to transform MSVC into something
    reasonable (quite a lot of code now compiles cleanly at warning level 4!),


    <code>
    #pragma warning( disable: 4061 ) // enum value is not *explicitly* handled in
    switch
    #pragma warning( disable: 4099 ) // first seen using 'struct' now seen using
    'class'
    #pragma warning( disable: 4127 ) // conditional expression is constant
    #pragma warning( disable: 4217 ) // member template isn't copy constructor
    #pragma warning( disable: 4250 ) // inherits (implements) some member via
    dominance
    #pragma warning( disable: 4251 ) // needs to have dll-interface to be used by
    clients
    #pragma warning( disable: 4275 ) // exported class derived from non-exported
    class
    #pragma warning( disable: 4347 ) // "behavior change", function called
    instead of template
    #pragma warning( disable: 4355 ) // "'this': used in member initializer list
    #pragma warning( disable: 4505 ) // unreferenced function has been removed
    #pragma warning( disable: 4510 ) // default constructor could not be generated
    #pragma warning( disable: 4511 ) // copy constructor could not be generated
    #pragma warning( disable: 4512 ) // assignment operator could not be generated
    #pragma warning( disable: 4513 ) // destructor could not be generated
    #pragma warning( disable: 4623 ) // default constructor could not be generated
    #pragma warning( disable: 4624 ) // destructor could not be generated
    #pragma warning( disable: 4625 ) // copy constructor could not be generated
    #pragma warning( disable: 4626 ) // assignment operator could not be generated
    #pragma warning( disable: 4640 ) // a local static object is not thread-safe
    #pragma warning( disable: 4661 ) // a member of the template class is not
    defined.
    #pragma warning( disable: 4670 ) // a base class of an exception class is
    inaccessible for catch
    #pragma warning( disable: 4672 ) // a base class of an exception class is
    ambiguous for catch
    #pragma warning( disable: 4673 ) // a base class of an exception class is
    inaccessible for catch
    #pragma warning( disable: 4675 ) // resolved overload was found by
    argument-dependent lookup
    #pragma warning( disable: 4702 ) // unreachable code, e.g. in <list> header.
    #pragma warning( disable: 4710 ) // call was not inlined
    #pragma warning( disable: 4711 ) // call was inlined
    #pragma warning( disable: 4820 ) // some padding was added
    #pragma warning( disable: 4917 ) // a GUID can only be associated with a
    class, interface or namespace

    // The following are real warnings but are generated by almost all MS headers,
    including
    // standard library headers, so it's impractical to leave them on.
    #pragma warning( disable: 4619 ) // there is no warning number 'XXXX'
    #pragma warning( disable: 4668 ) // XXX is not defined as a preprocessor macro
    </code>


    Cheers,

    - Alf
     
    Alf P. Steinbach, Feb 25, 2010
    #7
  8. Alf P. Steinbach

    Balog Pal Guest

    "Alf P. Steinbach" <>

    > 4127 // conditional expression is constant


    That is not silly at all, and do catch mistakes -- though too bad it can't
    guess where we used a constant intentionally...

    > 4099 // Noah Roberts| first seen using 'struct' now seen using 'class'


    Some versions create different names for class/struct so ignoring this may
    lead to cryptic linker errors...

    My tuning file looks like below. I normally compile at W3 switching to W4
    only occasionally. So most tuning is actually to elevate levels...


    - ----------
    // this file rearranges the default levels of warning messages
    #pragma warning(2:4032) // function arg has different type from
    declaration
    #pragma warning(2:4092) // 'sizeof' value too big
    #pragma warning(2:4132 4268)// const object not initialized
    #pragma warning(2:4152) // pointer conversion between function and data
    #pragma warning(error:4239) // standard doesn't allow this conversion
    #pragma warning(error:4172) // returning address of local variable or
    temporary
    #pragma warning(1:4701 4700) // local variable used without being
    initialized
    #pragma warning(2:4706) // if (a=b) instead of (if a==b)
    #pragma warning(2:4709) // comma in array subscript
    #pragma warning(2:4061) // not all enum values tested in switch
    statement
    #pragma warning(4:4710) // inline function was not inlined
    #pragma warning(1:4121) // space added for structure alignment
    #pragma warning(disable:4505) // unreferenced local function removed
    #pragma warning(3:4019) // empty statement at global scope
    #pragma warning(3:4057) // pointers refer to different base types
    #pragma warning(3:4125) // decimal digit terminates octal escape
    #pragma warning(2:4131) // old-style function declarator
    #pragma warning(3:4211) // extern redefined as static
    #pragma warning(4:4213) // cast on left side of = is non-standard
    #pragma warning(1:4222) // member function at file scope shouldn't be
    static
    #pragma warning(error:4234 4235)// keyword not supported or reserved for
    future
    #pragma warning(3:4504) // type ambiguous; simplify code
    #pragma warning(3:4507) // explicit linkage specified after default
    linkage
    #pragma warning(1:4515) // namespace uses itself
    #pragma warning(3:4516 4517)// access declarations are deprecated
    #pragma warning(3:4670) // base class of thrown object is inaccessible
    #pragma warning(3:4671) // copy ctor of thrown object is inaccessible
    #pragma warning(3:4673) // thrown object cannot be handled in catch
    block
    #pragma warning(3:4674) // dtor of thrown object is inaccessible
    #pragma warning(error:4705) // statement has no effect (example: a+1;)

    #pragma warning(disable:4786) // identifier was truncated to 'number'
    characters in the debug information

    #pragma warning(3:4727) // conditional expression is constant
    #pragma warning(error:4508) // function should return a value; void return
    type assumed

    #pragma warning(3:4239) //nonstandard extension used : 'token' : conversion
    from 'type' to 'type'
    #pragma warning(error:4146) //unary minus operator applied to unsigned type,
    result still unsigned
    #pragma warning(1:4132) //'object' : const object should be initialized

    #pragma warning(1:4238) //nonstandard extension used : class rvalue used as
    lvalue

    #pragma warning (disable:4097) //'typedef-name 'tParent' used as synonym for
    class-name 'IdxArr<struct tabdef>'
    #pragma warning (disable:4710) //function not expanded
    #pragma warning (disable:4711) //function 'function' selected for inline
    expansion


    #ifdef _DEBUG
    #pragma warning(4:4800) //forcing bool variable to one or zero, possible
    performance loss
    #else
    #pragma warning(disable:4800) //forcing bool variable to one or zero,
    possible performance loss
    #pragma warning(disable:4100) //unreferenced formal parameter
    #endif

    #pragma warning(disable:4290) //C++ exception specification ignored
     
    Balog Pal, Feb 26, 2010
    #8
  9. Alf P. Steinbach

    Balog Pal Guest

    "Pete Becker" <>
    >>> 4099 // Noah Roberts| first seen using 'struct' now seen using
    >>> 'class'

    >>
    >> Some versions create different names for class/struct so ignoring this
    >> may lead to cryptic linker errors...
    >>

    >
    > So the warning is telling you that the compiler has done something that is
    > not allowed by the language definition.


    Yeah :-/

    It is still better than doing it in the dark. ;-)
     
    Balog Pal, Feb 26, 2010
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dan
    Replies:
    0
    Views:
    1,123
  2. Victor Bazarov

    Re: array of complex numbers in MSVC++ 6

    Victor Bazarov, Jul 5, 2003, in forum: C++
    Replies:
    0
    Views:
    493
    Victor Bazarov
    Jul 5, 2003
  3. icedac
    Replies:
    1
    Views:
    359
    Bogdan Sintoma
    Feb 2, 2005
  4. Michael
    Replies:
    4
    Views:
    467
    Matt Hammond
    Jun 26, 2006
  5. Robert Klemme

    With a Ruby Yell: more, more more!

    Robert Klemme, Sep 28, 2005, in forum: Ruby
    Replies:
    5
    Views:
    236
    Jeff Wood
    Sep 29, 2005
Loading...

Share This Page