BelowCodeCompilation produces the following errors:
Compiling: Main. cpp
... Cc1wtyyu. S: receiver messages:
... Cc1wtyyu. S: 76: Error: symbol' _ z1gixadl_z1fveeevv 'is already defined
Code:
Void F ()
{
}
Typedef void (* f )();
Template <F _ F>
Void g ()
{
_ F ();
}
Int main ()
{
Void F ();
G <F> ();
{
Void F ();
G <F> ();
}
Return 0;
}
If the template is not instantiated, change G <F> () to F.
If a void F () declaration is removed, it will also be OK.
If the two instances are in the same code level, that is, the braces are removed.
The G <F> template instantiation is repeated. It seems that two F () declarations are treated as two different functions.
GCC version:
C:/Documents and Settings/jinqing> mingw32-g00000000.exe-V
Using built-in specs.
Collect_gccw.mingw32-gw.cmd.exe
Collect_lto_wrapper = D:/mingw/bin/../libexec/GCC/mingw32/4.5.0/Lto-wrapp
Target: mingw32
Configured with: ../gcc-4.5.0/configure -- enable-languages ages = C, C ++, Ada, fo
C, obj-C ++ -- disable-sjlj-exceptions -- with-dwarf2 -- enable-shared -- ena
MP -- disable-win32-registry -- enable-libstdcxx-Debug -- enable-version-S
Untime-Libs -- disable-werror -- Build = mingw32 -- prefix =/mingw
Thread model: Win32
GCC version 4.5.0 (GCC)
But VC can pass.
GCC errors can be confirmed.
However, some people found and raised the error many years ago, but it has not been fixed yet.
Bug 20357-multiply defined assembler symbols for template instantiations
http://gcc.gnu.org/bugzilla/show_bug.cgi? Id = 20357