There’s a good talk by the C++ committee language evolution chair on why.
Brief summary, the places that volatile
is being removed from didn’t have any well defined meaning in the standard and just caused confusion.
Motivating (Ambiguous) Examples
- Volatile bit Fields should be specified by your hardware manual and/or compiler.
- Is
+=
a single/atomic instruction? How about++
? - How many reads/writes are needed for
compare_exchange
? What if it fails? - What does
void foo(int volatile n)
mean? orint volatile foo()
? - Should
*vp;
do a load? (This has changed twice in the standard.)
Threading
Historically, people have used volatile
to achieve thread safety in C and C++. In C++11, non-UB ways to create synchronization and shared state between threads were added. I recommend Back to Basics: Concurrency as a good introduction.