[Bug c++/50044] New: Attributes for explicit template instantiation are ignored after an implicit template instantiation occurred.
ml@convergent-it.at
gcc-bugzilla@gcc.gnu.org
Thu Aug 11 13:36:00 GMT 2011
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50044
Bug #: 50044
Summary: Attributes for explicit template instantiation are
ignored after an implicit template instantiation
occurred.
Classification: Unclassified
Product: gcc
Version: 4.5.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: ml@convergent-it.at
Created attachment 24976
--> http://gcc.gnu.org/bugzilla/attachment.cgi?id=24976
Preprocessed file which shows the main problem.
Information about the used GCC:
Using built-in specs.
COLLECT_GCC=i686-mingw32-gcc
COLLECT_LTO_WRAPPER=/home/martin/mingw-4.5.2-new/install-i686-pc-linux-gnu/libexec/gcc/i686-mingw32/4.5.2/lto-wrapper
Target: i686-mingw32
Configured with: ../configure --build=i686-pc-linux-gnu
--host=i686-pc-linux-gnu --target=i686-mingw32
--prefix=/home/martin/mingw-4.5.2-new/install-i686-pc-linux-gnu
--with-gmp=/home/martin/mingw-4.5.2-new/install-i686-pc-linux-gnu
--with-mpfr=/home/martin/mingw-4.5.2-new/install-i686-pc-linux-gnu
--with-mpc=/home/martin/mingw-4.5.2-new/install-i686-pc-linux-gnu
--with-ppl=/home/martin/mingw-4.5.2-new/install-i686-pc-linux-gnu
--with-cloog=/home/martin/mingw-4.5.2-new/install-i686-pc-linux-gnu
--enable-threads=win32 --enable-tls --enable-languages=c,c++
--with-sysroot=/home/martin/mingw-4.5.2-new/install-i686-pc-linux-gnu/i686-mingw32
--disable-win32-registry --enable-sjlj-exceptions --disable-libstdcxx-pch
--with-host-libstdcxx='-lstdc++ -lsupc++'
Thread model: win32
gcc version 4.5.2 (GCC)
Command line that triggers the problem:
i686-mingw32-g++ -Wall -c -o A.cpp.obj A.cpp.i
Output of GCC:
A.cpp:8:43: warning: type attributes ignored after type is already defined
Summary:
Attributes for explicit template instantiation are ignored after an implicit
template instantiation occurred.
Description:
I have a problem with explicit template instantiation and exporting it's
symbols into a DLL. The file which triggers the problem is attached - as
requested in preprocessed form (A.cpp.i) - although I will also attach the
whole project for completeness (better for discussion, and to be able to see
linker errors).
It seems, that A<int> gets implicitly instantiated (or the type is defined - I
do not know the correct nomenclature) in the create function. Then when the
compiler sees the explicit instantiation, it prints the warning that it ignores
the dllexport attribute, and thus the symbols for A<int> are not exported.
That's why I receive the linker error for the application later. If the create
function had not been in the code, then everything would work fine.
For completeness the output of make looks like this:
i686-mingw32-g++ -Wall -shared -o dll.dll -DEXPORTS A.cpp
A.cpp:8:26: warning: type attributes ignored after type is already defined
i686-mingw32-g++ -Wall -o app.exe main.cpp dll.dll
/tmp/cc87EyrC.o:main.cpp:(.text+0x4e): undefined reference to `A<int>::A()'
/tmp/cc87EyrC.o:main.cpp:(.text+0x62): undefined reference to
`A<int>::doSomething()'
/tmp/cc87EyrC.o:main.cpp:(.rdata$_ZTV1AIiE[vtable for A<int>]+0x10):
undefined reference to `A<int>::doSomething()'
collect2: ld returned 1 exit status
In my opinion it makes sense to give attributes on an explicit template
instantiation precedence. It seems that attributes can only be assigned to the
type, when the compiler needs it the first time. This can be accomplished by
adding
extern template class INTERFACE A<int>; //C++11
to A.h - but which should not be needed actually.
In this case, if I run make, then I still receive the warning, but the
dllexport attribute is applied. The output of make look now like:
i686-mingw32-g++ -Wall -shared -o dll.dll -DEXPORTS -DUSE_EXTERN_TEMPLATE
A.cpp
A.cpp:8:26: warning: type attributes ignored after type is already defined
i686-mingw32-g++ -Wall -o app.exe -DUSE_EXTERN_TEMPLATE main.cpp dll.dll
/tmp/ccv8Knzo.o:main.cpp:(.text+0x67): undefined reference to `typeinfo for
A<int>'
collect2: ld returned 1 exit status
make: *** [app.exe] Error 1
So actually I see two problems here:
- The attributes on the explicit instantiation should have precedence.
- When using "extern template..." there is something wrong with exporting the
symbols for the typeinfo (i686-mingw32-nm shows that they are in the dll, but
it seems that they are not exported).
Thank you for your help,
Martin Lederhilger
More information about the Gcc-bugs
mailing list