GCC vs clang on common lambda: who is right?

Playback is simple:

#include <utility> int foo (int&) { return 0; } int bar (int&&) { return 0; } int main () { auto transparent = [](auto f, auto&& param) { return f(std::forward<decltype(param)>(param)); }; int a; transparent (foo, a); transparent (bar, std::move(a)); } 

clang compiles fine, but gcc says:

 04a-repro.cc: In instantiation of 'main()::<lambda(auto:1, auto:2&&)> [with auto:1 = int (*)(int&); auto:2 = int]': 04a-repro.cc:9:45: required by substitution of 'template<class auto:1, class auto:2> main()::<lambda(auto:1, auto:2&&)>::operator decltype (((main()::<lambda(auto:1, auto:2&&)>)0u).operator()(static_cast<auto:1>(<anonymous>), static_cast<auto:2&&>(<anonymous>))) (*)(auto:1, auto:2&&)() const [with auto:1 = int (*)(int&); auto:2 = int]' 04a-repro.cc:13:22: required from here 04a-repro.cc:10:13: error: invalid initialization of non-const reference of type 'int&' from an rvalue of type 'int' return f(std::forward<decltype(param)>(param)); ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 

GCC Information:

 Target: x86_64-w64-mingw32 Configured with: ../src/configure --with-gmp=/c/temp/gcc/gmp --with-mpfr=/c/temp/gcc/mpfr --with-mpc=/c/temp/gcc/mpc --enable-languages=c,c++ --build=x86_64-w64-mingw32 --host=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --disable-multilib --prefix=/c/temp/gcc/dest --with-sysroot=/c/temp/gcc/dest --disable-libstdcxx-pch --disable-nls --disable-shared --disable-win32-registry --enable-checking=release --with-tune=haswell Thread model: win32 gcc version 6.1.0 (GCC) 

I will also ask the same question on the GCC mailing list, so please do not redirect me there.

UPD: Found this bug in Bugzilla, it looks like the same GCC problems have already been filed.

+5
source share

Source: https://habr.com/ru/post/1265656/


All Articles