[llvm-bugs] [Bug 46022] New: if constexpr not working within a coroutine

via llvm-bugs llvm-bugs at lists.llvm.org
Thu May 21 09:07:47 PDT 2020


https://bugs.llvm.org/show_bug.cgi?id=46022

            Bug ID: 46022
           Summary: if constexpr not working within a coroutine
           Product: clang
           Version: trunk
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++2a
          Assignee: unassignedclangbugs at nondot.org
          Reporter: s_bugzilla at nedprod.com
                CC: blitzrakete at gmail.com, erik.pilkington at gmail.com,
                    llvm-bugs at lists.llvm.org, richard-llvm at metafoo.co.uk

https://godbolt.org/z/UXGMiJ

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 https://en.cppreference.com/w/cpp/language/if#Constexpr_If:

"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.

-- 
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/20200521/03e39042/attachment.html>


More information about the llvm-bugs mailing list