<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 - if constexpr not working within a coroutine"
href="https://bugs.llvm.org/show_bug.cgi?id=46022">46022</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>if constexpr not working within a coroutine
</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>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>C++2a
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>s_bugzilla@nedprod.com
</td>
</tr>
<tr>
<th>CC</th>
<td>blitzrakete@gmail.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
</td>
</tr></table>
<p>
<div>
<pre><a href="https://godbolt.org/z/UXGMiJ">https://godbolt.org/z/UXGMiJ</a>
For this sequence of code:
```
template<bool is_awaitable> using return_type =
std::conditional_t<is_awaitable, resumable, int>;
template<bool is_awaitable> return_type<is_awaitable> test_function(int x)
{
if constexpr(is_awaitable)
{
co_return x;
}
else
{
return x;
}
}
```
... trunk clang yields:
```
<source>:30:9: error: return statement not allowed in coroutine; did you mean
'co_return'?
return x;
^
<source>:26:9: note: function is a coroutine due to use of 'co_return' here
co_return x;
^
1 error generated.
Compiler returned: 1
```
>From <a href="https://en.cppreference.com/w/cpp/language/if#Constexpr_If">https://en.cppreference.com/w/cpp/language/if#Constexpr_If</a>:
"If a constexpr if statement appears inside a templated entity, and if
condition is not value-dependent after instantiation, the discarded statement
is not instantiated when the enclosing template is instantiated."
Therefore I think that the if constexpr ought to not cause the above error
diagnostic.</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>