Skip to content

[std module] Building std module fails with _FORTIFY_SOURCE #121709

@nmlgc

Description

@nmlgc

Tested on a relatively current trunk, but exists since at least Clang 18:

clang version 20.0.0 (/home/nmlgc/aur/llvm-git/llvm-project 743c84bb9b79ed70d9bed926c2a173db3b30f587)
Target: x86_64-pc-linux-gnu
Thread model: posix
$ clang++ -O -D_FORTIFY_SOURCE -stdlib=libc++ -std=c++2c --precompile -Wno-reserved-module-identifier /usr/share/libc++/v1/std.cppm
In file included from /usr/share/libc++/v1/std.cppm:229:
/usr/share/libc++/v1/std/cstdio.inc:47:14: error: using declaration referring to 'snprintf' with internal linkage cannot be exported
   47 |   using std::snprintf _LIBCPP_USING_IF_EXISTS;
      |              ^
/usr/include/bits/stdio2.h:75:8: note: target of using declaration
   75 | __NTH (snprintf (__fortify_clang_overload_arg (char *, __restrict, __s),
      |        ^
In file included from /usr/share/libc++/v1/std.cppm:229:
/usr/share/libc++/v1/std/cstdio.inc:48:14: error: using declaration referring to 'sprintf' with internal linkage cannot be exported
   48 |   using std::sprintf _LIBCPP_USING_IF_EXISTS;
      |              ^
/usr/include/bits/stdio2.h:37:8: note: target of using declaration
   37 | __NTH (sprintf (__fortify_clang_overload_arg (char *, __restrict, __s),
      |        ^
In file included from /usr/share/libc++/v1/std.cppm:234:
/usr/share/libc++/v1/std/cwchar.inc:30:14: error: using declaration referring to 'swprintf' with internal linkage cannot be exported
   30 |   using std::swprintf _LIBCPP_USING_IF_EXISTS;
      |              ^
/usr/include/bits/wchar2.h:181:8: note: target of using declaration
  181 | __NTH (swprintf (__fortify_clang_overload_arg (wchar_t *, __restrict, __s),
      |        ^
3 errors generated.

_FORTIFY_SOURCE is part of the default CFLAGS of (at least) Arch Linux during package builds via makepkg, and would need to be manually removed to work with modules.

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:modulesC++20 modules and Clang Header Moduleslibc++libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions