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: [email protected]
          Reporter: [email protected]
                CC: [email protected], [email protected],
                    [email protected], [email protected]

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.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to