Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: How to fix warning: [-Wdate-time] Date: Mon, 17 Apr 2017 12:30:05 -0700 Organization: None to speak of Lines: 46 Message-ID: References: <8e289215-369a-43c5-aa46-9428ad81a224@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="6ede04a56392f1431524e35eef643cab"; logging-data="28112"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/m9Ki9xgyyreDMW+jZnYgQ" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:iA9hqgCLnTa4jWDX84eZ6JhizuQ= sha1:1YH/tCRLsieJ9GqsRhtFR434Xkg= Xref: csiph.com comp.lang.c:108242 Tim Rentsch writes: > Keith Thompson writes: > >> [.. what if -D__DATE__=... or -D__DATE__=... is given? ..] >> >> The problem would be that the expansions of __DATE__ and __TIME__ would >> be whatever was passed on the compiler command line and not, as the >> standard specifies and a reader will assume, the date and time of >> translation. >> >> On the other hand, compilers *are* allowed to do that (the option is >> typically "-D" rather than "-d", and the quoting needs to be fixed if >> that's supposed to be part of a shell command line). The standard >> (6.10.8p2) says that none of the predefined macro names shall be the >> subject of #define or #undef, but that's not a constraint, so it is at >> most undefined behavior -- and the standard doesn't talk about -D. >> [...] > > Under the provisions of 7.1.3, any definition (ie, and not just #define) > of such names gives undefined behavior. That's questionable IMHO. It says the behavior is undefined if the *program* declares, defines, or undefines a reserved identifier. Arguably if I compile with `gcc -D__DATE__=...`, it's not the program that's defining it. A minor quibble, and ... > Also, the documentation for gcc says about -Dname=definition "[t]he > contents of definition are tokenized and processed as if they appeared > during translation phase three in a #define directive." That too > means undefined behavior. > > The documentation for clang says that -Dmacroname=value "[a]dds an > implicit #define into the predefines buffer which is read before the > source file is preprocessed." Also undefined behavior. > > Most likely using -D to give a value to __DATE__ or __TIME__ will > work fine and do what everyone expects. As far as the Standard > is concerned, it looks like it's just undefined behavior. Agreed. -- Keith Thompson (The_Other_Keith) kst-u@mib.org Working, but not speaking, for JetHead Development, Inc. "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"