Re[4]: constexpr - разочарование
От: Conr Россия  
Дата: 13.06.17 19:39
Оценка: 1 (1)
Здравствуйте, niXman, Вы писали:

X>все проверенные мною компиляторы(gcc-6.3-linux, mingw-w64-7.1-windows, clang-4.0-linux, intel-17.0-linux) генерят одинаковый код, приведенный мною ранее.

Это хорошо, конечно. Но необязательно и зависит от ключей:

clang -O1: run time
clang -O2: compile time
gcc -O0: run time
gcc -O1: compile time
gcc -O2: compile time


Bjarne Stroustrup said on Jan 14, 2013 08:58 PM:

The correct answer — as stated by Herb — is that according to the standard a constexpr function may be evaluated at compiler time or run time unless it is used as a constant expression, in which case it must be evaluated at compile-time. To guarantee compile-time evaluation, we must either use it where a constant expression is required (e.g., as an array bound or as a case label) or use it to initialize a constexpr. I would hope that no self-respecting compiler would miss the optimization opportunity to do what I originally said: "A constexpr function is evaluated at compile time if all its arguments are constant expressions."

 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.