#line directive/template interaction produces wrong file name onerrors (gcc 3.0, sparc-sun-solaris2.7)

Etan G. Cohen ecohen@angeles.com
Sat Jul 28 00:03:00 GMT 2001


Specifying a line number and file using the #line directive within a
template which causes an error results in the correct (new) line number but
the incorrect (old) filename.

File:

--------- start test.cpp
template <class T>
void doit(T arg) {
#line 20 "somefile.x"
        T local = args;
}

main() {
        double arg;
        doit(arg);
}
--------- end test.cpp

Output message:

g++ -v test.cpp
Reading specs from
/disk3/users/ecohen/GNU/INSTALL/sol2/lib/gcc-lib/sparc-sun-solaris2.7/3.0/sp
ecs
Configured with:
../gcc-3.0/configure --prefix=/disk3/users/ecohen/GNU/INSTALL/sol2 --with-gn
u-as --with-gnu-ld
Thread model: posix
gcc version 3.0

/disk3/users/ecohen/GNU/INSTALL/sol2/lib/gcc-lib/sparc-sun-solaris2.7/3.0/cc
1plus -v -D__GNUC__=3 -D__GNUC_MINOR__=0 -D__GNUC_PATCHLEVEL__=0 -Dsparc -Ds
un -Dunix -D__svr4__ -D__SVR4 -D__sparc__ -D__sun__ -D__unix__ -D__svr4__ -D
__SVR4 -D__sparc -D__sun -D__unix -Asystem=unix -Asystem=svr4 -D__NO_INLINE_
_ -D__STDC_HOSTED__=1 -D_XOPEN_SOURCE=500 -D_LARGEFILE_SOURCE=1 -D_LARGEFILE
64_SOURCE=1 -D__EXTENSIONS__ -D__GCC_NEW_VARARGS__ -Acpu=sparc -Amachine=spa
rc
test.cpp -D__GNUG__=3 -D__GXX_DEPRECATED -D__EXCEPTIONS -D__GXX_ABI_VERSION=
100 -quiet -dumpbase test.cpp -version -o /var/tmp/cc9bAsBh.s
GNU CPP version 3.0 (cpplib) (sparc)
GNU C++ version 3.0 (sparc-sun-solaris2.7)
        compiled by GNU C version 3.0.
ignoring nonexistent directory
"/disk3/users/ecohen/GNU/INSTALL/sol2/sparc-sun-solaris2.7/include"
#include "..." search starts here:
#include <...> search starts here:
 /disk3/users/ecohen/GNU/INSTALL/sol2/include/g++-v3
 /disk3/users/ecohen/GNU/INSTALL/sol2/include/g++-v3/sparc-sun-solaris2.7
 /disk3/users/ecohen/GNU/INSTALL/sol2/include/g++-v3/backward
 /usr/local/include

/disk3/users/ecohen/GNU/INSTALL/sol2/lib/gcc-lib/sparc-sun-solaris2.7/3.0/in
clude
 /usr/include
End of search list.
test.cpp: In function `void doit(T) [with T = double]':
somefile.x:25:   instantiated from here
test.cpp:20: `args' undeclared (first use this function)
test.cpp:20: (Each undeclared identifier is reported only once for each
   function it appears in.)

The message indicates "test.cpp:20" it should be "somefile.x:20" - the line
number is correct but the file name is incorrect.

Etan



More information about the Gcc-bugs mailing list