How to disable "note:" hints for msvc c++ compiler - c++

I'm using msvc cl.exe directly without visual studio and would like to have an easy way to read warnings and errors. I have quite complicated template setup and when i receive some warning or errors i have to scroll through wall of compiler output like
/internal/include/internal/scene/states/scene_events.h(32): error C2440: 'static_cast': cannot convert from 'game::events::random_event' to 'float'
/helpers/tsm/include/tsm/internal/actions.h(55): note: see reference to function template instantiation 'void game::internal::playing_event::receive_event::operator ()<FSM,OutState>(game::events::random_event &&,FSM &,InState &,game::internal::playing_event &) const' being compiled
with
[
FSM=tsm::back::internal::machine_base<game::internal::scene_fsm>,
OutState=game::internal::ready,
InState=game::internal::ready
]
/helpers/tsm/include/tsm/internal/actions.h(54): note: while compiling class template member function 'void tsm::actions::internal::action_invocation<Action,FSM,Event,InState,OutState>::operator ()(Event &&,FSM &,InState &,OutState &) const'
with
[
Action=game::internal::playing_event::receive_event,
FSM=tsm::back::internal::machine_base<game::internal::scene_fsm>,
Event=game::events::random_event,
InState=game::internal::ready,
OutState=game::internal::playing_event
]
....
and so on and so on. are there any options to disable "note:" output?
i didn't find any in official docs

Sorry for being the bearer of the bad news, but there is no way to disable those notes output from the compiler diagnostics.
There are (were) some filtering 3rd party tools, but discussing those would be offtopic.

Related

What is the alternative for -fpermssive flag in windows (visual studio)

I am using third party code(openssl) from our product code. While compiling the code, I am getting the errors which can be suppressed as warnings using -fpermissive flag in Linux (gcc/g++). In windows, I am getting the same compilation errors in visual studio (2005). Would like to know the alternative of -fpermissive flag that can be used in visual studio to suppress the errors.
I tried adding the flags such as '/fpermissive' , '/Ze' in module properties->C/C++->command Line->Additional options. But it did not resolve the problem.
Getting the errors like below.
ssl/packet_locl.h(429) : error C2440: '=' : cannot convert from 'void *' to 'unsigned char 'Conversion from 'void' to pointer to non-'void' requires an explicit cast
Since it is giving error in third party code, we can not make any code changes there.
Expected results: We need to suppress this error as warning and then proceed with compilation successfully.
>>I tried adding the flags such as '/fpermissive' , '/Ze' in module properties->C/C++->command Line->Additional options.
That is define on gcc, you cannot use on VS. This is not suitable for VS.
>>cannot convert from 'void *' to 'unsigned char 'Conversion from 'void' to pointer to non-'void' requires an explicit cast
These are errors defined by the language. You can't ignore these errors and run the program directly. They cannot be compiled.
>>Since it is giving error in third party code, we can not make any code changes there.
If you strictly abide by the method to use the interfaces of these third party libraries, There will be no such errors. What your need is modifying your own code, not changing the third party library code.

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.

How can I avoid this warning with boost:gil:png_write_view on x64

