Lambda return of value without capture

71 views Asked by At

This follows from another question.

The following program compiles on gcc and icc, but fails to compile on VS and clang:

template <typename Y>
auto add_value(Y y)
{
    const short z{9};
    return [y](auto x)
    {
        return z;
    };
}

int main()
{
    add_value(2);
}

godbolt example Flags were: -std=c++14 -O2 -Wall -Wshadow -pedantic -pthread

Which is correct? I suppose gcc is correct here? But I would prefer for this to fail.

0

There are 0 answers