[llvm-bugs] [Bug 33318] New: compile error related to static_assert and boost::hana
via llvm-bugs
llvm-bugs at lists.llvm.org
Mon Jun 5 17:50:13 PDT 2017
https://bugs.llvm.org/show_bug.cgi?id=33318
Bug ID: 33318
Summary: compile error related to static_assert and boost::hana
Product: clang
Version: 4.0
Hardware: Macintosh
OS: Linux
Status: NEW
Severity: enhancement
Priority: P
Component: C++14
Assignee: unassignedclangbugs at nondot.org
Reporter: matthias.thul at gmail.com
CC: llvm-bugs at lists.llvm.org
I originally posted this as a question on Stack Overflow and it was suggested
to me to file this as a bug here
(https://stackoverflow.com/questions/44355720).
The following program compiles successfully using Clang versions
3.8.0-2ubuntu4, 4.0.1-svn304242-1~exp1 and 5.0.0-svn304672-1~exp1 using
"-std=c++14". The Boost library version is 1.61.0.
========== BEGIN SOURCE 1 ==========
#include <boost/hana.hpp>
namespace hana = boost::hana;
int main() {
constexpr auto indices = hana::range<unsigned, 0, 3>();
hana::for_each(indices, [&](auto i) {
hana::for_each(indices, [&](auto j) {
constexpr bool test = (i == (j == i ? j : i));
static_assert(test, "error");
});
});
}
========== END SOURCE 1 ==========
The test is quite non-sensical but that is not the point. Consider now an
alternative version where the test is put inside the static_assert:
========== BEGIN SOURCE 2 ==========
#include <boost/hana.hpp>
namespace hana = boost::hana;
int main() {
constexpr auto indices = hana::range<unsigned, 0, 3>();
hana::for_each(indices, [&](auto i) {
hana::for_each(indices, [&](auto j) {
static_assert((i == (j == i ? j : i)), "error");
});
});
}
========== END SOURCE 2 ==========
I get a bunch of compile errors saying:
test.cpp:7:38: note: 'i' declared here
hana::for_each(indices, [&](auto i) {
^
test.cpp:9:39: error: reference to local variable 'i' declared in enclosing
lambda expression
static_assert((i == (j == i ? j : i)), "error");
^
The curious thing is, that when accessing i before the static_assert,
everything compiles again:
========== BEGIN SOURCE 3 ==========
#include <boost/hana.hpp>
namespace hana = boost::hana;
int main() {
constexpr auto indices = hana::range<unsigned, 0, 3>();
hana::for_each(indices, [&](auto i) {
hana::for_each(indices, [&](auto j) {
constexpr auto a = i;
static_assert((i == (j == i ? j : i)), "error");
});
});
}
========== END SOURCE 3 ==========
Note in particular that the added statement is unrelated to the static_assert.
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20170606/e0179810/attachment-0001.html>
More information about the llvm-bugs
mailing list