[cfe-dev] Evaluation of C++ intrinsics

Kéri Kálmán keri.kalman at gmail.com
Mon May 25 08:14:15 PDT 2015


Hi,

I'm working on a proposal for C++ standardization. It is in a very early
phase, I'm looking for directions and techniques.

I saw something in another proposal what makes me wonder. Please help me
understand it.

Suppose that we need some information from the compiler, and we want it to
be accessable from the compiled code. A hypothetical example is a function
that queries the current timestamp from the compiler.

namespace std {
    constexpr time_t compiler_time(); // intrinsic
}
...
std::time_t ct = std::compiler_time();
std::cout << "I was compiled at " << std::asctime(std::gmtime(&ct));

I wonder how is it possible? I would reason like this:

-it doesn't make sense to evaluate compiler_time() in runtime, so
-the compiler should make a guarantee on its evaluation time
-its declaration may have an internal flag that prescribes its "early"
evaluation.
-it has nothing to do with the constexpr specifier.

Do I think correctly?


Thanks,

Kalman Keri
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20150525/32b00fc7/attachment.html>


More information about the cfe-dev mailing list