[Bug c++/28044] New: Non-template class function return type taken as template when declared in a function template's return type

widman at gimpel dot com gcc-bugzilla@gcc.gnu.org
Thu Jun 15 18:14:00 GMT 2006


See below; G++ appears to correctly handle the use of 'struct B' to declare the
function template g(), but if there is no prior declaration of the class (as in
the declaration of f()), the class is erroneously taken as a class template.

extern "C" int printf( const char*, ... );

struct B{ int n; B(int n_) : n(n_){} };
template<class T> struct B g() // OK, g() returns B
    {
    return B(32);
    }

template<class T> struct A f(); // OK, f() returns A

struct A { char c; A(char c_) : c(c_){}};

template<class T> struct A f()
    {
    return A('x');
    }

int main(  )
    {
    (void) printf( "%d, %c\n", 
                   g<double>().n, 
                   f<float>().c ); // prints "32, x\n".
    return 0;
    }


-- 
           Summary: Non-template class function return type taken as
                    template when declared in a function template's return
                    type
           Product: gcc
           Version: 4.0.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: widman at gimpel dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28044



More information about the Gcc-bugs mailing list