decltype as a return type in class member function

Is it valid?

Your last example is well-formed, while the first one is not (so GCC is correct).

Paragraph 3.4.1/7 on unqualified name lookup specifies:

A name used in the definition of a class X outside of a member function body, default argument, brace-or-
equal-initializer
of a non-static data member, or nested class definition shall be declared in one of the
following ways
:

before its use in class X or be a member of a base class of X (10.2), or

— […]

And what follows are other conditions that do not apply in your case.

Leave a Comment