https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87775

            Bug ID: 87775
           Summary: error due __builtin_fprintf having the wrong type
           Product: gcc
           Version: 9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gcc dot gnu.org
  Target Milestone: ---

See also pr87774.  GCC fails to compile the program below because it declares
__builtin_fprintf as taking void* rather than FILE* as the first argument (it's
a hack to get around FILE not necessarily being a known type when the built-in
is declared).

$ cat t.c && gcc -O2 -S -Wall -Wextra t.c
#include <stdio.h>

int f (const char*, ...);
int ff (FILE*, const char*, ...);
int sf (char*, const char*, ...);

void g (int i, FILE *fp, char *d)
{
  (i ? printf : f)("abc");
  (i ? fprintf : ff)(fp, "abc");
  (i ? sprintf : sf)(d, "abc");
}

void h (int i, FILE *fp, char *d)
{
  (i ? __builtin_printf : f)("abc");
  (i ? __builtin_fprintf : ff)(fp, "abc");
  (i ? __builtin_sprintf : sf)(d, "abc");
}

__typeof__ (fprintf) *pf = __builtin_fprintf;


t.c: In function ‘h’:
t.c:17:26: warning: pointer type mismatch in conditional expression
   17 |   (i ? __builtin_fprintf : ff)(fp, "abc");
      |                          ^
t.c:17:26: error: called object is not a function or function pointer
   17 |   (i ? __builtin_fprintf : ff)(fp, "abc");
      |   ~~~~~~~~~~~~~~~~~~~~~~~^~~~~
t.c: At top level:
t.c:21:28: warning: initialization of ‘int (*)(FILE * restrict,  const char *
restrict,  ...)’ {aka ‘int (*)(struct _IO_FILE * restrict,  const char *
restrict,  ...)’} from incompatible pointer type ‘int (*)(void *, const char *,
...)’ [-Wincompatible-pointer-types]
   21 | __typeof__ (fprintf) *pf = __builtin_fprintf;
      |                            ^~~~~~~~~~~~~~~~~

Reply via email to