Evaluation of C++ intrinsics


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?


Kalman Keri