GCC vs普通lambda的铿锵:谁是正确的?

时间:2017-03-18 20:26:09

标签: c++ gcc clang c++14

繁殖很简单:

#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编译好了,但是gcc说:

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信息:

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)

我也会在GCC邮件列表上提出同样的问题,所以请不要在那里重定向。

UPD:在Bugzilla中找到了this bug,它似乎已经提交了相同的GCC问题。

0 个答案:

没有答案