-
Improvement
-
Resolution: Unresolved
-
Minor
Several C++ compilers output additional "note" lines together with errors or warnings. These are currently thrown away, but are often the only way to understand what is going on.
Examples:
void foo(struct A *); void bar() { foo(1); }
on gcc gives
tt.cpp: In function 'void bar()': tt.cpp:2:19: error: invalid conversion from 'int' to 'A*' [-fpermissive] void bar() { foo(1); } ^ tt.cpp:1:6: note: initializing argument 1 of 'void foo(A*)' void foo(struct A *); ^~~
and on Visual Studio gives
tt.cpp(2): error C2664: 'void foo(A *)': cannot convert argument 1 from 'int' to 'A *' tt.cpp(2): note: Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
It would be nice if these notes could be viewed from the detail view and/or the source view.
There is an annoying special rule in gcc apparently that notes that end in a colon mean that the following error is part of the note:
void foo(struct A *); void foo(struct B *); void bar() { foo(1); }
gives
tt.cpp: In function 'void bar()': tt.cpp:3:19: error: no matching function for call to 'foo(int)' void bar() { foo(1); } ^ tt.cpp:1:6: note: candidate: void foo(A*) <near match> void foo(struct A *); ^~~ tt.cpp:1:6: note: conversion of argument 1 would be ill-formed: tt.cpp:3:19: error: invalid conversion from 'int' to 'A*' [-fpermissive] void bar() { foo(1); } ^ tt.cpp:2:6: note: candidate: void foo(B*) <near match> void foo(struct B *); ^~~ tt.cpp:2:6: note: conversion of argument 1 would be ill-formed: tt.cpp:3:19: error: invalid conversion from 'int' to 'B*' [-fpermissive] void bar() { foo(1); } ^
The errors here are not proper error messages, but rather part of the note before.
Also, it would be nice to have the full error location information available for gcc (i.e. the line starting with "In" and following. Adversarial example:
template<int N> struct A : A<N - 1> { };
template<> struct A<0>;
A<3> a;
gives
tt.cpp: In instantiation of 'struct A<1>': tt.cpp:1:24: recursively required from 'struct A<2>' tt.cpp:1:24: required from 'struct A<3>' tt.cpp:3:6: required from here tt.cpp:1:24: error: invalid use of incomplete type 'struct A<0>' template<int N> struct A : A<N - 1> { }; ^ tt.cpp:2:19: note: declaration of 'struct A<0>' template<> struct A<0>; ^~~~
This is a single error with lots of context. The Visual Studio error is fairly tame for that code:
C:\Users\Build\Desktop\tt.cpp(1): error C2504: 'A<0>': base class undefined C:\Users\Build\Desktop\tt.cpp(1): note: see reference to class template instantiation 'A<1>' being compiled C:\Users\Build\Desktop\tt.cpp(1): note: see reference to class template instantiation 'A<2>' being compiled C:\Users\Build\Desktop\tt.cpp(3): note: see reference to class template instantiation 'A<3>' being compiled
Another adversarial example, for Visual Studio:
template<typename T> struct A { A(T) { } };
A<char> a(256.0);
With a high enough warning level, this generates
C:\Users\Build\Desktop\tt.cpp(2): warning C4244: 'argument': conversion from 'double' to 'T', possible loss of data with [ T=char ]
This information is also pretty important.
As a further complication, the output format on Visual Studio is also affected by the `/MP` flag (see also JENKINS-56450).
We have a bit of real-world log data and warnings-ng analysis publically available:
- links to