Skip to content

CWG3233 [dcl.contract.func] function contract assertions aren't needed enough #1003

Description

@notadragon

Full name of submitter (unless configured in github; will be published with the issue): Joshua Berne

Reference (section label): [dcl.contract.func] p9

Link to reflector thread (if any):

Issue description: Currently we require a function's contract assertions to be valid when the function is odr-used. This is fine in C++26 because calling a function always gets you to that function's definition.

With P3097 and contracts on virtual functions, we have a separate issue that calling a pure virtual function doesn't odr-use that function (because odr-use is about wanting the definition, not he declaration). We already have a similar seemingly-redundant carveout in the definition of needed for exception specifications where we say "in an expression, the function is selected by overload resolution" in addition to the case where the function is odr-used.

Therefore we need to add a similar bullet to when we need a function's function-contract-assertions. Since it is only evaluation that matters (and the assertions are not and never will be part of the type or relevant in unevaluated expressions) I think we need a parallel to the first bullet in [except.spec]p13 but limited to potentially-evaluated expressions.

Suggested resolution:
The function contract assertions of a function are considered to be needed (13.9.2) when
— in a potentially evaluated expression, the function is selected by overload resolution ([over.match],[over.over]),
— the function is odr-used ([basic.def.odr]) or
— the function is defined.

Activity

  1. changed the title [-][dcl.contract.func] function contract assertions aren't needed enough[/-] [+]CWG3233 [dcl.contract.func] function contract assertions aren't needed enough[/+] on Sep 20, 2026
  2. jensmaurer commented on Sep 20, 2026

    @jensmaurer
    Member
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions