From 3385506fe73e94274312eb1696ff3b965bdd368b Mon Sep 17 00:00:00 2001
From: zack <zack@138bc75d-0d04-0410-961f-82ee72b054a4>
Date: Fri, 2 Aug 2002 04:18:16 +0000
Subject: [PATCH] 	* c-common.c (c_common_init): -Wtraditional also
 implies -Wlong-long. 	* cppinit.c (cpp_post_options): Likewise.

	* cppexp.c (cpp_classify_number): Suppress -Wtraditional
	warning about 'LL' suffix (but not 'ULL' etc) when
	-Wno-long-long is in effect.

	* cppmacro.c (_cpp_builtin_macro_text) [BT_TIME, BT_DATE]:
	Check for failing time()/localtime(), issue a warning, and
	make __TIME__ and __DATE__ expand to fallback strings.

	* doc/cpp.texi, doc/extend.texi: Document behavior of __DATE__
	and __TIME__ when the date and time cannot be determined.


git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@55969 138bc75d-0d04-0410-961f-82ee72b054a4
---
 gcc/ChangeLog       | 18 +++++++++++++++++-
 gcc/c-common.c      |  5 +++--
 gcc/cppexp.c        | 19 ++++++++++++-------
 gcc/cppinit.c       |  5 +++--
 gcc/cppmacro.c      | 42 +++++++++++++++++++++++++++++++-----------
 gcc/doc/cpp.texi    |  8 ++++++++
 gcc/doc/extend.texi |  4 +++-
 7 files changed, 77 insertions(+), 24 deletions(-)

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index f86aa87b6d6a..d0c32e545c20 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,19 @@
+2002-08-01  Zack Weinberg  <zack@codesourcery.com>
+
+	* c-common.c (c_common_init): -Wtraditional also implies -Wlong-long.
+	* cppinit.c (cpp_post_options): Likewise.
+
+	* cppexp.c (cpp_classify_number): Suppress -Wtraditional
+	warning about 'LL' suffix (but not 'ULL' etc) when
+	-Wno-long-long is in effect.
+
+	* cppmacro.c (_cpp_builtin_macro_text) [BT_TIME, BT_DATE]:
+	Check for failing time()/localtime(), issue a warning, and
+	make __TIME__ and __DATE__ expand to fallback strings.
+
+	* doc/cpp.texi, doc/extend.texi: Document behavior of __DATE__
+	and __TIME__ when the date and time cannot be determined.
+
 2002-08-02  Alan Modra  <amodra@bigpond.net.au>
 
 	* config/rs6000/rs6000.c (output_cbranch): Hint differently for power4.
@@ -48,7 +64,7 @@
 
 2002-08-01  Richard Henderson  <rth@redhat.com>
 
-	* toplev.c (parse_options_and_default_flags): Don't set 
+	* toplev.c (parse_options_and_default_flags): Don't set
 	flag_reorder_blocks for -Os.
 
 	* config/avr/avr.c (avr_optimization_options): Remove.
diff --git a/gcc/c-common.c b/gcc/c-common.c
index 415127317f01..363e72f949d6 100644
--- a/gcc/c-common.c
+++ b/gcc/c-common.c
@@ -4945,8 +4945,9 @@ c_common_init (filename)
   options->stdc_0_in_system_headers = STDC_0_IN_SYSTEM_HEADERS;
 
   /* We want -Wno-long-long to override -pedantic -std=non-c99
-     whatever the ordering.  */
-  options->warn_long_long = warn_long_long && !flag_isoc99 && pedantic;
+     and/or -Wtraditional, whatever the ordering.  */
+  options->warn_long_long
+    = warn_long_long && ((!flag_isoc99 && pedantic) || warn_traditional);
 
   /* Register preprocessor built-ins before calls to
      cpp_main_file.  */
diff --git a/gcc/cppexp.c b/gcc/cppexp.c
index 569043651d67..a3ef96538ef0 100644
--- a/gcc/cppexp.c
+++ b/gcc/cppexp.c
@@ -270,13 +270,18 @@ cpp_classify_number (pfile, token)
 	  return CPP_N_INVALID;
 	}
 
