Re:Show HN: C++ runtime/compile-time detection in constexpr ...
by lbrandy on Tuesday August 08, 2017 @12:36PM
(#14959570)
Just so I'm clear, what this appears to be doing is the moral equivalent of a function that asks if some constant equals what we know to be its value (true at compile time)? And then at program-init time (via __attribute__((constructor(101)))) changing the value of the constant in the text section so the test is now false?
If so, that's both quite clever and something I don't think I want in my codebase :P. The good news is I'm pretty sure Daveed's proposal that you mention (http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p059...) got support last time it came around EWG so I'm hoping we can just go that way.
Re:Show HN: C++ runtime/compile-time detection in constexpr ...
by nickelbox on Tuesday August 08, 2017 @12:26PM
(#14959462)
So would a valid tl;dr be, "modify the compiled program to catch any invocations not evaluated at compile time and make them return the correct value?"
Re:Show HN: C++ runtime/compile-time detection in constexpr ...
by minipci1321 on Wednesday August 09, 2017 @02:31AM
(#14966060)
Why to mlock() the page? And since the code is already specific to linux/gcc/clang, why not to assign the flag to a read-write section (__attribute__((section(name))) -- should allow to get rid of mprotect()?
If so, that's both quite clever and something I don't think I want in my codebase :P. The good news is I'm pretty sure Daveed's proposal that you mention (http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p059...) got support last time it came around EWG so I'm hoping we can just go that way.
http://saadahmad.ca/detecting-evaluation-context-inside-cons...
* `if ( __ctfe) { ... }` for compile time
* `if (!__ctfe) { ... }` for runtime
"An approach for runtime dection inside a constexpr function"
https://github.com/SaadAhmad/in_constexpr