C++ Logo

std-proposals

Advanced search

Re: [std-proposals] <type_traits> std::contains_mutable

From: Thiago Macieira <thiago_at_[hidden]>
Date: Fri, 14 Nov 2025 11:14:48 -0800
On Friday, 14 November 2025 06:38:23 Pacific Standard Time Frederick Virchanza
Gotham via Std-Proposals wrote:
> If we store a 'const' object in a section of memory that later gets
> set read-only, we need to be sure that it is really a const object --
> i.e. it can't contain mutable members.

"if we store" is the issue here. How are you doing that?

If you're using a linker script, you're outside of the Standard. I'd call this
a bug: choosing to put read-write objects in read-only memory was your own
fault.

If the compiler did that on its own, then it's a compiler bug. Please contact
your vendor with a testcase and have them fix it. GCC does it correctly:
https://godbolt.org/z/Gx41hMWTb

Note how "m" is in the .data section and "ro" is in the .rodata section.

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
  Principal Engineer - Intel Data Center - Platform & Sys. Eng.

Received on 2025-11-14 19:14:55