Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesn't Clang like the __DATE__ macro?

Tags:

I use the __DATE__ macro for getting a compile-time year:

const QString build_year = __DATE__ + 7;

The Clang Code Model in QtCreator throws a -Wdate-time warning for using the __DATE__ macro.

warning: expansion of date or time macro is not reproducible

I can disable this warning with -Wno-date-time, but what is wrong with using __DATE__?

What is an "expansion" of the macro, how can it be "reproducible" or "not reproducible", and why is "not reproducible" bad?

like image 378
yalov Avatar asked Oct 19 '18 17:10

yalov


People also ask

What is the __time__ macro in C++?

Similarly, the __TIME__ macro is used to insert the current compilation time in the form "hh:mm:ss" into your program. This date-and-time-stamp feature should not be confused with the current system date and time. Rather, these two macros enable you to keep track of the date and time your program was last compiled.

What is the difference between _date_ and _time_ macros?

Thank You for your Questions.... _DATE_ macro expands to a string constant that describes the date on which the pre-processor is being run whereas _TIME_ macro expands to a string constant that describes the time at which the pre-processor is being run. Thanks, Team DishaaPro

What is the difference between __date__ and __time__ in C++?

__DATE__ This macro expands to a string constant that describes the date on which the preprocessor is being run. The string constant contains eleven characters and looks like "Feb 12 1996". __TIME__ This macro expands to a string constant that describes the time at which the preprocessor is being run.


2 Answers

Having repeated builds reproduce binary-identical outputs is desirable from many points of view. Building identical source code from identical tool chains giving different binaries each time could hide serious problems.

If you don't need to produce identical binaries every time you build identical code just disable that warning. that's why the command-line switch exists.

like image 54
Stephen M. Webb Avatar answered Oct 12 '22 00:10

Stephen M. Webb


The warning message tells you why. Using the macro does not result in a reproducible build since its value will change over time. A build in 2018 and one in 2019 will not produce the same binary.

like image 33
Jesper Juhl Avatar answered Oct 12 '22 01:10

Jesper Juhl