Constexpr
Functions
| ← Previous revision | Revision as of 13:56, 20 April 2026 | ||
| Line 57: | Line 57: | ||
[[Coroutine]]s may not be constexpr. Historically, constexpr functions had far more restrictions, including the disallowing of multiple return statements, try blocks, and [[Inline assembler|inline assembly]] blocks, all of which have been gradually relaxed with each revision.{{Cite web|title=Relaxing constraints on constexpr functions|url=https://open-std.org/JTC1/SC22/WG21/docs/papers/2013/n3597.html|publisher=WG21|author=Richard Smith|date=15 March 2013}} |
[[Coroutine]]s may not be constexpr. Historically, constexpr functions had far more restrictions, including the disallowing of multiple return statements, try blocks, and [[Inline assembler|inline assembly]] blocks, all of which have been gradually relaxed with each revision.{{Cite web|title=Relaxing constraints on constexpr functions|url=https://open-std.org/JTC1/SC22/WG21/docs/papers/2013/n3597.html|publisher=WG21|author=Richard Smith|date=15 March 2013}} |
||
[[Method (computer programming)|Class methods]] may also be declared with constexpr. Prior to [[C++14]], constexpr methods had implicit const access, preventing them from being able to manipulate the class. Prior to C++20, [[virtual function]]s could not be constexpr.{{Cite web|title=Allowing Virtual Functions Calls in Constant Expressions|url=https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p1064r0.html|author=Peter Dimov, Vassil Vassilev|website=open-std.org|publisher=WG21|date=4 May 2018}} |
[[Method (computer programming)|Class methods]] and [[operator overloading|overloadable operators]] may also be declared with constexpr. Prior to [[C++14]], constexpr methods had implicit const access, preventing them from being able to manipulate the class. Prior to C++20, [[virtual function]]s could not be constexpr.{{Cite web|title=Allowing Virtual Functions Calls in Constant Expressions|url=https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p1064r0.html|author=Peter Dimov, Vassil Vassilev|website=open-std.org|publisher=WG21|date=4 May 2018}} |
||
=== Constructors and destructors === |
=== Constructors and destructors === |
||