[libcxx-commits] [libcxx] [libcxx] Remove the second inclusion of the system header (PR #120946)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Mon Jan 6 12:49:15 PST 2025


================
@@ -106,10 +106,6 @@ void perror(const char* s);
 #  ifndef _LIBCPP_STDIO_H
 #    define _LIBCPP_STDIO_H
 
-#    if __has_include_next(<stdio.h>)
-#      include_next <stdio.h>
----------------
ldionne wrote:

It had been done that way because the first `include_next <stdio.h>` could potentially be the target of a `__need_size_t` macro (for example), which would result in the first inclusion only declaring `size_t`, not everything that should be in `stdio.h`.

After your patch, I believe that the following might not work anymore:

```c++
#define __need_size_t
#include <stdio.h>

int main() {
  puts("foo");
}
```

That's because I'd assume `#include <stdio.h>` to *only* define `size_t` when it gets included after defining the macro. I would expect e.g. `puts` to only be defined the second time around `stdio.h` is included, which you removed.

But if I'm wrong (and I'm happy to be), then I don't mind this patch.

https://github.com/llvm/llvm-project/pull/120946


More information about the libcxx-commits mailing list