<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<title>Remove contracts on virtual functions for now</title>

	<style>
	p {text-align:justify}
	li {text-align:justify}
	blockquote.note
	{
		background-color:#E0E0E0;
		padding-left: 15px;
		padding-right: 15px;
		padding-top: 1px;
		padding-bottom: 1px;
	}
	ins {color:#00A000}
	del {color:#A00000}
	</style>
</head>
<body>

<address>
Document number: P3616R0
<br/>
Audience: EWG
<br/>
<br/>
<a href="mailto:ville.voutilainen@gmail.com">Ville Voutilainen</a><br/>

2025-02-08<br/>
</address>
<hr/>
<h1>Remove contracts on virtual functions for now</h1>

<h2>Abstract</h2>

<p>We should, for the time being, remove contracts on virtual functions.
  The model that is currently in P2900 has a couple of problems, we
  have ostensible fixes being worked on, and those fixes need implementation
  prototyping and proposal work that takes more time than we have
  before the C++26 deadline.
</p>

<h2>Brief elaboration</h2>

<p>There's no way to express "give my derived class virtual function override
  exactly the contract of my base class virtual function". The currently
  suggested way to approximate that is to attempt to repeat the base
  function contract, but that's not the same thing, and might not even
  be possible if the base contract is written in terms of private members.</p>

<p>This inability leads to troublesome results, including in cases
  where static polymorphism, either via templates or via manually written
  code, is applied to objects at different levels of an inheritance hierarchy.
</p>

<p>We can likely solve this problem and bring back automatic inheritance
  of contracts, once we have prototype-proven building blocks in place,
  including the ability to overrule an inherited contract, the ability
  to state the intent of inheriting a base contract as-is, and the ability
  to optionally diagnose (along the lines of -Wsuggest-override)
  cases where a base contract is implicitly inherited,
  allowing users who don't want that to be notified by their build, rather
  than have it be a surprise to them.
</p>
<p>The current model of P2900 for contracts on virtual functions closes
  the door to some such plausible models. So we should remove contracts
  on virtual functions for now, and make another attempt at solving
  these problems in a way that makes a larger portion of us happier.</p>
</body>
</html>
