[PATCH] D137043: [clang] add implicit include for Linux/gnu compatibility

YingChi Long via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Oct 30 12:22:30 PDT 2022


inclyc added a comment.

> That is OK for glibc system because glibc includes this file manually. But with other libc (e.g. musl), which does not manually include this, clang will fail but GCC can get it compiled.

FWIW currently we cannot build libedit using clang on x86_64-unknown-linux-musl and to fix this issue, they have a workaround here https://patchwork.ozlabs.org/project/buildroot/patch/1452127277-9538-1-git-send-email-sergio.prado@e-labworks.com/ which manually defined `__STDC_ISO_10646__`

Reproducer:

  #include <stdio.h>
  // #include <stdc-predef.h>
  
  int main() {
          printf("%d", __STDC_ISO_10646__);
  }

GCC accepted this code but clang complained `use of undeclared identifier '__STDC_ISO_10646__'`

  test.c:5:15: error: use of undeclared identifier '__STDC_ISO_10646__'
          printf("%d", __STDC_ISO_10646__);
                       ^
  1 error generated.

Note that glibc includes `stdc-predefs.h` at the source-code level, so this problem cannot be reproduced on the glibc-based systems. (The header `stdio.h` actually #includes `stdc-predefs.h` in glibc!)

However if we do not #include `stdio.h`, different behaviors can be seen on glibc platforms.

  int main() {
    return __STDC_ISO_10646__;
  }

See https://godbolt.org/z/Gd9Kbn766.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137043/new/

https://reviews.llvm.org/D137043



More information about the cfe-commits mailing list