N3690
Цитата
146p 7.1.6.1 The cv-qualifiers
7 [ Note: volatile is a hint to the implementation to avoid aggressive optimization involving the object
because the value of the object might be changed by means undetectable by an implementation. Furthermore,
for some implementations, volatile might indicate that special hardware instructions are required to access
the object. See 1.9 for detailed semantics. In general, the semantics of volatile are intended to be the
same in C++ as they are in C. — end note ]
8p 1.9 Program execution
8 The least requirements on a conforming implementation are:
— Access to volatile objects are evaluated strictly according to the rules of the abstract machine
Т.е. оно не заоптимизирует указатель даже если не видит переприсваиваний ему, а в нужном участке кода считает его значение и выполнит вызов функции по нему.
Отчего у вас в голове родилась странная идея что внутри тела фукнции будет отключена оптимизация я не знаю. Она неверна.
Цитата(aiwa @ Jul 10 2018, 10:11)
{
((void (* volatile)())func)(); // оптимизирует несмотря на volatile. наверное потому, что получаемый указатель rvalue;
}
Нет волатайл объекта - нет ограничений.
Вот так уже работает.