https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77462
Bug ID: 77462 Summary: Error message prints source from wrong file after #line Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: d.frey at gmx dot de Target Milestone: --- When I use #line, I can make the compiler print a source line from another file when it encounters an error. This is totally misleading. Consider two files, first fool.cc: #include "liar.hh" int main() { static_assert( 2 + 2 == 4, "oops" ); } and a second file liar.hh: #line 5 "fool.cc" static_assert( 2 + 2 == 5, "oops" ); If I now compile with GCC, I get: frey@vbox::~/work/test/lie_to_me$ g++-6 -std=c++11 fool.cc In file included from fool.cc:1:0: fool.cc:5:3: error: static assertion failed: oops static_assert( 2 + 2 == 4, "oops" ); ^~~~~~~~~~~~~ Note the line says "2 + 2 == 4", which is the line from "fool.cc", not the one where the error *actually* occurs, namely the one saying "2 + 2 == 5" from "liar.hh". Clang gets it right: frey@vbox:1:~/work/test/lie_to_me$ clang++-3.9 -std=c++11 fool.cc In file included from fool.cc:1: fool.cc:5:3: error: static_assert failed "oops" static_assert( 2 + 2 == 5, "oops" ); ^ ~~~~~~~~~~ 1 error generated. Yes, #line leads to "fool.cc:5:3", but that is fine and what is intended by #line is AFAICT *not* to read the source line for the error message from that file and line.