From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 30147 invoked by alias); 13 Apr 2003 21:36:00 -0000 Mailing-List: contact gcc-prs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-prs-owner@gcc.gnu.org Received: (qmail 30128 invoked by uid 71); 13 Apr 2003 21:36:00 -0000 Resent-Date: 13 Apr 2003 21:36:00 -0000 Resent-Message-ID: <20030413213600.30127.qmail@sources.redhat.com> Resent-From: gcc-gnats@gcc.gnu.org (GNATS Filer) Resent-Cc: gcc-prs@gcc.gnu.org, gcc-bugs@gcc.gnu.org Resent-Reply-To: gcc-gnats@gcc.gnu.org, colby@alum.mit.edu Received: (qmail 29663 invoked by uid 48); 13 Apr 2003 21:34:34 -0000 Message-Id: <20030413213434.29662.qmail@sources.redhat.com> Date: Sun, 13 Apr 2003 21:36:00 -0000 From: colby@alum.mit.edu Reply-To: colby@alum.mit.edu To: gcc-gnats@gcc.gnu.org X-Send-Pr-Version: gnatsweb-2.9.3 (1.1.1.1.2.31) Subject: c++/10394: type inference gets confused during template instantiation X-SW-Source: 2003-04/txt/msg00583.txt.bz2 List-Id: >Number: 10394 >Category: c++ >Synopsis: type inference gets confused during template instantiation >Confidential: no >Severity: serious >Priority: medium >Responsible: unassigned >State: open >Class: rejects-legal >Submitter-Id: net >Arrival-Date: Sun Apr 13 21:36:00 UTC 2003 >Closed-Date: >Last-Modified: >Originator: Christopher Colby >Release: 3.2.2 >Organization: >Environment: Windows XP >Description: Enclosed is a small test program with class A templated by and class C templated by . C expects V to define a type V::X and instantiates A with that type. In C's constructor, there are two occurrences of A. The first occurrence correctly instantiates A with V::X, but the second occurrence erroneously instantiates A with V, thus causing the compiler to reject the program. Tweaking the enclosed demonstration program in almost any way makes this error disappear. For instance, line #1 compiles, but line #2 generates the type error: #1 C c(A()); #2 A a; C c(a); Also, removing the unused template argument from A's templated subclass B also eliminates the type error. >How-To-Repeat: Read the comments in main() before compiling the program. >Fix: >Release-Note: >Audit-Trail: >Unformatted: ----gnatsweb-attachment---- Content-Type: text/plain; name="test.cpp" Content-Disposition: inline; filename="test.cpp" template class A { public: template class B {}; void f(B) {} }; template class C { public: C(A a) { a.f(A::B()); } }; template class D { public: D(A* a) { a->f(A::B()); } }; class E { public: typedef int X; }; int main() { A a; // When you uncomment one of the following four lines... // C c(A()); // okay; see [1] below. // C c(a); // compile error; see [2] below. // D d(new A()); // compile error; see [3] below. // D d(&a); // compile error; see [4] below. } /* c:\cygwin\home\Christopher Colby\df>g++ -v g++ -v Reading specs from /usr/lib/gcc-lib/i686-pc-cygwin/3.2.2/specs Configured with: ../src/configure --enable-languages=c,c++,f77,java --enable-libgcj --enable-threads=posix --with-system-zlib --enable-nls --without-included-gettext --enable-interpreter --disable-sjlj-exceptions --disable-version-specific-runtime-libs --enable-shared --enable-haifa --prefix=/usr --exec-prefix=/usr --sysconfdir=/etc --libdir=/usr/lib --includedir=/nonexistent/include --libexecdir=/usr/sbin Thread model: posix gcc version 3.2.2 [1] c:\cygwin\home\Christopher Colby\df>g++ test.cpp g++ test.cpp [2] c:\cygwin\home\Christopher Colby\df>g++ test.cpp g++ test.cpp test.cpp: In constructor `C::C(A) [with V = E]': test.cpp:28: instantiated from here test.cpp:9: no matching function for call to `A::f(A::B)' test.cpp:4: candidates are: void A::f(A::B) [with T = int] [3] c:\cygwin\home\Christopher Colby\df>g++ test.cpp g++ test.cpp test.cpp: In constructor `D::D(A*) [with V = E]': test.cpp:29: instantiated from here test.cpp:14: no matching function for call to `A::f(A::B)' test.cpp:4: candidates are: void A::f(A::B) [with T = int] [4] c:\cygwin\home\Christopher Colby\df>g++ test.cpp g++ test.cpp test.cpp: In constructor `D::D(A*) [with V = E]': test.cpp:30: instantiated from here test.cpp:14: no matching function for call to `A::f(A::B)' test.cpp:4: candidates are: void A::f(A::B) [with T = int] */