From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23002 invoked by alias); 4 Jun 2012 17:13:36 -0000 Received: (qmail 22987 invoked by uid 22791); 4 Jun 2012 17:13:33 -0000 X-SWARE-Spam-Status: No, hits=-4.3 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00,KHOP_THREADED 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; Mon, 04 Jun 2012 17:13:20 +0000 From: "keean@fry-it.com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/53573] template type dependent name resolution broken Date: Mon, 04 Jun 2012 17:13:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Keywords: X-Bugzilla-Severity: major X-Bugzilla-Who: keean@fry-it.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: In-Reply-To: References: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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: 2012-06/txt/msg00192.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D53573 --- Comment #5 from Keean Schupke 2012-06-04 17:13:18 UT= C --- The following program will apparently compile correctly, but will silently produce incorrect results at runtime: #include char g(char x) { return x - 1; } template T f(T t) { return g(t); } int g(int x) { return x + 1; } main() { int x(1); int y(f(x)); std::cout << y << "\n"; int z(f(x)); std::cout << z << "\n"; } This should print "2 2" but prints "0 0". Interestingly it also produces incorrect results with gcc-4.6.3 and gcc-4.5.3. However the code below (whi= ch does not compile on gcc-4.7.0 does produce the correct results on gcc-4.6.3= and gcc-4.5.3: #include template T f(T t) { return g(t); } char g(char x) { return x - 1; } int g(int x) { return x + 1; } main() { int x(1); int y(f(x)); std::cout << y << "\n"; int z(f(x)); std::cout << z << "\n"; } So it looks like earlier versions of GCC relied on 'g' being undefined at t= he point of definition to defer binding until instantiation instead of looking= for dependence on a template parameter. gcc-4.7.0 does not seem to do either. One more example: #include class A {}; A g(A x) { return x; } template T f(T t) { return g(t); } int g(int x) { return x + 1; } main() { int x(1); int y(f(x)); std::cout << y << "\n"; int z(f(x)); std::cout << z << "\n"; } generates the following compile error: test.cpp: In function =E2=80=98T f(T) [with T =3D int]=E2=80=99: test.cpp:35:11: instantiated from here test.cpp:26:12: error: could not convert =E2=80=98t=E2=80=99 from =E2=80=98= int=E2=80=99 to =E2=80=98A=E2=80=99