In <http://lists.gnu.org/archive/html/bug-tar/2006-06/msg00023.html>
Denis Excoffier reports that compiling tar-1.15.91 generates the
following bogus error message on powerpc-apple-darwin8.6.0:

   openat.c: In function 'rpl_openat':
   openat.c:60: warning: 'mode_t' is promoted to 'int' when passed through
'...'
   openat.c:60: warning: (so you should pass 'int' not 'mode_t' to 'va_arg')
   openat.c:60: note: if this code is reached, the program will abort

I reproduced the problem on my i686-pc-linux-gnu platform, so the
problem is generic.  At the end of this description is a sample test
case that illustrates the problem.  Compiling it with 'gcc -c' yields
the messages:

t.c: In function 'foo':
t.c:18: warning: 'mode_t' is promoted to 'int' when passed through '...'
t.c:18: warning: (so you should pass 'int' not 'mode_t' to 'va_arg')
t.c:18: note: if this code is reached, the program will abort

This diagnostic is bogus: line 18 cannot possibly be executed because
sizeof (mode_t) < sizeof (int).  GCC knows this, since it doesn't
generate code for line 18, so GCC should be smart enough to not
generate the diagnostic for line 18.

#include <stdarg.h>

typedef unsigned short int mode_t;

int
foo (int flags, ...)
{
  mode_t mode = 0;
  va_list arg;
  va_start (arg, flags);

  /* If mode_t is narrower than int, use the promoted type (int),
     not mode_t.  Use sizeof to guess whether mode_t is nerrower;
     we don't know of any practical counterexamples.  */
  if (sizeof (mode_t) < sizeof (int))
    mode = va_arg (arg, int);
  else
    mode = va_arg (arg, mode_t);   /* This is line 18.  */

  va_end (arg);

  return flags == mode;
}


-- 
           Summary: bogus warning for va_arg argument promotion
           Product: gcc
           Version: 4.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: eggert at gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28106

Reply via email to