Search code examples
c++visual-c++structreturn-typefunction-declaration

Anonymous struct as a return type


The following code compiles fine with vc++ 19.00.23506 (flags: /Wall /WX /Za) and with vc++ 19.10.25109.0 (flags: /Wall /WX /Za /permissive-, this can be checked at http://webcompiler.cloudapp.net), but doesn't compile with clang 3.8.0 and g++ 6.3.0 (flags: -std=c++11 -Wall -Wextra -Werror -pedantic-errors). Is it a bug in vc++ and does the standard prohibit such constructions?

struct
{
}
foo()
{
    return {};
}

int main()
{
}

Solution

  • MSVC appears wrong:

    [dcl.fct]/9 Types shall not be defined in return or parameter types...