<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 - Poor diagnostic for assertion failure during constexpr invocation"
href="https://bugs.llvm.org/show_bug.cgi?id=38534">38534</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Poor diagnostic for assertion failure during constexpr invocation
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>All
</td>
</tr>
<tr>
<th>OS</th>
<td>All
</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++
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>llvmbugs@contacts.eelis.net
</td>
</tr>
<tr>
<th>CC</th>
<td>dgregor@apple.com, llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>Consider:
constexpr int f(int i)
{
assert(i > 3);
return i * 2;
}
This works great:
static_assert(f(4) == 8); // ok!
Less great is the diagnostic given in case the i > 3 assertion fails:
static_assert(f(1) == 2); // produces:
----------------------------
<source>:11:15: error: static_assert expression is not an integral constant
expression
static_assert(f(1) == 2);
^~~~~~~~~
<source>:5:5: note: non-constexpr function '__assert_fail' cannot be used in a
constant expression
assert(i > 3);
^
/usr/include/assert.h:95:9: note: expanded from macro 'assert'
: __assert_fail (#expr, __FILE__, __LINE__, __ASSERT_FUNCTION))
^
<source>:11:15: note: in call to 'f(1)'
static_assert(f(1) == 2);
^
/usr/include/assert.h:69:13: note: declared here
extern void __assert_fail (const char *__assertion, const char *__file,
^
----------------------------
I understand where all the noise about constant expressions and the
__assert_fail function and the assert macro comes from, but I think we can
serve users better by emitting a diagnostic that directly states the /real/
problem right away: "assertion i > 3 failed". :)</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>