C++ Logo

std-discussion

Advanced search

Re: Default arguments and classes nested within class templates

From: Jens Maurer <jens.maurer_at_[hidden]>
Date: Sun, 8 Jan 2023 19:06:17 +0100
On 08/01/2023 18.41, Matthew House via Std-Discussion wrote:
> According to 9.3.4.7 [dcl.fct.default] paragraph 6,
>
> Default arguments for a member function of a class template shall be
> specified on the initial declaration of the member function within
> the class template.
>
> This wording does not include redeclarations of member functions of
> classes nested within class templates, so it implies that the
> following program is well-formed:
>
> template<class> struct A { struct B { void c(int); }; };
> template<class T> void A<T>::B::c(int = 0) {}
> int main() {}
>
> However, only MSVC accepts this program; both GCC and Clang reject it.
> Is it intentional that such declarations are valid?

No. That's another case where "templated function" should be used.

Feel free to create an issue at

https://github.com/cplusplus/CWG/issues

Jens

Received on 2023-01-08 18:06:21