User account creation filtered due to spam.

Bug 47544 - [C++0x] linker does not find =default constructor for explicitly instantiated template
Summary: [C++0x] linker does not find =default constructor for explicitly instantiated...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.5.2
: P3 normal
Target Milestone: 4.6.1
Assignee: Jason Merrill
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-01-30 15:25 UTC by Trevor Spiteri
Modified: 2011-05-25 01:23 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2011-05-22 19:41:14


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Trevor Spiteri 2011-01-30 15:25:44 UTC
When compiling the file a.cpp below, the linker does not find the constructor of an explicitly instantiated template if the constructor is defined using = default.


$ cat a.cpp
template <typename T>
struct s {
	s();
};

extern template struct s<int>;

template <typename T>
s<T>::s() = default;
//s<T>::s() {} // gives no error

template struct s<int>;

int main()
{
	s<int> a;
}


$ g++-4.5 -std=c++0x a.cpp
/tmp/cc4PTe2q.o(.text+0x10): In function `main':
: undefined reference to `s<int>::s()'
collect2: ld returned 1 exit status


$ g++-4.5 -v
Using built-in specs.
COLLECT_GCC=g++-4.5
COLLECT_LTO_WRAPPER=/home/eeyts/root/libexec/gcc/x86_64-unknown-linux-gnu/4.5.2/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ../gcc-4.5.2/configure --prefix=/home/eeyts/root --disable-shared --enable-threads=posix --enable-__cxa_atexit --enable-libgomp --disable-libunwind-exceptions --enable-languages=c,c++,ada --with-gmp=/home/eeyts/root --with-mpfr=/home/eeyts/root --with-mpc=/home/eeyts/root --with-host-libstdcxx=/usr/lib64/libstdc++.so.6 --with-ppl=/home/eeyts/root --with-cloog=/home/eeyts/root --with-libelf=/home/eeyts/root --program-suffix=-4.5
Thread model: posix
gcc version 4.5.2 (GCC) 


$ ld -v
GNU ld version 2.15.92.0.2 20040927
Comment 1 Jason Merrill 2011-05-23 15:32:23 UTC
Author: jason
Date: Mon May 23 15:32:19 2011
New Revision: 174071

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=174071
Log:
	PR c++/47544
	* pt.c (instantiate_decl): Handle =default.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/defaulted27.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/pt.c
    trunk/gcc/testsuite/ChangeLog
Comment 2 Jason Merrill 2011-05-25 01:08:19 UTC
Author: jason
Date: Wed May 25 01:08:16 2011
New Revision: 174159

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=174159
Log:
	PR c++/47544
	* pt.c (instantiate_decl): Handle =default.

Added:
    branches/gcc-4_6-branch/gcc/testsuite/g++.dg/cpp0x/defaulted27.C
Modified:
    branches/gcc-4_6-branch/gcc/cp/ChangeLog
    branches/gcc-4_6-branch/gcc/cp/pt.c
    branches/gcc-4_6-branch/gcc/testsuite/ChangeLog
Comment 3 Jason Merrill 2011-05-25 01:23:24 UTC
Fixed for 4.6.1.