C++ Logo

liaison

Advanced search

Re: [isocpp-wg14/wg21-liaison] qualifier and type deduction

From: Jₑₙₛ Gustedt <jens.gustedt_at_[hidden]>
Date: Tue, 28 Apr 2026 15:48:58 +0200
Jens,

on Tue, 28 Apr 2026 15:36:38 +0200 you (Jens Maurer via Liaison
<liaison_at_[hidden]>) wrote:

> On 4/28/26 15:05, Martin Uecker wrote:
> > Am Dienstag, dem 28.04.2026 um 13:11 +0200 schrieb Jens Maurer via
> > Liaison:
> >>
> >> On 4/28/26 12:45, Aaron Ballman via Liaison wrote:
> [...]
> [...]
> [...]
> >
> > Sorry, I still do not undertand this. We also put "const" on the
> > pointer target in function interfaces. The qualifier on the
> > argument itself does become part of the type of the function.
> >
> > So are you saying "const" also causes problems for type generic code
> > and qualifiers are generally a problem in C++?
>
> Not really.
>
> Consider:
>
> const /* 1 */ int * const /* 2 */ ptr = foo();
>
>
> There are two ways to place a "const" here, and each syntactic
> location has its implied meaning.
>
> "const" at position 2 means you can't modify the "ptr" variable
> going forward.
> "const" at position 1 means you can't modify the object to which
> the value of "ptr" points (using this particular access path).

Exactly, but as your careful formulation shows ("you can't modify")
this is not a property of the pointer (for 2) nor the pointed object
(for 1), but a permission for the access to them.

> (Yes, the object itself might be non-const, but that's not in the
> picture here.)

In the contrary, that's exactly the point. The additon of an
`_Optional` to the pointer target type does not change the object's
type, but only changes the ways in which it might be accessed: once I
use `*ptr` and an lvalue conversion happens, a `const`, `_Optional` or
whatever disapears.

All of these rules perfectly fit into C's handling of qualifiers. We
should not repeat the design error that we made for `restrict` where
we put a qualifier on a pointer object that is supposed to regulate
the rules for accessing the pointed-to object.

Thanks
Jₑₙₛ

-- 
:: ICube :::::::::::::::::::::::::::::: deputy director ::
:: Université de Strasbourg :::::::::::::::::::::: ICPS ::
:: INRIA antenne de Strasbourg :::::::::::::::::: Camus ::
:: INRIA PIQ program Strasbourg :::::::::: piq.inria.fr ::
:: :::::::::::::::::::::::::::::::::::: ☎ +33 368854536 ::
:: https://icube-icps.unistra.fr/index.php/Jens_Gustedt ::

Received on 2026-04-28 13:49:01