This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/51385] New: Unnecessary instantiation converting to pointer to template class instance
- From: "hstong at ca dot ibm.com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Thu, 01 Dec 2011 23:32:23 +0000
- Subject: [Bug c++/51385] New: Unnecessary instantiation converting to pointer to template class instance
- Auto-submitted: auto-generated
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51385
Bug #: 51385
Summary: Unnecessary instantiation converting to pointer to
template class instance
Classification: Unclassified
Product: gcc
Version: 4.6.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: hstong@ca.ibm.com
Host: powerpc64-unknown-linux-gnu
Target: powerpc64-unknown-linux-gnu
The test case below uses SFINAE to check whether pointers to certain types
can be implicitly converted.
When a template class which is expensive to instantiate is used as the type
pointed-to by the target of the conversion, GCC takes a long time to compile.
I do not believe that the instantiation of the type in question is necessary to
determine the validity of the conversion (notwithstanding the non-normative
note
in 3.2 [basic.def.odr] paragraph 4). See Core Issue 50 regarding that note.
### Self-contained source:$ cat bb2.C
#ifndef SLOW
enum { Depth = 3 };
#else
enum { Depth = 15 };
#endif
template <unsigned N> struct NTmpl;
template <typename T, typename U, typename V = NTmpl<sizeof(T *)> >
struct PtrConvs {
enum { bad = 1 };
};
template <typename Target, typename Source>
struct PtrConvs<Target, Source, NTmpl<sizeof (*(Target **)0 = (Source *)0)> >;
template <unsigned N, typename T> struct FastGrowingTemplate;
template <typename T>
struct FastGrowingTemplate<0, T> { };
template <unsigned N, typename T>
struct FastGrowingTemplate :
FastGrowingTemplate<N - 1, const T *>,
FastGrowingTemplate<N - 1, volatile T *>
{ };
struct B { };
typedef char chk[1];
typedef char chk[PtrConvs<FastGrowingTemplate<Depth, short>, B>::bad];
### Time without -DSLOW:$ time /data/gcc/bin/g++-4.6.0 bb2.C -c
real 0m0.236s
user 0m0.007s
sys 0m0.006s
### Time with -DSLOW:$ time /data/gcc/bin/g++-4.6.0 bb2.C -c -DSLOW
real 1m45.826s
user 1m42.505s
sys 0m0.312s
### g++ -v output:$ /data/gcc/bin/g++-4.6.0 -v
Using built-in specs.
COLLECT_GCC=/data/gcc/bin/g++-4.6.0
COLLECT_LTO_WRAPPER=/data/gcc/libexec/gcc/powerpc64-unknown-linux-gnu/4.6.0/lto-wrapper
Target: powerpc64-unknown-linux-gnu
Configured with: ./configure --prefix=/data/gcc --program-suffix=-4.6.0
--disable-libssp --disable-libgcj --enable-version-specific-runtime-libs
--with-cpu=default32 --enable-secureplt --with-long-double-128 --enable-shared
--enable-__cxa_atexit --enable-threads=posix --enable-languages=c,c++,fortran
--with-gmp=/usr/local
Thread model: posix
gcc version 4.6.0 (GCC)