3

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.

Community
  • 1
  • 1
wally
  • 10,717
  • 5
  • 39
  • 72

0 Answers0