The following code issues a warning:
boost::gil::rgb8_image_t img(10, 10);
boost::gil::png_write_view("TenByTen.png", view(img));
when compiled with VS 2010 under 64 bit. It says:
\boost\gil\extension\io\png_io_private.hpp(341): warning C4244: 'argument' : conversion from '__int64' to 'png_uint_32', possible loss of data
\boost\gil\extension\io\png_io.hpp(202) : see reference to function template instantiation 'void boost::gil::detail::png_writer::apply<View>(const View &)' being compiled
with
[
View=boost::gil::image_view<boost::gil::rgb8_loc_t>
]
main.cpp(20) : see reference to function template instantiation 'void boost::gil::png_write_view<boost::gil::image_view<Loc>>(const char *,const View &)' being compiled
with
[
Loc=boost::gil::rgb8_loc_t,
View=boost::gil::image_view<boost::gil::rgb8_loc_t>
]
It seems quite obvious that in apply() the call to png_set_IHDR() should give a png_uint_32, but view.width() seems to be a signed __int64 (maybe a ptrdiff_t).
Does anybody know what i could do about it?
I guess that boost:gil is meant to work under 64 bits.
I use boost 1_50.
It seems that the specific issue is known from (at least) Boost v1.35 (e.g. http://objectmix.com/c/733997-how-use-graphics.html#post2586573).
Checking Boost trac database I see similar tickets for other modules but nothing for GIL.
Probably the best thing is open a new ticket.
Meanwhile, since it doesn't seem "catastrophic", you could wrap the #include(s) in this way:
#ifdef _MSC_VER
# pragma warning(push)
# pragma warning(disable: 4244) // Perhaps also 4100, 4127, 4512
// GIL headers
# pragma warning(pop)
#endif
See also How to: Enable and Disable Code Analysis for Specific C/C++ Warnings
(with clang/gcc you have the -isystem switch, but I don't think Visual Studio lets you differentiate between application/header files)

How can I test the portability of a C++ codebase developed and managed in Visual Studio 2010?

I have a very large and very old C++ project currently maintained in Visual Studio 2010. One member of our team has just tested the bumpiness of the upgrade path to VS 2012, and found we were being affected by this, through our use of Microsoft's non-standard extensions to the language.
Is there any tool we can run over our codebase that will tell us how many other non-standard extensions we're using, so we can eliminate them before they cause us any more problems?
Specify the compiler switch /Za which disables extensions.
For example, the following code:
#include <string>
void f(std::string&) {}
int main()
{
f(std::string("hello"));
}
Compiles (with warning) when /Za is not specified but fails to compile when /Za is specified with the following error:
main.cpp(7) : error C2664: 'f' : cannot convert parameter 1 from 'std::basic_string<_Elem,_Traits,_Ax>' to 'std::string &'
with
[
_Elem=char,
_Traits=std::char_traits,
_Ax=std::allocator
]
A non-const reference may only be bound to an lvalue

Tools to generate higher-quality error messages for template-based code?

Concepts, that would render these tools unnecessary, are not part of C++11.
STLFilt would have been one option but it is no longer maintained.
Clang claims to give expressive diagnostics although important C++11 features are not available yet.
colorgcc seems to be abandoned since 1999.
What production quality tools are available to decipher error messages stemming from template-based code? Eclipse-CDT support would be nice too. :)
If I give up on C++11, what options do I have for C++98?
Related questions:
Deciphering C++ template error messages
Improving g++ output
Let's have a stab at an answer (I marked this community wiki so we get a good response together)...
I'm working since a long time with templates and error messages have generally improved in some way or another:
Writing a stack of errors creates a lot more text but also typically includes the level the user is looking at and this generally includes a hint at what the actual problem is. Given that the compiler only sees a translation unit tossed at it, there isn't a lot which can be done determining which error in the stack is the one most suitable for the user.
Using concept checkers, i.e. classes or functions which exercise all the required members of template arguments and possibly generating errors messages using static_assert() give the template author a way to tell users about assumptions which apparently don't hold.
Telling the user about types he writes rather than expanding all typedefs as the compiler like to see at the lowest level also helps. clang is rather good at this and actually gives you error messages e.g. talking about std::string rather than expanding things type to whatever it ends up to be.
A combination of the technique actually causes e.g. clang to create quite decent error message (even if it doesn't implement C++2011, yet; however, no compiler does and as far as I can tell gcc and clang are leading the pack). I know other compiler developers actively work on improving the template error messages as lots of programmers have discovered that templates actually are a huge leap forward even though the error messages are something which takes a bit of getting used to.
One problem tools like stlfilt face is that C++ compilers and libraries are under active development. This results in error messages shifting all the time, causing the tool to receive different outputs. While it is good that compiler writers work on improving error messages, it certainly makes life harder for people who try to work from the error messages they got. There is another side to this as well: once a certain error pattern is detected to be common and is picked up e.g. by stlfilt (well, it isn't actively maintained as far as I know) compiler writers are probably keen to report the errors following these patterns directly, possibly also providing additional information available to the compiler but not emitted before. Put differently, I would expect that compiler writers are quite receptive to reports from users describing common error situations and how they are best reported. The compiler writers may not encounter the errors themselves because the code they are working on is actually C (e.g. gcc is implemented in C) or because they are so used to certain template techniques that they avoid certain errors (e.g. omission of typename for dependent types).
Finally, to address the question about concrete tools: the main "tool" I'm using when I get kind of stuck with a compiler complaining about some template instantiation is to use different compilers! Although it isn't always the case but often one compiler reports an entirely incomprehensible error messages which only makes sense after seeing the fairly concise report from another compiler (in case you are interested, I regularly use recent version of gcc, clang, and EDG for this). I'm not aware of a readily packaged too like stlfilt, however.
I know this may not be as helpful as you wanted, but I've found the best tool against template error messages is knowledge.
A good understanding of the STL and how to use it will help you avoid lots of errors in the first place. Secondly, often error messages refer to functions in the STL source - if you have a rough idea how the STL is implemented, this can be extremely helpful in deciphering what the error message is going on about. Finally, compiler makers are aware of this issue and are gradually improving error message output, so you would do well to stick to the latest version of your compiler.
Here's a good example of an obscure template error:
std::vector<std::unique_ptr<int>> foo;
std::vector<std::unique_ptr<int>> bar = foo;
unique_ptr is not copyable, it can only be moved. So trying to assign a vector of unique_ptr to another vector will mean somewhere in the vector source code will try to copy a unique pointer. Therefore the error will originate from code which is not yours and throw a fairly opaque error message as a result. The ideal error message would be
main.cpp(20): cannot construct 'bar' from 'foo': foo's template type is non-copyable
Instead, VS2010 gives the following error:
1>C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xmemory(48): error C2248: 'std::unique_ptr<_Ty>::unique_ptr' : cannot access private member declared in class 'std::unique_ptr<_Ty>'
1> with
1> [
1> _Ty=int
1> ]
1> C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\memory(2347) : see declaration of 'std::unique_ptr<_Ty>::unique_ptr'
1> with
1> [
1> _Ty=int
1> ]
1> C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xmemory(197) : see reference to function template instantiation 'void std::_Construct<std::unique_ptr<_Ty>,const std::unique_ptr<_Ty>&>(_Ty1 *,_Ty2)' being compiled
1> with
1> [
1> _Ty=int,
1> _Ty1=std::unique_ptr<int>,
1> _Ty2=const std::unique_ptr<int> &
1> ]
1> C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xmemory(196) : while compiling class template member function 'void std::allocator<_Ty>::construct(std::unique_ptr<int> *,const _Ty &)'
1> with
1> [
1> _Ty=std::unique_ptr<int>
1> ]
1> C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\vector(421) : see reference to class template instantiation 'std::allocator<_Ty>' being compiled
1> with
1> [
1> _Ty=std::unique_ptr<int>
1> ]
1> C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\vector(481) : see reference to class template instantiation 'std::_Vector_val<_Ty,_Alloc>' being compiled
1> with
1> [
1> _Ty=std::unique_ptr<int>,
1> _Alloc=std::allocator<std::unique_ptr<int>>
1> ]
1> main.cpp(19) : see reference to class template instantiation 'std::vector<_Ty>' being compiled
1> with
1> [
1> _Ty=std::unique_ptr<int>
1> ]
Sifting through this there are clues. The first section references a private member access of std::unique_ptr<int>. The second section, if you click through to the source line, points at the copy constructor of unique_ptr, which is declared beneath a private: specifier. So now we know we tried to copy a unique_ptr which is not allowed. Sections 3, 4 and 5 just point to boilerplate code - it's just noise. Section 6 says "see reference to class template instantiation 'std::_Vector_val<_Ty,_Alloc>' being compiled". In other words, this error happened in vector's template code. The last section is most interesting: it directly points at the line declaring foo in your own source code - it's figured out where in your own source code the error originated from!
So adding up the clues:
It originates in foo,
It originates in vector code,
It tries to copy a unique_ptr which is not allowed.
Conclusion: the vector tried to copy one of its elements, which is not allowed. Review code for foo and check for anything causing a copy.
Since the compiler only pointed at foo's declaration, if the assignment is far away in the source code some hunting will be involved. This obviously is not ideal, but I think this approach ultimately gives you more chance of fixing mistakes in general. You'll start to recognise that kind of error dump means "you copied a unique_ptr". Again, I'm not defending it, it definitely needs improving - but I think these days there's just enough information in the output that combined with a good knowledge of the STL allows you to fix the problem.
I have found Clang to generate the best error messages for heavily templated code.
Of course verbosity is unavoidable in most cases, but it's still better than GCC or MSVC most of the time. Here's the Clang error message for the example code posted by AshleysBrain:
$ clang++ -std=c++11 -stdlib=libc++ -o dummy dummy.cpp
In file included from dummy.cpp:1:
In file included from /usr/include/c++/v1/vector:243:
In file included from /usr/include/c++/v1/__bit_reference:15:
In file included from /usr/include/c++/v1/algorithm:594:
/usr/include/c++/v1/memory:1425:36: error: calling a private constructor of class 'std::__1::unique_ptr<int,
std::__1::default_delete<int> >'
::new ((void*)__p) _Tp(_STD::forward<_Args>(__args)...);
^
/usr/include/c++/v1/memory:1358:14: note: in instantiation of function template specialization
'std::__1::allocator_traits<std::__1::allocator<std::__1::unique_ptr<int, std::__1::default_delete<int> > >
>::__construct<std::__1::unique_ptr<int, std::__1::default_delete<int> >, std::__1::unique_ptr<int,
std::__1::default_delete<int> > &>' requested here
{__construct(__has_construct<allocator_type, pointer, _Args...>(),
^
/usr/include/c++/v1/vector:781:25: note: in instantiation of function template specialization
'std::__1::allocator_traits<std::__1::allocator<std::__1::unique_ptr<int, std::__1::default_delete<int> > >
>::construct<std::__1::unique_ptr<int, std::__1::default_delete<int> >, std::__1::unique_ptr<int,
std::__1::default_delete<int> > &>' requested here
__alloc_traits::construct(__a, _STD::__to_raw_pointer(this->__end_), *__first);
^
/usr/include/c++/v1/vector:924:9: note: in instantiation of function template specialization
'std::__1::vector<std::__1::unique_ptr<int, std::__1::default_delete<int> >,
std::__1::allocator<std::__1::unique_ptr<int, std::__1::default_delete<int> > >
>::__construct_at_end<std::__1::unique_ptr<int, std::__1::default_delete<int> > *>' requested here
__construct_at_end(__x.__begin_, __x.__end_);
^
dummy.cpp:7:37: note: in instantiation of member function 'std::__1::vector<std::__1::unique_ptr<int,
std::__1::default_delete<int> >, std::__1::allocator<std::__1::unique_ptr<int, std::__1::default_delete<int> > >
>::vector' requested here
std::vector<unique_ptr<int>> bar = foo;
^
/usr/include/c++/v1/memory:1997:5: note: declared private here
unique_ptr(const unique_ptr&);
^
1 error generated.
It's still long and ugly, but in my opinion much clearer regarding what/where the problem is.