https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65133 Bug ID: 65133 Summary: [C++11] Result type deduction proceeds even though argument deduction fails Product: gcc Version: 4.9.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: mbianco at cscs dot ch GCC 4.8.0 to 4.9.0 fails in employing SFINAE to find the proper implementation when infinite template recursion is hit. ICPC (15) and CLANG++ (3.7) compile and run the code correctly. #STANDALONE SOURCE #include #include template struct count { using type = typename count::type; }; template <> struct count<0> { using type = void; }; template auto foo(typename std::enable_if<(I>=0)>::type * = nullptr) -> typename count::type /* Substituting count::type with void would make the code to compile.*/ { std::cout << "I>=0" << std::endl; } // Specialization #2 template void foo(typename std::enable_if<(I<0)>::type * = nullptr) { std::cout << "I<0" << std::endl; } int main() { foo<2>(); // This Works fine foo<-1>(); // This should go the specialization #2 but GCC fails since it goes into counting down 900 times without resolution return 0; } ### COMPILER INVOCATION: g++ -std=c++11 -c main.cpp ### EXPECTED OUTPUT: Successful compile. ### ACTUAL OUTPUT: main.cpp:7:43: error: template instantiation depth exceeds maximum of 900 (use -ftemplate-depth= to increase the maximum) instantiating ‘struct count<-900>’ using type = typename count::type; ^ main.cpp:7:43: recursively required from ‘struct count<-2>’ main.cpp:7:43: required from ‘struct count<-1>’ main.cpp:18:6: required by substitution of ‘template typename count::type foo(typename std::enable_if<(I >= 0)>::type*) [with int I = -1]’ main.cpp:35:13: required from here main.cpp:7:43: error: invalid use of incomplete type ‘struct count<-900>’ main.cpp:5:8: error: declaration of ‘struct count<-900>’ struct count ^ ### g++ -v OUTPUT: Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/apps/dom/gcc/4.9.0/libexec/gcc/x86_64-unknown-linux-gnu/4.9.0/lto-wrapper Target: x86_64-unknown-linux-gnu Configured with: ./configure --prefix=/apps/dom/gcc/4.9.0 --enable-languages=c,c++,fortran --with-mpfr=/apps/dom/gnu/mpfr/3.1.2 --with-mpc=/apps/dom/gnu/mpc/1.0.2 --with-gmp=/apps/dom/gnu/gmp/5.1.3 --with-isl=/apps/dom/gnu/isl/0.12.2 --with-cloog=/apps/dom/gnu/cloog/0.18.1 Thread model: posix gcc version 4.9.0 (GCC) >From gcc-bugs-return-477892-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Fri Feb 20 09:21:05 2015 Return-Path: Delivered-To: listarch-gcc-bugs@gcc.gnu.org Received: (qmail 15493 invoked by alias); 20 Feb 2015 09:21:04 -0000 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 Delivered-To: mailing list gcc-bugs@gcc.gnu.org Received: (qmail 15205 invoked by uid 48); 20 Feb 2015 09:21:00 -0000 From: "e29253 at jp dot ibm.com" To: gcc-bugs@gcc.gnu.org Subject: [Bug go/65134] New: gccgo ignores the attribute "constructor" in a subdirectory Date: Fri, 20 Feb 2015 09:21:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: go X-Bugzilla-Version: 5.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: e29253 at jp dot ibm.com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: ian at airs dot com X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter cc attachments.created Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2015-02/txt/msg02225.txt.bz2 Content-length: 1462 https://gcc.gnu.org/bugzilla/show_bug.cgi?ide134 Bug ID: 65134 Summary: gccgo ignores the attribute "constructor" in a subdirectory Product: gcc Version: 5.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: go Assignee: ian at airs dot com Reporter: e29253 at jp dot ibm.com CC: cmang at google dot com Created attachment 34813 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id4813&actioníit Example to reproduce the constructor problem Gccgo ignores a C-function with the "constructor" attribute in a subdirectory. In the attached example, gc executes a C-function init() in sub.go before a Go function main(), but gccgo does not: ~/example$ export GOPATH=$(pwd) ~/example$ /usr/local/go/bin/go version go version go1.4.2 linux/amd64 ~/example$ /usr/local/go/bin/go run src/main/main.go Hello from constructor Hello from main ~/example$ export LD_LIBRARY_PATH=/usr/local/gccgo/lib64:$LD_LIBRARY_PATH ~/example$ /usr/local/gccgo/bin/go version go version gccgo (GCC) 5.0.0 20150115 (experimental) linux/amd64 ~/example$ /usr/local/gccgo/bin/go run src/main/main.go Hello from main ~/example$ It seems this difference is due to that gccgo cannot detect a function with the constructor attribute in an archived objects created in a subdirectory. Is there any workaround to avoid this problem?