public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/51385] New: Unnecessary instantiation converting to pointer to template class instance
@ 2011-12-01 23:32 hstong at ca dot ibm.com
2011-12-02 10:36 ` [Bug c++/51385] " redi at gcc dot gnu.org
` (5 more replies)
0 siblings, 6 replies; 7+ messages in thread
From: hstong at ca dot ibm.com @ 2011-12-01 23:32 UTC (permalink / raw)
To: gcc-bugs
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)
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/51385] Unnecessary instantiation converting to pointer to template class instance
2011-12-01 23:32 [Bug c++/51385] New: Unnecessary instantiation converting to pointer to template class instance hstong at ca dot ibm.com
@ 2011-12-02 10:36 ` redi at gcc dot gnu.org
2011-12-02 10:43 ` paolo.carlini at oracle dot com
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: redi at gcc dot gnu.org @ 2011-12-02 10:36 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51385
--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> 2011-12-02 10:36:14 UTC ---
Here's a version which isn't a compile-time-hog but demonstrates the
unnecessary instantiation with a static_assert (so needs -std=c++11)
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<typename T> struct test { static const bool value = true; };
template<> struct test<short> { static const bool value = false; };
template <typename T>
struct FussyTemplate
{
static_assert( test<T>::value, "not short" );
};
struct B { };
typedef char chk[1];
typedef char chk[PtrConvs<FussyTemplate<short>, B>::bad];
EFG and Clang compile this happily, without instantiating FussyTemplate<short>
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/51385] Unnecessary instantiation converting to pointer to template class instance
2011-12-01 23:32 [Bug c++/51385] New: Unnecessary instantiation converting to pointer to template class instance hstong at ca dot ibm.com
2011-12-02 10:36 ` [Bug c++/51385] " redi at gcc dot gnu.org
@ 2011-12-02 10:43 ` paolo.carlini at oracle dot com
2011-12-02 10:48 ` redi at gcc dot gnu.org
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: paolo.carlini at oracle dot com @ 2011-12-02 10:43 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51385
Paolo Carlini <paolo.carlini at oracle dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Last reconfirmed| |2011-12-02
CC| |jason at gcc dot gnu.org
Ever Confirmed|0 |1
--- Comment #2 from Paolo Carlini <paolo.carlini at oracle dot com> 2011-12-02 10:42:28 UTC ---
Let's add Jason in CC, definitely not a regression, but the issue seems pretty
interesting, eh.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/51385] Unnecessary instantiation converting to pointer to template class instance
2011-12-01 23:32 [Bug c++/51385] New: Unnecessary instantiation converting to pointer to template class instance hstong at ca dot ibm.com
2011-12-02 10:36 ` [Bug c++/51385] " redi at gcc dot gnu.org
2011-12-02 10:43 ` paolo.carlini at oracle dot com
@ 2011-12-02 10:48 ` redi at gcc dot gnu.org
2014-09-29 8:55 ` paolo.carlini at oracle dot com
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: redi at gcc dot gnu.org @ 2011-12-02 10:48 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51385
--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> 2011-12-02 10:47:45 UTC ---
Interestingly G++ is happy to not instantiate the template when it's not
possible to, i.e. making this change and defining -DINCOMPLETE allows it to
compile:
template <typename T>
struct FussyTemplate
#ifndef INCOMPLETE
{
static_assert( test<T>::value, "not short" );
}
#endif
;
But if the class template definition is available it gets instantiated.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/51385] Unnecessary instantiation converting to pointer to template class instance
2011-12-01 23:32 [Bug c++/51385] New: Unnecessary instantiation converting to pointer to template class instance hstong at ca dot ibm.com
` (2 preceding siblings ...)
2011-12-02 10:48 ` redi at gcc dot gnu.org
@ 2014-09-29 8:55 ` paolo.carlini at oracle dot com
2014-09-29 9:07 ` paolo at gcc dot gnu.org
2014-09-29 9:08 ` paolo.carlini at oracle dot com
5 siblings, 0 replies; 7+ messages in thread
From: paolo.carlini at oracle dot com @ 2014-09-29 8:55 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=51385
--- Comment #4 from Paolo Carlini <paolo.carlini at oracle dot com> ---
This is fixed in 4.9.0, I'm adding the testcase and closing the bug.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/51385] Unnecessary instantiation converting to pointer to template class instance
2011-12-01 23:32 [Bug c++/51385] New: Unnecessary instantiation converting to pointer to template class instance hstong at ca dot ibm.com
` (3 preceding siblings ...)
2014-09-29 8:55 ` paolo.carlini at oracle dot com
@ 2014-09-29 9:07 ` paolo at gcc dot gnu.org
2014-09-29 9:08 ` paolo.carlini at oracle dot com
5 siblings, 0 replies; 7+ messages in thread
From: paolo at gcc dot gnu.org @ 2014-09-29 9:07 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=51385
--- Comment #5 from paolo at gcc dot gnu.org <paolo at gcc dot gnu.org> ---
Author: paolo
Date: Mon Sep 29 09:06:31 2014
New Revision: 215680
URL: https://gcc.gnu.org/viewcvs?rev=215680&root=gcc&view=rev
Log:
2014-09-29 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/51385
* g++.dg/template/pr51385.C: New.
Added:
trunk/gcc/testsuite/g++.dg/template/pr51385.C
Modified:
trunk/gcc/testsuite/ChangeLog
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/51385] Unnecessary instantiation converting to pointer to template class instance
2011-12-01 23:32 [Bug c++/51385] New: Unnecessary instantiation converting to pointer to template class instance hstong at ca dot ibm.com
` (4 preceding siblings ...)
2014-09-29 9:07 ` paolo at gcc dot gnu.org
@ 2014-09-29 9:08 ` paolo.carlini at oracle dot com
5 siblings, 0 replies; 7+ messages in thread
From: paolo.carlini at oracle dot com @ 2014-09-29 9:08 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=51385
Paolo Carlini <paolo.carlini at oracle dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution|--- |FIXED
Target Milestone|--- |4.9.0
--- Comment #6 from Paolo Carlini <paolo.carlini at oracle dot com> ---
Done.
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2014-09-29 9:08 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-12-01 23:32 [Bug c++/51385] New: Unnecessary instantiation converting to pointer to template class instance hstong at ca dot ibm.com
2011-12-02 10:36 ` [Bug c++/51385] " redi at gcc dot gnu.org
2011-12-02 10:43 ` paolo.carlini at oracle dot com
2011-12-02 10:48 ` redi at gcc dot gnu.org
2014-09-29 8:55 ` paolo.carlini at oracle dot com
2014-09-29 9:07 ` paolo at gcc dot gnu.org
2014-09-29 9:08 ` paolo.carlini at oracle dot com
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).