template <typename TF> constexpr auto f(TF) { return [](auto...) constexpr { return true; }; } // Compiles and works as intended. template <typename T0> void ok_0(T0) { static_assert(f([](auto x) -> decltype(x){})(T0{})); } // Compiles and works as intended. template <typename T0> void ok_1(T0) { constexpr auto a = f([](auto x) -> decltype(x){})(T0{}); if constexpr(a) { } } // Compile-time error! template <typename T0> void fail_0(T0) { if constexpr(f([](auto x) -> decltype(x){})(T0{})) { } } --- Error: prog.cc: In function 'void fail_0(T0)': prog.cc:29:54: error: expression '<lambda>' is not a constant expression if constexpr(f([](auto x) -> decltype(x){})(T0{})) { } Minimal example: http://melpon.org/wandbox/permlink/NY4oKSlA76CkqPQ9 Related StackOverflow question: http://stackoverflow.com/questions/40283001 P.S. the bug is still present even if 'constexpr' is explicitly specified for the lambdas passed to 'f'.
Author: paolo Date: Wed Oct 4 20:58:52 2017 New Revision: 253431 URL: https://gcc.gnu.org/viewcvs?rev=253431&root=gcc&view=rev Log: 2017-10-04 Paolo Carlini <paolo.carlini@oracle.com> PR c++/78131 * g++.dg/cpp1z/constexpr-lambda17.C: New. Added: trunk/gcc/testsuite/g++.dg/cpp1z/constexpr-lambda17.C Modified: trunk/gcc/testsuite/ChangeLog
Fixed in trunk.