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]

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


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


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