<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/57762>57762</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            coroutines: change in behaviour (regression?) when updating from clang 14 to clang 15
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          adrianimboden
      </td>
    </tr>
</table>

<pre>
    https://godbolt.org/z/aGefcTMvo

The behavior of the `return_object` changed with clang 15. I'm not sure if that is against the standard, or if it is not defined very well.
clang 14 and gcc 12.2 behave the same, clang 15 is different.

When the object returned by `get_return_object()` is a different type than the coroutines return type, but it is implicitly convertible to it, **previously:**
- The intermediate type is instantiated locally
- After the final suspension point, it gets converted to the return type

**now:**
- The intermediate type is directly converted to the final type on starting the coroutine.


Reproducer (see godbolt link):
```
#include <coroutine>
#include <exception>
#include <iostream>

struct awaitable{};

struct task {

    struct convertible_to_task {
        operator task() {
            std::cout << "operator task()" << std::endl;
            return task{};
        }
    };

    struct promise_type {
        auto get_return_object(){
            return convertible_to_task{};
        }

        auto return_void() {
        }

        std::suspend_never initial_suspend(){
            return {};
        }

        std::suspend_always final_suspend() noexcept {
            return {};
        }

        void unhandled_exception(){
            std::terminate();
        }

        auto await_transform(awaitable) {
            struct Suspension {
                auto await_ready() {
                    return false;
                }

                auto await_suspend(std::coroutine_handle<>) {
                    std::cout << "Suspension::await_suspend" << std::endl;
                }

                auto await_resume() {
                    std::terminate(); // does not happen in example
                }
            };

            return Suspension{};
        }
    };
};


task foo() {
    co_await awaitable{};
    co_return;
}

int main() {
    foo();
}
```

clang 14.0.0:
```
Suspension::await_suspend
operator task()
```

clang 15.0.0:
```
operator task()
Suspension::await_suspend
```

gcc 12.2:
```
Suspension::await_suspend
operator task()
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy1V0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