llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.32k stars 11.69k forks source link

Clang exposes C interfaces in C++ mode that it shouldn't #87668

Open AaronBallman opened 6 months ago

AaronBallman commented 6 months ago

The C++ standard library is based on a particular revision of the C standard (e.g., C++23 is based on C17, C++17 is based on C11, C++14 is based on C99). The compiler provides some of the C standard library headers, but it exposes non-conforming interfaces from them in some language modes. For example:

https://godbolt.org/z/G8W7Gs1vE https://godbolt.org/z/vbjs787TT https://godbolt.org/z/Ks67KEoh3

For improved conformance, we should do a comprehensive review of the C standard library headers provided by Clang to ensure that we're exposing the proper interfaces in the proper language modes.

llvmbot commented 6 months ago

@llvm/issue-subscribers-c-1

Author: Aaron Ballman (AaronBallman)

The C++ standard library is based on a particular revision of the C standard (e.g., C++23 is based on C17, C++17 is based on C11, C++14 is based on C99). The compiler provides some of the C standard library headers, but it exposes non-conforming interfaces from them in some language modes. For example: https://godbolt.org/z/G8W7Gs1vE https://godbolt.org/z/vbjs787TT https://godbolt.org/z/Ks67KEoh3 For improved conformance, we should do a comprehensive review of the C standard library headers provided by Clang to ensure that we're exposing the proper interfaces in the proper language modes.
frederick-vs-ja commented 6 months ago

In older C++ modes, some headers are just non-standard (and <stdnoreturn.h> is never a standard library header in C++). The standard doesn't seem to specify the contents of any non-standard "header".

The following example seems more critical to me (Godbolt link).

#define timespec_get 42
#include <ctime> // oops, timespec_get is declared even in C++14 mode