<html>
<head>
<base href="https://bugs.llvm.org/">
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW - compile error related to static_assert and boost::hana"
href="https://bugs.llvm.org/show_bug.cgi?id=33318">33318</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>compile error related to static_assert and boost::hana
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>4.0
</td>
</tr>
<tr>
<th>Hardware</th>
<td>Macintosh
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>enhancement
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>C++14
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>matthias.thul@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>I originally posted this as a question on Stack Overflow and it was suggested
to me to file this as a bug here
(<a href="https://stackoverflow.com/questions/44355720">https://stackoverflow.com/questions/44355720</a>).
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.</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>