Title
Name lookup for coroutine allocation
Status
open
Section
9.5.4 [dcl.fct.def.coroutine]
Submitter
Xu Chuanqi

Created on 2022-05-12.00:00:00 last changed 2 weeks ago

Messages

Date: 2022-05-21.12:38:12

Suggested resolution:

... The allocation function's name is looked up by searching for it in the scope of the promise type.
  • If any declarations are found in the scope of the promise type, overload resolution is performed on a function call created by assembling an argument list. The first argument is the amount of space requested, and has type std::size_t. The lvalues p1 ... pn are the succeeding arguments. Otherwise, a search is performed in the global scope. If no viable function is found (12.2.3 [over.match.viable]), overload resolution is performed again on a function call created by passing just the amount of space required as an argument of type std::size_t.
  • If no declarations are found in the scope of the promise type, a search is performed in the global scope. Overload resolution is performed on a function call created by passing the amount of space required as an argument of type std::size_t.
Date: 2022-05-12.00:00:00

Consider:

  struct Allocator;

  struct resumable::promise_type {
    void* operator new(std::size_t sz, Allocator&);
    // ...
  };
  resumable foo() {
    co_return;
  }

Subclause 9.5.4 [dcl.fct.def.coroutine] paragraph 9 specifies:

... The allocation function's name is looked up by searching for it in the scope of the promise type.
  • If any declarations are found, overload resolution is performed on a function call created by assembling an argument list. The first argument is the amount of space requested, and has type std::size_t. The lvalues p1 . . . pn are the succeeding arguments.
  • Otherwise, a search is performed in the global scope.
If no viable function is found (12.2.3 [over.match.viable]), overload resolution is performed again on a function call created by passing just the amount of space required as an argument of type std::size_t.

Is the example ill-formed because resumable::promise_type is not viable, or is the example well-formed because the global operator new can be used? There is implementation divergence.

See also LLVM issue 54881.

History
Date User Action Args
2022-05-12 07:39:38adminsetmessages: + msg6827
2022-05-12 00:00:00admincreate