Bug 9420 - [3.2/3.3/3.4 regression] incomplete type incorrectly reported
Summary: [3.2/3.3/3.4 regression] incomplete type incorrectly reported
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 3.2.2
: P3 normal
Target Milestone: ---
Assignee: Jason Merrill
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2003-01-23 16:26 UTC by mdorey
Modified: 2004-01-17 04:22 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description mdorey 2003-01-23 16:26:00 UTC
enum Bools
{
  False
};

template<class T>
struct Container
{
  static const int a = False < false;
};

template<class CharType>
class BasicString
{
  Container<int> b;
};

struct InplaceString
{
  InplaceString(BasicString<int>);
};
int operator<(int, InplaceString);

Container<int> c;

Produces:

Reading specs from /usr/lib/gcc-lib/i386-linux/3.2.2/specs
Configured with: ../src/configure -v --enable-languages=c,c++,java,f77,proto,pascal,objc,ada --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-gxx-include-dir=/usr/include/c++/3.2 --enable-shared --with-system-zlib --enable-nls --without-included-gettext --enable-__cxa_atexit --enable-clocale=gnu --enable-java-gc=boehm --enable-objc-gc i386-linux
Thread model: posix
gcc version 3.2.2 20030109 (Debian prerelease)
 /usr/lib/gcc-lib/i386-linux/3.2.2/cc1plus -v -D__GNUC__=3 -D__GNUC_MINOR__=2 -D__GNUC_PATCHLEVEL__=2 -D__GXX_ABI_VERSION=102 -D__ELF__ -Dunix -D__gnu_linux__ -Dlinux -D__ELF__ -D__unix__ -D__gnu_linux__ -D__linux__ -D__unix -D__linux -Asystem=posix -D__NO_INLINE__ -D__STDC_HOSTED__=1 -D_GNU_SOURCE -Acpu=i386 -Amachine=i386 -Di386 -D__i386 -D__i386__ -D__tune_i386__ Whole.cpp -D__GNUG__=3 -D__DEPRECATED -D__EXCEPTIONS -quiet -dumpbase Whole.cpp -W -Wall -pedantic -version -o /tmp/ccWxcPJh.s
GNU CPP version 3.2.2 20030109 (Debian prerelease) (cpplib) (i386 Linux/ELF)
GNU C++ version 3.2.2 20030109 (Debian prerelease) (i386-linux)
        compiled by GNU C version 3.2.2 20030109 (Debian prerelease).
ignoring nonexistent directory "/usr/i386-linux/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/include/c++/3.2
 /usr/include/c++/3.2/i386-linux
 /usr/include/c++/3.2/backward
 /usr/local/include
 /usr/lib/gcc-lib/i386-linux/3.2.2/include
 /usr/include
End of search list.
Whole.cpp: In instantiation of `BasicString<int>':
Whole.cpp:10:   instantiated from `Container<int>'
Whole.cpp:25:   instantiated from here
Whole.cpp:16: `BasicString<CharType>::b' has incomplete type
Whole.cpp:9: declaration of `struct Container<int>'

When compiled with:

gcc -v -c -W -Wall -pedantic Whole.cpp

Release:
GNU C version 3.2.2 20030109 (Debian prerelease)

Environment:
Linux trevithick 2.4.16 #2 Mon Dec 10 15:54:50 GMT 2001 i686 unknown unknown GNU/Linux
Comment 1 Wolfgang Bangerth 2003-01-23 17:13:55 UTC
State-Changed-From-To: open->analyzed
State-Changed-Why: True. Very weird problem:
    --------------------------
    enum { E };
    
    template <typename T> struct A {
      static const int a = (E < 0);
    };
    
    template <typename T> class B {
      A<int> b;
    };
    
    struct C {
      C(B<int>);
    };
    
    int operator<(C, C);
    
    A<int> c;
    ----------------------------
    Changing any bit of the code makes the bug go away (e.g.
    changing op< to function foo). Used to work with 2.95, but
    does no longer with 3.2.2 and 3.3 (just accidentially
    ruined my 3.4 installation, but likely to show same problem).
    
    W.
