MSVC sillywarnings -- more?

A

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.


<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
 
R

red floyd

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?
 
N

Noah Roberts

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.
 
A

Alf P. Steinbach

* red floyd:
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
 
N

Noah Roberts

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().
 
A

Alf P. Steinbach

* 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
 
B

Balog Pal

Alf P. Steinbach said:
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
 
B

Balog Pal

Pete Becker said:
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. ;-)
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top