Skip to content

-Wformat-signedness incorrectly warns when a bitfield field is passed to printf #155665

@ahatanak

Description

@ahatanak

$ cat test.c

int printf(const char *, ...) __attribute__((__format__(__printf__, 1, 2)));

struct S {
  unsigned int bf : 16;
  unsigned char c;
};

struct S s;

void foo(void) {
  printf("%x\n", s.bf);
  printf("%x\n", s.c);
}

$ clang test.c -c -o -Wformat -Wformat-signedness
test.c:11:18: warning: format specifies type 'unsigned int' but the argument has type 'int', which differs in signedness [-Wformat-signedness]
11 | printf("%x\n", s.bf);
| ~~ ^~~~
| %x
1 warning generated.

Both s.bf and s.c are promoted to int as a result of default argument promotion. clang silences the warning only when the latter is passed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerclang:frontendLanguage frontend issues, e.g. anything involving "Sema"

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions