This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

c++/6523: bug with pointers to template functions



>Number:         6523
>Category:       c++
>Synopsis:       bug with pointers to template functions
>Confidential:   no
>Severity:       critical
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          ice-on-legal-code
>Submitter-Id:   net
>Arrival-Date:   Tue Apr 30 14:46:00 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     Oliver Schoenborn
>Release:        3.0.1
>Organization:
>Environment:
System: IRIX64 onyx1 6.5 07091542 IP27
host: mips-sgi-irix6.5
build: mips-sgi-irix6.5
target: mips-sgi-irix6.5
configured with: ../configure --prefix=/usr/freeware --enable-version-specific-runtime-libs --disable-shared --enable-threads --enable-haifa
>Description:
Note that I built g++ 3.0.4 on my home linux system (Mandrake 8.1) 
and got same compiler failure so it is unlikely to be related to environment. 
Output from g++ is following:
     funcPtrProblem.cc: In function `int main()':
     funcPtrProblem.cc:32: Internal compiler error in 
         c_expand_expr, at c-common.c: 4121

A class Tester defines a function pointer typedef BarFunc and an example static function 
template of that type, called bar<T>(). Two different class templates Foo1<T> and Foo2<T> 
each have a /templated/ constructor (ie Foo1<T>::Foo1<T2>) that use a pointer to the 
bar<T2>() template function.  One Foo accesses this bar<T> via inheritence, i.e. Foo2 inherits 
from Tester.  The other, Foo1, accesses it directly since it is static and public.  In other words, 
both Foo classes do exactly the same thing (semantically) but in different ways.  Foo2 causes 
compiler crash. Compilation works if constructor of Foo2 is not templated, or even if it is but 
Foo2 itself is not a class template, or if bar is not a template.

>How-To-Repeat:
Put following code in one file called funcPtrProblem.cc and do 
g++ -c funcPtrProblem.cc
to get the above internal compiler error

struct Tester
{
    typedef void (*BarFunc)();

    template <typename T>
    static void bar() {}
};

template <typename T>
struct Foo1
{
    template <typename T2>
    Foo1(T2*, Tester::BarFunc = &Tester::bar<T2>) {}
};

template <typename T>
struct Foo2: private Tester
{
    template <typename T2>
    Foo2(T2*, BarFunc = &bar<T2>) {}
};

int main()
{
     Foo1<int> foo1(new int);
     Foo2<int> foo2(new int);
}

>Fix:
Do not use inheritence. This means that Tester must have everything public 

>Release-Note:
>Audit-Trail:
>Unformatted:


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]