Bug 39270 - Explicit instantiation rejected
Summary: Explicit instantiation rejected
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.3.1
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: rejects-valid
: 104193 (view as bug list)
Depends on:
Blocks: 102184
  Show dependency treegraph
 
Reported: 2009-02-23 06:56 UTC by Jaroslav Hajek
Modified: 2022-01-24 18:20 UTC (History)
6 users (show)

See Also:
Host:
Target: x86_64-suse-linux
Build:
Known to work:
Known to fail: 3.3.6
Last reconfirmed: 2021-07-26 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jaroslav Hajek 2009-02-23 06:56:18 UTC
Hello.

The following does not compile:

---------

class A
{
public:
 class B {};
 template <class T, class X> void x(X a) {}
 template <class T> void x(int a);
};

template <class T>
void A::x (int a)
{ }

template void A::x<A::B> (int a);

----------

Namely, the explicit instantiation on the last line is rejected with the error:
test.cc:13: error: ambiguous template specialization ‘x<A::B>’ for ‘void A::x(int)’

i.e. not even recognized as an explicit instantiation.
Implicit instantiation seems to work fine.

cheers

gcc config:
Configured with: ../configure --prefix=/usr --with-local-prefix=/usr/local --infodir=/usr/share/info --mandir=/usr/share/man --libdir=/usr/lib64 --libexecdir=/usr/lib64 --enable-languages=c,c++,objc,fortran,obj-c++,java,ada --enable-checking=release --with-gxx-include-dir=/usr/include/c++/4.3 --enable-ssp --disable-libssp --with-bugurl=http://bugs.opensuse.org/ --with-pkgversion='SUSE Linux' --disable-libgcj --with-slibdir=/lib64 --with-system-zlib --enable-__cxa_atexit --enable-libstdcxx-allocator=new --disable-libstdcxx-pch --program-suffix=-4.3 --enable-version-specific-runtime-libs --enable-linux-futex --without-system-libunwind --with-cpu=generic --build=x86_64-suse-linux
Thread model: posix
gcc version 4.3.1 20080507 (prerelease) [gcc-4_3-branch revision 135036] (SUSE Linux)
Comment 1 Richard Biener 2009-02-23 09:56:29 UTC
Confirmed.  Fails at least since GCC 3.3.
Comment 2 Paolo Carlini 2014-06-26 10:38:45 UTC
Mine.
Comment 3 Patrick Palka 2021-09-16 16:30:23 UTC
Slightly more reduced rejects-valid testcase:

template<class T, class U>
void f(U); // #1

template<class T>
void f(int) { } // #2

template void f<char>(int);


more_specialized_inst is unable to determine that #2 is more specialized than #1.  Perhaps we should be passing the explicitly specified template arguments to get_bindings?  But that ends up breaking gcc/testsuite/g++.old-deja/g++.pt/explicit22.C among others..
Comment 4 Patrick Palka 2021-09-16 16:36:18 UTC
PR102184 is probably due to the same underlying bug
Comment 5 Patrick Palka 2022-01-23 14:56:45 UTC
*** Bug 104193 has been marked as a duplicate of this bug. ***
Comment 6 Andrew Pinski 2022-01-24 18:19:39 UTC
*** Bug 64063 has been marked as a duplicate of this bug. ***
Comment 7 Andrew Pinski 2022-01-24 18:19:45 UTC
*** Bug 104204 has been marked as a duplicate of this bug. ***