C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Alteration of elements in a set (non-const iterator)

From: Thiago Macieira <thiago_at_[hidden]>
Date: Mon, 22 May 2023 10:10:22 -0700
On Monday, 22 May 2023 04:22:18 PDT Edward Catmur via Std-Proposals wrote:
> Anyway, the point (nowadays) is optimization - the compiler can assume that
> opaque code does not modify a const object (or subobject).

Actually, it's the opposite. Compilers assume that const objects can be
modified through const_cast all the time...

Note how they all reload from memory: https://gcc.godbolt.org/z/YEnzMr8xP.
Even if the member itself is const: https://gcc.godbolt.org/z/xs7xhE5os

I've been meaning to ask for a [[really_const]] attribute for a while.

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
   Software Architect - Intel DCAI Cloud Engineering

Received on 2023-05-22 17:10:30