[Bug c++/86429] New: lambda capture breaks constexpr-ness
zub at linux dot fjfi.cvut.cz
gcc-bugzilla@gcc.gnu.org
Fri Jul 6 20:52:00 GMT 2018
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86429
Bug ID: 86429
Summary: lambda capture breaks constexpr-ness
Product: gcc
Version: 9.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: zub at linux dot fjfi.cvut.cz
Target Milestone: ---
This issue seems similar to bug 82643 but unlike that bug, this code compiles
fine in g++ 7.3 and fails to compile in g++ 8.1. Trying it out at wandabox.org
with gcc HEAD (201807) also results in compilation error.
The code requires boost hana:
====
#include <iostream>
#include <boost/hana.hpp>
int main()
{
namespace hana = boost::hana;
constexpr auto map = hana::make_map(hana::make_pair(hana::type_c<int>,
"foo"));
[&](auto v) {
constexpr auto x = boost::hana::find(map, v);
std::cout << *x << '\n';
}(hana::type_c<int>);
return 0;
}
====
With g++ 7.3 and clang++ it compiles OK and when run, prints out "foo\n" on
stdout. With g++ 8.1 I get:
$ g++-8 -std=c++17 gcc-8.1-not_contant.cc
gcc-8.1-not_contant.cc: In instantiation of ‘main()::<lambda(auto:1)> [with
auto:1 = boost::hana::type_impl<int>::_]’:
gcc-8.1-not_contant.cc:12:21: required from here
gcc-8.1-not_contant.cc:10:18: error: ‘__closure’ is not a constant expression
constexpr auto x = boost::hana::find(map, v);
^
While I'm not 100% sure the code is correct, even the error message is strange
(__closure?).
More information about the Gcc-bugs
mailing list