How to disable warning C4927 in VS2013 Community - c++

I'm receiving the following warning in my project:
warning C4927: illegal conversion; more than one user-defined conversion has been implicitly applied while calling the constructor 'std::basic_string<char,std::char_traits<char>,std::allocator<char>>::basic_string(const _Elem *)'
with
[
_Elem=char
]
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\xstring(778) : see declaration of 'std::basic_string<char,std::char_traits<char>,std::allocator<char>>::basic_string'
I understand why it's happening, I'm just unable to suppress it. I've tried adding it to the Disable Specific Warnings list in my project settings, and I've also set my warning level to Turn Off All Warnings (/W0), yet the warning persists. Does anyone have any recommendations on how to hide the message?

You can control Visual Studio warnings directly in code using #pragma warning (https://msdn.microsoft.com/en-us/library/2c8f766e.aspx). If you'd like to silence the warning for a single line, you can put the following immediately before the line:
#pragma warning (suppress: 4927)
line-that-causes-warning-4927
You can also disable it from any point past the #pragma, by using 'disable' instead of 'suppress'. However, as the comments suggest, it's better to actually fix the warning, because it could be causing issues in your program.

Related

How to pinpoint what part of my code is making a library raise a compile-time error?

I am trying to compile a project and am getting the following error
It goes away if I suppress the warning by defining a macro
#define _SCL_SECURE_NO_WARNINGS
How can I pinpoint what part of my code is using that library in a way that is making it angry like that? Double clicking the error takes me to the xutility file, which is not very helpful.
Edit: The error description is Error C4996 'std::copy::_Unchecked_iterators::_Deprecate': Call to 'std::copy' with parameters that may be unsafe - this call relies on the caller to check that the passed values are correct. To disable this warning, use -D_SCL_SECURE_NO_WARNINGS. See documentation on how to use Visual C++ 'Checked Iterators'

No warning on deleting a forward declared pointer (Visual Studio)

Deleting forward declared pointers leads to undefined behavior.
Examples:
https://gist.github.com/jatinganhotra/4144778
https://stackoverflow.com/a/14382111/399908
However, my Visual Studio (VS2012) compiler doesn't warn me about it.
Is this an unfixed VS2012 compiler bug?
Did I disable (or never enable) the corresponding warning?
Is this specific to some project setting?
Visual Leak Detector hinted me to the problem, but is there some method (pragma, code, macro, ...) to detect this at compile time?
The respective warning is C4150.
It should be active by default and it is categorized in warning level 2 (which should be active too, since default warning level is W3 afaik).
Note: Instead of lowering the warning level, try to pragma warnings in specific cases.

MSVC - Suppress template being compiled with messages

I have an application that uses numerous templates and template specializations, and during MSVC compilation many messages are output showing how the templates are being compiled. This makes for an incredibly difficult time finding an actual compilation error. These messages are not output when the application is compiled on Linux using g++.
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\INCLUDE\map(382)
: see reference to function template instantiation 'std::pair<std::_Tree_iterator<std::_Tree_val<std::_Tree_simple_types<std::pair<const _Kty,_Ty>>>>,bool> std:
:_Tree<std::_Tmap_traits<_Kty,_Ty,_Pr,_Alloc,true>>::insert<std::pair<std::string,uint64_t>>(_Valty &&)' being compiled
with
[
_Kty=std::string
, _Ty=size_t
, _Pr=std::less<std::string>
, _Alloc=std::allocator<std::pair<const std::string,size_t>>
, _Valty=std::pair<std::string,uint64_t>
]
Is there a way can I suppress these more or less useless messages? Or possibly lower the verbosity setting? I've tried looking at link but I'm not sure if there is a flag that relates to the messages I'm seeing.
The message is related to an warning (or error) with a specific template instantiation. If it is a warning, you could suppress it (via #pragma warning, or project settings), and this message would also go away. Or, you could fix the cause of the warning. There is no way to suppress this message without also suppressing the warning, because without it, the warning doesn't make much sense.

Is there an alternative to suppressing warnings for unreachable code in the xtree?

When using the std::map with types that use trivial, non-throwing, copy constructors, a compiler warning/error is thrown (warning level 4, release mode) for unreachable code in xtree. This is because the std::map has a try-catch in it that helps maintain the state of the tree in the case of an exception, but the compiler figures out that the catch statement will never be called if the stored elements don't throw. These warnings can be easily suppressed with the following lines at the top of the .cpp file:
#pragma warning(push)
#pragma warning(disable:4702)
#include <xtree>
#pragma warning(pop)
Is there a way to bypass this warning/error without changing the warning level, building in debug, suppressing the warning, or using a different type in the map? Is there plans to change this in the standard library?
Update:
Maybe it is compiler specific. I am using vc7.
The error is below:
c:\program files\microsoft visual studio .net 2003\vc7\include\xtree(1116) : error C2220: warning treated as error - no 'object' file generated
c:\program files\microsoft visual studio .net 2003\vc7\include\xtree(1116) : warning C4702: unreachable code
Apparently the xtree is used by the std::map.
Unfortunately it looks like xtree is part of the underlying implementation of map in VC7, and as such there isn't much that can be done to mitigate it. It looks like it's a bug in the standard library.
Is it a possibility to use a newer compiler? I'm fairly sure there are free downloads of more recent versions of the compiler you could use, and perhaps they've fixed this issue.
If that's not an option, probably the best solution is to wrap the include of map into your own private header, complete with a comment and the #pragma+include <xtree> lines you already discovered (in addition to an include of map. This way you hide the workaround from normal use.

How can I inhibit warning 4200 in Visual Studio 2005?

I can inhibit many warnings in Visual Studio 2005 SP1 in the C/C++ Advanced property page, which causes the IDE to use the /wd switch on the command line which invokes the compiler. However, when I try to inhibit warning 4200 (nonstandard extension used : zero-sized array in struct/union), it still appears when I compile. (Of course it's justified; I'm just not in a position to fix the code, nor would it be worth bothering, because it's generated, and the warning is entirely benign under the circumstances.) Does anybody happen to know if this is a bug in the compiler? Or might there be something I can do about it?
To completely disable the warning in the file you can add the following to the top of the file
#pragma warning(disable:2400)
If you want some more flexibility other than a blanket disable for the file, the following page lists several other more fine grained options.
http://msdn.microsoft.com/en-us/library/2c8f766e(VS.80).aspx
It's unclear based on your information as to whether or not it's a bug in the compiler or a configuration issue. I would lean towards a configuration issue, specifically conflicting compiler options that is making it difficult to suppress the warning.
EDIT
OP mentioned they can't control the generated code so they can't directly include the pragma. If that's the case then try this trick. Say the file name is Generated.cpp. No longer include Generated.cpp as one of the files to compile. Instead create a new file called Example.cpp with the following contents
#pragma warning(disable:2400)
#include "Generated.cpp"
Now you'll get the text of Generated.cpp with the disabled warning by only compiling Example.cpp.
You mean like with pragma?
#pragma warning( disable : 2400 )