Why do Clang and MSVC not like a member typedef declaration with a redundant set of parentheses?

  ambiguous-grammar, c++, language-lawyer

Consider

using foo = int;

struct A {
    typedef A (foo)();
};

GCC and ICC accept the snippet, while Clang and MSVC reject it. Clang’s error message is

<source>:4:15: error: function cannot return function type 'void ()'
    typedef A (foo)();
              ^
<source>:4:13: error: typedef name must be an identifier
    typedef A (foo)();
            ^
2 errors generated.

And MSVC says

<source>(4,15): error C2091: function returns function
    typedef A (foo)();
              ^

(live demo)

Why do Clang and MSVC produce this error? Which compilers are correct?

Source: Windows Questions C++

LEAVE A COMMENT