"Use constexpr wherever possible" -- Scott Myers, item 15, Effective modern C++
Already const is an overloaded term which means multiple things in multiple contexts. Given this, and Myers' guidance, suppose I am feeling adventurous and do a project wide search and replace of all instances of const with constexpr, what is the worst that can happen?
-- If the previous code with const was working fine with no errors, should I expect to see no errors when each instance of const is changed to constexpr on compilation?
-- Is constexpr more overloaded in its meaning than const ?
-- Can this change of all consts to constexprs lead to subtle bugs or undefined behavior even though the code compiles fine?
Posted Apr 8, 2026, 2:48 AM UTC
1139