25845f
commit e4043b84c49e1cf9bcf1e8320233343ecc34f8eb
25845f
Author: Joseph Myers <joseph@codesourcery.com>
25845f
Date:   Tue Jun 27 17:12:13 2017 +0000
25845f
25845f
    Fix strftime build with GCC 8.
25845f
    
25845f
    Building with current GCC mainline fails with:
25845f
    
25845f
    strftime_l.c: In function '__strftime_internal':
25845f
    strftime_l.c:719:4: error: macro expands to multiple statements [-Werror=multistatement-macros]
25845f
        digits = d > width ? d : width;          \
25845f
        ^
25845f
    strftime_l.c:1260:6: note: in expansion of macro 'DO_NUMBER'
25845f
          DO_NUMBER (1, tp->tm_year + TM_YEAR_BASE);
25845f
          ^~~~~~~~~
25845f
    strftime_l.c:1259:4: note: some parts of macro expansion are not guarded by this 'else' clause
25845f
        else
25845f
        ^~~~
25845f
    
25845f
    In fact this particular instance is harmless; the code looks like:
25845f
    
25845f
              if (modifier == L_('O'))
25845f
                goto bad_format;
25845f
              else
25845f
                DO_NUMBER (1, tp->tm_year + TM_YEAR_BASE);
25845f
    
25845f
    and because of the goto, it doesn't matter that part of the expansion
25845f
    isn't under the "else" conditional.  But it's also clearly bad style
25845f
    to rely on that.  This patch changes DO_NUMBER and DO_NUMBER_SPACEPAD
25845f
    to use do { } while (0) to avoid such problems.
25845f
    
25845f
    Tested (full testsuite) for x86_64 (GCC 6), and with
25845f
    build-many-glibcs.py with GCC mainline, in conjunction with my libgcc
25845f
    patch <https://gcc.gnu.org/ml/gcc-patches/2017-06/msg02032.html>.
25845f
    
25845f
            * time/strftime_l.c (DO_NUMBER): Define using do { } while (0).
25845f
            (DO_NUMBER_SPACEPAD): Likewise.
25845f
25845f
Index: b/time/strftime_l.c
25845f
===================================================================
25845f
--- a/time/strftime_l.c
25845f
+++ b/time/strftime_l.c
25845f
@@ -715,12 +715,22 @@ __strftime_internal (CHAR_T *s, size_t m
25845f
       format_char = *f;
25845f
       switch (format_char)
25845f
 	{
25845f
-#define DO_NUMBER(d, v) \
25845f
-	  digits = d > width ? d : width;				      \
25845f
-	  number_value = v; goto do_number
25845f
-#define DO_NUMBER_SPACEPAD(d, v) \
25845f
-	  digits = d > width ? d : width;				      \
25845f
-	  number_value = v; goto do_number_spacepad
25845f
+#define DO_NUMBER(d, v)				\
25845f
+	  do					\
25845f
+	    {					\
25845f
+	      digits = d > width ? d : width;	\
25845f
+	      number_value = v;			\
25845f
+	      goto do_number;			\
25845f
+	    }					\
25845f
+	  while (0)
25845f
+#define DO_NUMBER_SPACEPAD(d, v)		\
25845f
+	  do					\
25845f
+	    {					\
25845f
+	      digits = d > width ? d : width;	\
25845f
+	      number_value = v;			\
25845f
+	      goto do_number_spacepad;		\
25845f
+	    }					\
25845f
+	  while (0)
25845f
 
25845f
 	case L_('%'):
25845f
 	  if (modifier != 0)