https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110872

            Bug ID: 110872
           Summary: coroutine postcondition is not evaluated
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: akrzemi1 at gmail dot com
  Target Milestone: ---

Created attachment 55673
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=55673&action=edit
demo program

A postconditon declared on a coroutine should be evaluated when the coroutine
is invoked and returns to the caller. But it isn't as per the following
Compiler Explorer link.

https://godbolt.org/z/48fh3f34j

The expectation is enforced by the fact that the compiler allows mentioning the
return type of the coroutine declaration:

```
template <typename T>
struct generator
{
    // ...
    bool is_valid() { return false; }
};

generator<int> val(int v) 
[[post g: g.is_valid()]]
{
    co_yield v;
}
```

Generally, I would expect that preconditions and postconditions on coroutines
should work the same as if the call to the coroutine was wrapped in a
forwarding function containing the preconditions and postconditions:

```
awaitable<int> f1(int i)  // coroutine
  [[pre: p(i)]]
  [[post r: q(r)]];

awaitable<int> f2(int i); // coroutine

awaitable<int> ff2(int i)
  [[pre: p(i)]]
  [[post r: q(r)]];
{
  return f2(i);
}

void caller()
{
  f1(1);  // these two calls should have analogous
  ff2(1); // precondition and postcondition semantics
}
```

Reply via email to