
Deprecating Volatile in C++ - fanf2
http://wg21.link/P1152R3
======
0xcde4c3db
The headline is misleading.

"We propose deprecating most of volatile. [...] The proposed deprecation
preserves the useful parts of volatile, and removes the dubious / already
broken ones."

This is an important distinction to make because people sometimes overreact to
misuses of volatile by effectively claiming that it's useless or has no
meaning.

~~~
deaddodo
Correct. More specifically:

"Continue supporting the time-honored usage of volatile to load and store
variables that are used for shared memory, signal handling, setjmp / longjmp,
or other external modifications such as special hardware support."

Which is what people want and use volatile for in the vast majority of cases.
Removing that functionality would render driver, OS and embedded development a
pain.

~~~
lisper
> Removing that functionality would render driver, OS and embedded development
> a pain.

It would be worse than "a pain", it would actually make it _impossible_. There
is no way other than "volatile" to _guarantee_ that a load or a store to/from
a particular memory address happens at a particular time (AFAIK).

~~~
aardvark179
You should.be able to enforce it with the memory ordering supported since
either C++11 or 14 (can’t recall which). It wouldn’t be quite as easy to write
down, but might provide stronger guarantees than the volatile semantics.

~~~
FartyMcFarter
How would you do something like this [1] using those?

[1] [https://godbolt.org/z/Aj5bJ8](https://godbolt.org/z/Aj5bJ8)

~~~
amluto
I would argue that this particular example is useless. A volatile variable at
file scope can easily be IO memory. A volatile static at function scope? Not
so easy.

~~~
FartyMcFarter
It can be set by a debugger for example.

In any case, the scope of the variable was not the point of the question. The
behaviour doesn't really change if you make the variable a static file-scoped
one.

------
johntb86
As mentioned in the link, the first version of the proposal -
[http://www.open-
std.org/jtc1/sc22/wg21/docs/papers/2018/p115...](http://www.open-
std.org/jtc1/sc22/wg21/docs/papers/2018/p1152r0.html#prop) \- has a simpler
summary of what the actual changes are.

