Why does this default function argument cause the parser to crash?

Is the following program not finished C ++ 03? Does it show an old GCC error? Is this known?

template <typename T, typename U>
struct A
{};

template<class T>
struct B
{};


template <typename T, typename U>
struct B<A<T, U> >
{
    B(const A<T, U>& a = A<T, U>()) {};
};

int main() {}

It compiles for me with GCC 4.8, but GCC 4.3.3 (Sourcery g ++ Lite 2009q1-203) rejects it with the following:

test.cpp:13: error: expected ',' or '...' before '>' token
test.cpp:13: error: wrong number of template arguments (1, should be 2)
test.cpp:2: error: provided for 'template<class T, class U> struct A'
test.cpp:13: error: default argument missing for parameter 2 of 'B<A<T, U> >::B(const A<T, U>&, U)'

Both compilers happily create it when I remove the default constructor argument or surround the expression with parentheses:

B(const A<T, U>& a = (A<T, U>())) {};
//                   ^         ^
+4
source share

Source: https://habr.com/ru/post/1536451/


All Articles