consteval

Will consteval allow using static_assert on function arguments?

社会主义新天地 提交于 2020-01-22 18:26:23
问题 Currently you cannot use static_assert to verify parameters of a constexpr function, even if all calls to it are indeed constexpr . That makes sense because the compiler still has to create a non-constexpr instantiation of this function in case some other module will try to call it. Sadly, this is the case even if the function is static or in an anonymous namespace. C++20 however, will introduce a new keyword consteval which is like constexpr but it doesn't allow calling a function in a non

Will consteval allow using static_assert on function arguments?

旧街凉风 提交于 2020-01-22 18:24:06
问题 Currently you cannot use static_assert to verify parameters of a constexpr function, even if all calls to it are indeed constexpr . That makes sense because the compiler still has to create a non-constexpr instantiation of this function in case some other module will try to call it. Sadly, this is the case even if the function is static or in an anonymous namespace. C++20 however, will introduce a new keyword consteval which is like constexpr but it doesn't allow calling a function in a non

Can consteval functions from different translation units interfere?

安稳与你 提交于 2020-01-06 05:46:07
问题 I am trying to dig into implications of a function being inline and stumbled upon this issue. Consider this small program (demo): /* ---------- main.cpp ---------- */ void other(); constexpr int get() { return 3; } int main() { std::cout << get() << std::endl; other(); } /* ---------- other.cpp ---------- */ constexpr int get() { return 4; } void other() { std::cout << get() << std::endl; } When compiled without optimizations, the program yields the following output: 3 3 Which might be not

Is compiler allowed to call an immediate (consteval) function during runtime?

末鹿安然 提交于 2019-12-21 04:43:30
问题 This might be a stupid question, but I am confused. I had a feeling that an immediate ( consteval ) function has to be executed during compile time and we simply cannot see its body in the binary. This article clearly supports my feeling: This has the implication that the [immediate] function is only seen at compile time. Symbols are not emitted for the function, you cannot take the address of such a function, and tools such as debuggers will not be able to show them. In this matter,

What is consteval?

我只是一个虾纸丫 提交于 2019-12-09 02:07:02
问题 Apparently, consteval is going to be a keyword in C++20. The cppreference page for it is currently blank. What is it going to be and how does it relate to constexpr ? 回答1: It declares immediate functions , that is, functions that must be evaluated at compile time to produce a constant. (It used to be spelled constexpr! in a previous revision of the paper.) In contrast, constexpr functions may be evaluated at compile time or run time, and need not produce a constant in all cases. The adopted

Why does a consteval function allow undefined behavior?

北慕城南 提交于 2019-12-03 23:35:35
问题 There is a very neat property of constant expressions in C++: their evaluation cannot have undefined behavior (7.7.4.7): An expression e is a core constant expression unless the evaluation of e, following the rules of the abstract machine ([intro.execution]), would evaluate one of the following: ... an operation that would have undefined behavior as specified in [intro] through [cpp] of this document [ Note: including, for example, signed integer overflow ([expr.prop]), certain pointer

Is compiler allowed to call an immediate (consteval) function during runtime?

好久不见. 提交于 2019-12-03 16:34:34
This might be a stupid question, but I am confused. I had a feeling that an immediate ( consteval ) function has to be executed during compile time and we simply cannot see its body in the binary. This article clearly supports my feeling: This has the implication that the [immediate] function is only seen at compile time. Symbols are not emitted for the function, you cannot take the address of such a function, and tools such as debuggers will not be able to show them. In this matter, immediate functions are similar to macros. The similar strong claim might be found in Herb Sutter's publication

What is consteval?

*爱你&永不变心* 提交于 2019-12-01 02:06:11
Apparently, consteval is going to be a keyword in C++20. The cppreference page for it is currently blank. What is it going to be and how does it relate to constexpr ? T.C. It declares immediate functions , that is, functions that must be evaluated at compile time to produce a constant. (It used to be spelled constexpr! in a previous revision of the paper.) In contrast, constexpr functions may be evaluated at compile time or run time, and need not produce a constant in all cases. The adopted paper is P1073R3 , which is not yet publicly available, but a previous revision is available and the