Comment 2 Nathan Sidwell 2003-01-23 18:20:31 UTC
Responsible-Changed-From-To: unassigned->nathan
Responsible-Changed-Why: fixing
Comment 3 Jason Merrill 2003-03-13 19:14:35 UTC
Responsible-Changed-From-To: nathan->jason
Responsible-Changed-Why: theft
Comment 4 Jason Merrill 2003-03-13 19:29:34 UTC
State-Changed-From-To: analyzed->open
State-Changed-Why: an->an
Comment 5 Jason Merrill 2003-03-13 20:26:21 UTC
State-Changed-From-To: open->analyzed
State-Changed-Why: Core issues 63 and 212 are relevant here.  [temp.inst] says
    
    A class template specialization is implicitly instantiated if the class type is used in a context that requires a completely-defined object type or if the completeness of the class type might affect the semantics of the program. [Note: in particular, if the semantics of an expression depend on the member or base class lists of a class template specialization, the class template specialization is implicitly generated. For instance, deleting a pointer to class type depends on whether or not the class declares a destructor, and conversion between pointer to class types depends on the inheritance relationship between the two classes involved. ]
    ...
    If the overload resolution process can determine the correct function to call without instantiating a class
    template definition, it is unspecified whether that instantiation actually takes place.
    
    In this case, we need to do overload resolution for E<0,
    because E is an enum.  We consider op<(C,C) as a candidate.
    To test whether or not it is a valid candidate, we need to
    determine whether or not there is a conversion from E (and
    int) to C.
    
    Hmm...
    
    No, I'm making this harder than it actually is.  The bug is
    that we're instantiating B<int> when we don't need to,
    because we can't use a user-defined conversion from E (or int)
    to B<int>, because we're already considering a UDC to C.
    This should be simple to fix.
Comment 6 Jason Merrill 2003-03-13 21:39:40 UTC
From: jason@gcc.gnu.org
To: gcc-gnats@gcc.gnu.org
Cc:  
Subject: c++/9420
Date: 13 Mar 2003 21:39:40 -0000

 CVSROOT:	/cvs/gcc
 Module name:	gcc
 Changes by:	jason@gcc.gnu.org	2003-03-13 21:39:40
 
 Modified files:
 	gcc/cp         : ChangeLog call.c search.c 
 
 Log message:
 	PR c++/9420
 	* search.c (lookup_conversions): Call complete_type here.
 	* call.c (implicit_conversion): Not here.
 
 Patches:
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&r1=1.3271&r2=1.3272
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/call.c.diff?cvsroot=gcc&r1=1.368&r2=1.369
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/search.c.diff?cvsroot=gcc&r1=1.256&r2=1.257
 

Comment 7 Jason Merrill 2003-03-13 21:40:34 UTC
From: jason@gcc.gnu.org
To: gcc-gnats@gcc.gnu.org
Cc:  
Subject: c++/9420
Date: 13 Mar 2003 21:40:34 -0000

 CVSROOT:	/cvs/gcc
 Module name:	gcc
 Branch: 	gcc-3_3-branch
 Changes by:	jason@gcc.gnu.org	2003-03-13 21:40:34
 
 Modified files:
 	gcc/cp         : ChangeLog call.c search.c 
 
 Log message:
 	PR c++/9420
 	* search.c (lookup_conversions): Call complete_type here.
 	* call.c (implicit_conversion): Not here.
 
 Patches:
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.3076.2.83&r2=1.3076.2.84
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/call.c.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.341.2.13&r2=1.341.2.14
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/search.c.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.243.2.2&r2=1.243.2.3
 

Comment 8 Jason Merrill 2003-03-13 21:41:38 UTC
From: jason@gcc.gnu.org
To: gcc-gnats@gcc.gnu.org
Cc:  
Subject: c++/9420
Date: 13 Mar 2003 21:41:38 -0000

 CVSROOT:	/cvs/gcc
 Module name:	gcc
 Branch: 	gcc-3_2-branch
 Changes by:	jason@gcc.gnu.org	2003-03-13 21:41:38
 
 Modified files:
 	gcc/cp         : ChangeLog call.c search.c 
 
 Log message:
 	PR c++/9420
 	* search.c (lookup_conversions): Call complete_type here.
 	* call.c (implicit_conversion): Not here.
 
 Patches:
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_2-branch&r1=1.2685.2.114.2.69&r2=1.2685.2.114.2.70
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/call.c.diff?cvsroot=gcc&only_with_tag=gcc-3_2-branch&r1=1.307.2.6.4.2&r2=1.307.2.6.4.3
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/search.c.diff?cvsroot=gcc&only_with_tag=gcc-3_2-branch&r1=1.223.2.3.4.2&r2=1.223.2.3.4.3
 

Comment 9 Jason Merrill 2003-03-13 21:41:59 UTC
State-Changed-From-To: analyzed->closed
State-Changed-Why: fixed.
Comment 10 Jason Merrill 2003-03-21 07:10:44 UTC
From: jason@gcc.gnu.org
To: gcc-gnats@gcc.gnu.org
Cc:  
Subject: c++/9420
Date: 21 Mar 2003 07:10:44 -0000

 CVSROOT:	/cvs/gcc
 Module name:	gcc
 Changes by:	jason@gcc.gnu.org	2003-03-21 07:10:44
 
 Added files:
 	gcc/testsuite/g++.dg/template: overload1.C 
 
 Log message:
 	PR c++/9420
 	* search.c (lookup_conversions): Call complete_type here.
 	* call.c (implicit_conversion): Not here.
 
 Patches:
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/overload1.C.diff?cvsroot=gcc&r1=NONE&r2=1.1