From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15379 invoked by alias); 1 Dec 2011 23:32:42 -0000 Received: (qmail 15369 invoked by uid 22791); 1 Dec 2011 23:32:42 -0000 X-SWARE-Spam-Status: No, hits=-2.8 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00,TW_CX,TW_GC,TW_NV X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 01 Dec 2011 23:32:27 +0000 From: "hstong at ca dot ibm.com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/51385] New: Unnecessary instantiation converting to pointer to template class instance Date: Thu, 01 Dec 2011 23:32:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: hstong at ca dot ibm.com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2011-12/txt/msg00124.txt.bz2 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 struct NTmpl; template > struct PtrConvs { enum { bad = 1 }; }; template struct PtrConvs >; template struct FastGrowingTemplate; template struct FastGrowingTemplate<0, T> { }; template struct FastGrowingTemplate : FastGrowingTemplate, FastGrowingTemplate { }; struct B { }; typedef char chk[1]; typedef char chk[PtrConvs, 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)