http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57728

            Bug ID: 57728
           Summary: Explicit template instantiation with defaulted method
                    causes missing symbol
           Product: gcc
           Version: 4.8.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: bmerry at gmail dot com

Created attachment 30378
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=30378&action=edit
Minimal test case

I don't claim to fully understand all the intricies of C++11, but the following
smells fishy to me. I am using a combination of features:
1. The = default syntax to restore implicit constructors/assignments that were
otherwise hidden (e.g. default constructor when there are no user-defined
constructors), in a templated class.
2. "extern template" in the header to suppress instantiation of a specific
instance, with an explicit instantiation in one translation unit.

In some cases (I assume depending on compiler eliding) this causes a link-time
error for the defaulted constructor. I have attached a minimal test case. I
don't know whether there is supposed to be a symbol or whether the compiler is
supposed to inline the default implementation, but currently there is a
mismatch.

System information: Ubuntu 12.04 with
gcc version 4.8.1 (Ubuntu 4.8.1-2ubuntu1~12.04) 

Output (there's a more detailed log in the attachment with -v -save-temps):
g++-4.8 -std=c++11 -c defaulted.cpp
g++-4.8 -std=c++11 -c impl.cpp
g++-4.8 -std=c++11 -o defaulted defaulted.o impl.o
defaulted.o: In function `main':
defaulted.cpp:(.text+0x10): undefined reference to `A<int>::A()'
collect2: error: ld returned 1 exit status
make: *** [defaulted] Error 1

Reply via email to