-      /* Traditional C only accepted the 'L' suffix.  */
-      if (result != CPP_N_SMALL && result != CPP_N_MEDIUM
-	  && CPP_WTRADITIONAL (pfile)
-	  && ! cpp_sys_macro_p (pfile))
-	cpp_error (pfile, DL_WARNING,
-		   "traditional C rejects the \"%.*s\" suffix",
-		   (int) (limit - str), str);
+      /* Traditional C only accepted the 'L' suffix.
+         Suppress warning about 'LL' with -Wno-long-long.  */
+      if (CPP_WTRADITIONAL (pfile) && ! cpp_sys_macro_p (pfile))
+	{
+	  int u_or_i = (result & (CPP_N_UNSIGNED|CPP_N_IMAGINARY));
+	  int large = (result & CPP_N_WIDTH) == CPP_N_LARGE;
+
+	  if (u_or_i || (large && CPP_OPTION (pfile, warn_long_long)))
+	    cpp_error (pfile, DL_WARNING,
+		       "traditional C rejects the \"%.*s\" suffix",
+		       (int) (limit - str), str);
+	}
 
       if ((result & CPP_N_WIDTH) == CPP_N_LARGE
 	  && ! CPP_OPTION (pfile, c99)
diff --git a/gcc/cppinit.c b/gcc/cppinit.c
index 212f1a463084..03f04c1a5d68 100644
--- a/gcc/cppinit.c
+++ b/gcc/cppinit.c
@@ -1787,8 +1787,9 @@ cpp_post_options (pfile)
 
   /* The compiler front ends override this, but I think this is the
      appropriate setting for the library.  */
-  CPP_OPTION (pfile, warn_long_long) = (CPP_OPTION (pfile, pedantic)
-					&& !CPP_OPTION (pfile, c99));
+  CPP_OPTION (pfile, warn_long_long)
+     = ((CPP_OPTION (pfile, pedantic) && !CPP_OPTION (pfile, c99))
+	|| CPP_OPTION (pfile, warn_traditional));
 
   /* Permanently disable macro expansion if we are rescanning
      preprocessed text.  Read preprocesed source in ISO mode.  */
diff --git a/gcc/cppmacro.c b/gcc/cppmacro.c
index 50cc9bbf4ba6..f0986b353cba 100644
--- a/gcc/cppmacro.c
+++ b/gcc/cppmacro.c
@@ -207,17 +207,37 @@ _cpp_builtin_macro_text (pfile, node)
 	     storage.  We only do this once, and don't generate them
 	     at init time, because time() and localtime() are very
 	     slow on some systems.  */
-	  time_t tt = time (NULL);
-	  struct tm *tb = localtime (&tt);
-
-	  pfile->date = _cpp_unaligned_alloc (pfile,
-					      sizeof ("\"Oct 11 1347\""));
-	  sprintf ((char *) pfile->date, "\"%s %2d %4d\"",
-		   monthnames[tb->tm_mon], tb->tm_mday, tb->tm_year + 1900);
-
-	  pfile->time = _cpp_unaligned_alloc (pfile, sizeof ("\"12:34:56\""));
-	  sprintf ((char *) pfile->time, "\"%02d:%02d:%02d\"",
-		   tb->tm_hour, tb->tm_min, tb->tm_sec);
+	  time_t tt;
+	  struct tm *tb = NULL;
+
+	  /* (time_t) -1 is a legitimate value for "number of seconds
+	     since the Epoch", so we have to do a little dance to
+	     distinguish that from a genuine error.  */
+	  errno = 0;
+	  tt = time(NULL);
+	  if (tt != (time_t)-1 || errno == 0)
+	    tb = localtime (&tt);
+
+	  if (tb)
+	    {
+	      pfile->date = _cpp_unaligned_alloc (pfile,
+						  sizeof ("\"Oct 11 1347\""));
+	      sprintf ((char *) pfile->date, "\"%s %2d %4d\"",
+		       monthnames[tb->tm_mon], tb->tm_mday, tb->tm_year + 1900);
+
+	      pfile->time = _cpp_unaligned_alloc (pfile,
+						  sizeof ("\"12:34:56\""));
+	      sprintf ((char *) pfile->time, "\"%02d:%02d:%02d\"",
+		       tb->tm_hour, tb->tm_min, tb->tm_sec);
+	    }
+	  else
+	    {
+	      cpp_errno (pfile, DL_WARNING,
+			 "could not determine date and time");
+		
+	      pfile->date = U"\"??? ?? ????\"";
+	      pfile->time = U"\"??:??:??\"";
+	    }
 	}
 
       if (node->value.builtin == BT_DATE)
diff --git a/gcc/doc/cpp.texi b/gcc/doc/cpp.texi
index 28e78000cf8d..73785c13794a 100644
--- a/gcc/doc/cpp.texi
+++ b/gcc/doc/cpp.texi
@@ -1780,11 +1780,19 @@ the preprocessor is being run.  The string constant contains eleven
 characters and looks like @code{@w{"Feb 12 1996"}}.  If the day of the
 month is less than 10, it is padded with a space on the left.
 
+If GCC cannot determine the current date, it will emit a warning message
+(once per compilation) and @code{__DATE__} will expand to
+@code{@w{"??? ?? ????"}}.
+
 @item __TIME__
 This macro expands to a string constant that describes the time at
 which the preprocessor is being run.  The string constant contains
 eight characters and looks like @code{"23:59:01"}.
 
+If GCC cannot determine the current time, it will emit a warning message
+(once per compilation) and @code{__TIME__} will expand to
+@code{"??:??:??"}.
+
 @item __STDC__
 In normal operation, this macro expands to the constant 1, to signify
 that this compiler conforms to ISO Standard C@.  If GNU CPP is used with
diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi
index 0ddcb345161e..70afc3b8ffab 100644
--- a/gcc/doc/extend.texi
+++ b/gcc/doc/extend.texi
@@ -366,7 +366,9 @@ directive (6.10.6).}
 @cite{The definitions for @code{__DATE__} and @code{__TIME__} when
 respectively, the date and time of translation are not available (6.10.8).}
 
-GCC assumes that the date and time is always available.
+If the date and time are not available, @code{__DATE__} expands to
+@code{@w{"??? ?? ????"}} and @code{__TIME__} expands to
+@code{"??:??:??"}.
 
 @end itemize
 
-- 
GitLab