c++ - Interpreting gcc warning/error messages split across multiple lines -




the gcc/g++ compiler (gcc 4.9.2) outputs error messages across multiple lines , sometimes multiple consecutive lines should read one, in order details , fullest explanation error.

my question is, how tell when multiple error lines should read one, , when given error line read itself?

in other words, when error message continued next error message , when single 1 line independent error message?

here example of program wrote deliberately fails compile in way understand , know multi-line error messages part of 1 message , telling me 1 thing:

the code:

  1   #include <iostream>   2      3      4   using std::cout;   5   using std::endl;   6      7   class myclass   8   {   9       public:  10           // not ok because gets initialised before b  11           // see warning in gcc output  12           myclass(int x) : b(x), a(b-1), c(0)  13           { cout << "a=" <<  14               << "\nb=" << b  15                << "\nc=" << c << "\n";   16           };  17     18       private:  19           int a;  20           int b;  21           int c;  22   }; 

the output of compilation:

user@computer:$ make proggy    g++ -std=c++98 -pedantic -wall -werror    proggy.cpp   -o proggy proggy.cpp: in constructor ‘myclass::myclass(int)’: proggy.cpp:20:13: error: ‘myclass::b’ initialized after [-werror=reorder]          int b;              ^ proggy.cpp:19:13: error:   ‘int myclass::a’ [-werror=reorder]          int a;              ^ proggy.cpp:12:9: error:   when initialized here [-werror=reorder]          myclass(int x) : b(x), a(b-1), c(0)          ^ cc1plus: warnings being treated errors <builtin>: recipe target 'proggy' failed make: *** [proggy] error 1 

notice full message single issue (which order of usage doesn't match order of initialisation) split on 3 error message lines.

the first error message says:

proggy.cpp:20:13: error: ‘myclass::b’ initialized after 

which sentence hasn't been finished. needs have next 2 error messages appended it. , if read second error message in isolation, make no sense:

 proggy.cpp:19:13: error:   ‘int myclass::a’ [-werror=reorder]              int a; 

so, need merge these messages 1 , form single sentence stating problem is. sentence this:

    "‘myclass::b’ initialized after ‘myclass::a’ when initialized    here (line 12) --> myclass(int x) : b(x), a(b-1), c(0)" 

that obvious in example because small example , understand going on in code. if have more lengthy error message output, how know when read number of consecutive error messages one?

how know when given error message continued next error message , when not?





wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -