Title
noexcept-specifier of friend function vs class completeness
Status
nad
Section
11.4.1 [class.mem.general]
Submitter
John Spicer

Created on 2021-10-26.00:00:00 last changed 25 months ago

Messages

Date: 2022-11-11.15:53:10

CWG 2022-11-10

CWG believes that, in general, a "when needed" approach to parsing complete-class contexts is superior. In the present case, the existing wording clearly requires that the noexcept-specifier be delayed-parsed, which implies that matching the declaration of a friend function to declarations at namespace scope is also delayed.

Date: 2021-12-15.00:00:00

Notes from the December, 2021 teleconference:

CWG questioned why the declaration matching couldn't be deferred until the end of the class.

Date: 2022-02-15.00:00:00

According to 11.4.1 [class.mem.general] paragraph 7, a noexcept-specifier is a complete-class context. This raises an issue when the function is a friend function; for example, consider:

  using T = int;
  struct B {
    friend void g(B b) noexcept(sizeof(b.m) >= 4) { }
    T m = T();
  };
  int main() {
    B b;
    g(b);
  }

For friend declarations you need to be able to decide at the point of declaration whether it matches a prior declaration, and you can't do that if you treat the noexcept-specifier as a complete-class context.

There is implementation divergence in the treatment of this example.

History
Date User Action Args
2022-11-11 15:53:10adminsetmessages: + msg7022
2022-11-11 15:53:10adminsetstatus: open -> nad
2022-01-06 00:00:00adminsetmessages: + msg6618
2021-10-26 00:00:00admincreate