C++ Logo


Advanced search

Re: [std-proposals] Every variable is volatile, everything is laundered, no optimisation

From: Alejandro Colomar <alx.manpages_at_[hidden]>
Date: Mon, 28 Aug 2023 01:42:07 +0200

You seem to want a portable way of specifying unportable semantics to
the language.

That does exist. Or kind of. It's in #pragma and [[vendor::attribute]].
That as far as the standard will take you by the hand. You need to cross
the door alone. At the other side of the door, your compiler vendor will
hopefully take your hand, if they are kind.

You should be asking your compiler vendor to provide a vendor specific
attribute or pragma that says "hey, the standard be ashes. I want some
other semantics" In GCC, I guess you have what you want with

$ g++ -fno-strict-overflow -fno-strict-overflow -fno-trapv -fno-strict-aliasing

That's an entire new dialect of C++ that some programmers believe to be
fine, and blame compiler authors for taking advantage of UB just because
they can. That's fine, if you need it, just use it. If you want to
enable those flags within the source code, you'll probably have pragmas
that enable it just for a few specific lines, although I don't do that
myself, so I didn't look that up.

The standard provides minimal tools to specify "my code invokes UB, I
know, and I won't fix it, so you better compile my code in my own
dialect of C++ without going crazy". I don't think it should extend
more than that, especially, when it's up to the compiler vendors to
define such a new dialect of C++, in an agreement between them and you.

These things are more often used in C, and not in C++, but hey, it's free.


Received on 2023-08-27 23:42:10