https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61808
Bug ID: 61808
Summary: Linking error with explicit template instantiation and
default template param
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: gael.guennebaud at gmail dot com
Created attachment 33124
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=33124&action=edit
Tarball of the files to reproduce the issue.
Here is small example which fails to compile with gcc but works well with other
compilers. Compiling the files with:
$ g++ func.cpp main.cpp
produces the following error:
Undefined symbols for architecture x86_64:
"void foo<2>(Bar::Matrix<2, (2)+((int)((Bar::._1)0))>&)", referenced from:
_main in ccZW4Wal.o
You can workaround the issue doing either:
1 - In main.cpp, line 3: remove the declaration"enum { fifi = sizeof(int) };"
2 - In main.cpp, move the above declaration after including func.h
3 - In either func.h or main.cpp, replace one (or both) anonymous enum
declaration with a non-anonymous one.
4 - Move the explicit template declaration from func.cpp to main.cpp.
A real-word use case is described there:
http://stackoverflow.com/questions/24730981/undefined-reference-error-from-gcc-using-a-template-with-a-stdvector-and-an-ei