llvm-project/libcxx/include
Louis Dionne a4ba780510 [libc++] Enable -Wformat-nonliteral when building libc++
Using user-provided data as a format string is a well known source of
security vulnerabilities. For this reason, it is a good idea to compile
our code with -Wformat-nonliteral, which basically warns if a non-constant
string is used as a format specifier. This is the compiler’s best signal
that a format string call may be insecure.

I audited the code after adding the warning and made sure that the few
places where we used a non-literal string as a format string were not
potential security issues. I either disabled the warning locally for
those instances or fixed the warning by using a literal. The idea is
that after we add the warning to the build, any new use of a non-literal
string in a format string will trigger a diagnostic, and we can either
get rid of it or disable the warning locally, which is a way of
acknowledging that it has been audited.

I also looked into enabling it in the test suite, which would perhaps
allow finding additional instances of it in our headers, however that
is not possible at the moment because Clang doesn't support putting
__attribute__((__format__(...))) on variadic templates, which would
be needed.

rdar://84571685

Differential Revision: https://reviews.llvm.org/D112927
2021-11-09 13:17:45 -05:00
..
__algorithm [libc++] Add an option to disable wide character support in libc++ 2021-10-12 06:08:23 -04:00
__bit [libc++] Implement C++20's P0476R2: std::bit_cast 2021-09-09 11:05:54 -04:00
__charconv [libc++][NFC] split <charconv>. 2021-08-31 18:45:19 +02:00
__compare [libc++] [P1614] Implement std::compare_three_way. 2021-10-10 21:57:10 -04:00
__concepts [libc++] Remove an unused internal concept. 2021-09-02 19:27:49 +02:00
__format [libc++][format] Use preferred_name attribute. 2021-10-30 12:51:56 +02:00
__functional [libc++] Add an option to disable wide character support in libc++ 2021-10-12 06:08:23 -04:00
__iterator [libc++] Use addressof in vector. 2021-10-21 17:28:17 +02:00
__memory [libc++] P0433R2: test that deduction guides are properly SFINAEd away. 2021-11-09 09:32:24 -08:00
__random [libcxx] Move all algorithms into their own headers 2021-06-19 07:49:06 -04:00
__ranges [libc++] Ensure valid view for view_interface template parameter 2021-10-29 19:04:54 -04:00
__support [libcxx][AIX] Remove locale fallbacks for old OS levels 2021-09-21 21:14:50 -04:00
__utility [libc++] Make __decay_copy constexpr 2021-10-27 17:32:08 -04:00
__variant [libc++][NFC] Remove useless _LIBCPP_PUSH_MACROS 2021-08-27 12:41:55 -04:00
experimental [libcxx] Make allocator<T>:allocate throw bad_array_new_length 2021-10-18 19:12:42 +01:00
ext [libcxx][functional][modular] splices <functional> into modular headers 2021-07-01 14:01:49 -04:00
CMakeLists.txt [libc++] Add an option to disable wide character support in libc++ 2021-10-12 06:08:23 -04:00
__availability [libc++][format] Add __format_arg_store. 2021-09-01 19:45:02 +02:00
__bit_reference [libc++] __bit_iterator mustn't rely on deprecated SMF generation. 2021-04-26 16:22:42 -04:00
__bits [libc++] Fix some typos and remove unused macros. NFCI. 2021-04-22 12:02:22 -04:00
__bsd_locale_defaults.h
__bsd_locale_fallbacks.h [libc++] Add an option to disable wide character support in libc++ 2021-10-12 06:08:23 -04:00
__config Revert "[libc++] Always define a key function for std::bad_function_call in the dylib" 2021-11-08 00:44:47 -08:00
__config_site.in [libc++] Add an option to disable wide character support in libc++ 2021-10-12 06:08:23 -04:00
__debug [libc++] NFC: Normalize `#endif //` comment indentation 2021-04-20 12:03:32 -04:00
__errc [libc++] NFC: Normalize `#endif //` comment indentation 2021-04-20 12:03:32 -04:00
__function_like.h [libc++][NFC] Remove useless _LIBCPP_PUSH_MACROS 2021-08-27 12:41:55 -04:00
__functional_base [libcxx][functional][modular] splices <functional> into modular headers 2021-07-01 14:01:49 -04:00
__hash_table [libc++] Use addressof to fix debug tests. 2021-10-12 18:15:35 +02:00
__libcpp_version [libcxx] Bump __libcpp_version to 14 after branch 2021-07-28 11:07:06 +00:00
__locale [libc++] Add an option to disable wide character support in libc++ 2021-10-12 06:08:23 -04:00
__mbstate_t.h [libc++] Add an option to disable wide character support in libc++ 2021-10-12 06:08:23 -04:00
__mutex_base [libc++][NFCI] Remove uses of _LIBCPP_INLINE_VAR 2021-09-22 16:03:00 -04:00
__node_handle [libc++][NFC] Add missing synopsis for node handles 2021-09-07 15:26:33 -04:00
__nullptr [libc++] NFC: Normalize `#endif //` comment indentation 2021-04-20 12:03:32 -04:00
__split_buffer [libc++] Comma-operator-proof a lot of algorithm/container code. 2021-09-08 13:34:01 -04:00
__std_stream [libc++] Alphabetize and include-what-you-use. NFCI. 2021-05-29 19:54:48 -04:00
__string [libc++] Add an option to disable wide character support in libc++ 2021-10-12 06:08:23 -04:00
__threading_support [libc++] Remove non-atomic "platform" semaphore implementations. 2021-11-04 14:33:34 -04:00
__tree [libc++] Use addressof in assignment operator. 2021-10-07 18:10:47 +02:00
__tuple [libc++] Remove workarounds for [[nodebug]] not working properly on typedefs in older Clangs 2021-09-01 10:51:09 -04:00
__undef_macros
algorithm [libc++][NFC] Remove useless _LIBCPP_PUSH_MACROS 2021-08-27 12:41:55 -04:00
any [libcxx][modularisation] moves <utility> content out of <type_traits> 2021-06-24 17:57:29 +00:00
array [libc++] Use enable_if_t instead of _EnableIf 2021-09-08 09:09:28 -04:00
atomic [libc++] Update atomic synopsis and tests. 2021-10-12 17:28:08 +02:00
barrier [libc++] Fix a few warnings in system headers with GCC 2021-07-27 20:09:01 -04:00
bit [libc++] Implement C++20's P0476R2: std::bit_cast 2021-09-09 11:05:54 -04:00
bitset [libc++][NFC] Rename _EnableIf to __enable_if_t for consistency 2021-09-08 15:20:58 -04:00
cassert
ccomplex [libc++] NFC: Normalize `#endif //` comment indentation 2021-04-20 12:03:32 -04:00
cctype [libc++] Use the using_if_exists attribute when provided 2021-06-04 09:55:21 -04:00
cerrno [libc++] NFC: Normalize `#endif //` comment indentation 2021-04-20 12:03:32 -04:00
cfenv [libc++] Use the using_if_exists attribute when provided 2021-06-04 09:55:21 -04:00
cfloat [libc++] NFC: Normalize `#endif //` comment indentation 2021-04-20 12:03:32 -04:00
charconv [libc++] LWG3266: delete the to_chars(bool) overload. 2021-10-15 17:52:58 +02:00
chrono [libcxx] Remove nonstandard _FilesystemClock::{to,from}_time_t 2021-11-04 10:24:47 +02:00
cinttypes [libc++] Use the using_if_exists attribute when provided 2021-06-04 09:55:21 -04:00
ciso646 [libc++] NFC: Normalize `#endif //` comment indentation 2021-04-20 12:03:32 -04:00
climits [libc++] NFC: Normalize `#endif //` comment indentation 2021-04-20 12:03:32 -04:00
clocale [libc++] Remove support for CloudABI, which has been abandoned 2021-08-24 14:11:32 -04:00
cmath [libc++] Use enable_if_t instead of _EnableIf 2021-09-08 09:09:28 -04:00
codecvt [libc++] Add an option to disable wide character support in libc++ 2021-10-12 06:08:23 -04:00
compare [libc++] [P1614] Implement std::compare_three_way. 2021-10-10 21:57:10 -04:00
complex [libc++] Fix buggy numerics of tanh(complex) at inf 2021-10-28 16:10:56 -04:00
complex.h [libc++] NFC: Normalize `#endif //` comment indentation 2021-04-20 12:03:32 -04:00
concepts [libc++][NFC] Move concepts to a subheader. 2021-09-02 19:22:15 +02:00
condition_variable [libc++] NFC: Normalize `#endif //` comment indentation 2021-04-20 12:03:32 -04:00
csetjmp [libc++] Use the using_if_exists attribute when provided 2021-06-04 09:55:21 -04:00
csignal [libc++] Use the using_if_exists attribute when provided 2021-06-04 09:55:21 -04:00
cstdarg [libc++] Use the using_if_exists attribute when provided 2021-06-04 09:55:21 -04:00
cstdbool [libc++] NFC: Normalize `#endif //` comment indentation 2021-04-20 12:03:32 -04:00
cstddef [libc++] Add an option to disable wide character support in libc++ 2021-10-12 06:08:23 -04:00
cstdint [libc++] Use the using_if_exists attribute when provided 2021-06-04 09:55:21 -04:00
cstdio [libc++] Remove support for CloudABI, which has been abandoned 2021-08-24 14:11:32 -04:00
cstdlib [libc++] Remove _LIBCPP_HAS_NO_LONG_LONG in favour of using_if_exists 2021-09-03 14:26:59 -04:00
cstring [libc++] Remove support for CloudABI, which has been abandoned 2021-08-24 14:11:32 -04:00
ctgmath [libc++] NFC: Normalize `#endif //` comment indentation 2021-04-20 12:03:32 -04:00
ctime [libc++] Remove support for CloudABI, which has been abandoned 2021-08-24 14:11:32 -04:00
ctype.h [libc++] NFC: Normalize `#endif //` comment indentation 2021-04-20 12:03:32 -04:00
cwchar [libc++] Remove _LIBCPP_HAS_NO_LONG_LONG in favour of using_if_exists 2021-09-03 14:26:59 -04:00
cwctype [libc++] Fix incorrect bypassing of <wctype.h> 2021-08-26 13:26:31 -04:00
deque [libc++] P0433R2: test that deduction guides are properly SFINAEd away. 2021-11-09 09:32:24 -08:00
errno.h [libc++] NFC: Normalize `#endif //` comment indentation 2021-04-20 12:03:32 -04:00
exception [libcxx][modularisation] moves <utility> content out of <type_traits> 2021-06-24 17:57:29 +00:00
execution [pstl][libc++] Provide uglified header names for interface headers 2019-08-06 21:11:24 +00:00
fenv.h
filesystem Raise compile error when using unimplemented functions 2021-10-20 13:55:50 -04:00
float.h [libc++] NFC: Normalize `#endif //` comment indentation 2021-04-20 12:03:32 -04:00
format [libc++] Add an option to disable wide character support in libc++ 2021-10-12 06:08:23 -04:00
forward_list [libc++] P0433R2: test that deduction guides are properly SFINAEd away. 2021-11-09 09:32:24 -08:00
fstream [libc++] Remove support for CloudABI, which has been abandoned 2021-08-24 14:11:32 -04:00
functional [libc++] [P1614] Implement std::compare_three_way. 2021-10-10 21:57:10 -04:00
future [libc++][NFC] Fix include guard for decay_copy.h and remove underscores from the header 2021-08-27 12:45:53 -04:00
initializer_list [libc++] NFC: Normalize `#endif //` comment indentation 2021-04-20 12:03:32 -04:00
inttypes.h [libc++] NFC: Normalize `#endif //` comment indentation 2021-04-20 12:03:32 -04:00
iomanip [libc++][NFC] Remove _VSTD:: when not needed. 2021-05-10 18:15:50 +02:00
ios [libc++] Restore `basic_ios`'s implicit conversion to `bool` in C++03 mode. 2021-08-11 13:36:29 -04:00
iosfwd [libc++] Add an option to disable wide character support in libc++ 2021-10-12 06:08:23 -04:00
iostream [libc++] Add an option to disable wide character support in libc++ 2021-10-12 06:08:23 -04:00
istream [libc++] Add an option to disable wide character support in libc++ 2021-10-12 06:08:23 -04:00
iterator [libcxx][ranges] Add `unreachable_sentinel`. 2021-08-12 10:11:27 -07:00
latch [libc++] Alphabetize and include-what-you-use. NFCI. 2021-05-29 19:54:48 -04:00
limits [libc++] NFC: Normalize `#endif //` comment indentation 2021-04-20 12:03:32 -04:00
limits.h [libc++] NFC: Normalize `#endif //` comment indentation 2021-04-20 12:03:32 -04:00
list [libc++] P0433R2: test that deduction guides are properly SFINAEd away. 2021-11-09 09:32:24 -08:00
locale [libc++] Enable -Wformat-nonliteral when building libc++ 2021-11-09 13:17:45 -05:00
locale.h [libc++][NFC] Reindent error message 2021-08-23 15:34:51 -04:00
map [libc++] P0433R2: test that deduction guides are properly SFINAEd away. 2021-11-09 09:32:24 -08:00
math.h [libc++][NFC] Rename _EnableIf to __enable_if_t for consistency 2021-09-08 15:20:58 -04:00
memory [libc++] LWG3001: add `remove_extent_t` to `weak_ptr::element_type`. 2021-10-25 11:15:54 -04:00
module.modulemap [libc++] Add an option to disable wide character support in libc++ 2021-10-12 06:08:23 -04:00
mutex [libc++][NFC] Mark LWG2731 as complete 2021-10-26 13:46:00 -04:00
new [libcxx] Make allocator<T>:allocate throw bad_array_new_length 2021-10-18 19:12:42 +01:00
numbers [libc++][NFC] Remove useless _LIBCPP_PUSH_MACROS 2021-08-27 12:41:55 -04:00
numeric [libc++] Alphabetize header inclusions and include-what-you-use <__debug>. NFCI. 2021-05-18 19:56:30 -04:00
optional [libc++][NFCI] Remove uses of _LIBCPP_INLINE_VAR 2021-09-22 16:03:00 -04:00
ostream [libc++] Add an option to disable wide character support in libc++ 2021-10-12 06:08:23 -04:00
queue [libc++] P0433R2: test that deduction guides are properly SFINAEd away. 2021-11-09 09:32:24 -08:00
random [libc++] Fix a few warnings in system headers with GCC 2021-07-27 20:09:01 -04:00
ranges [libc++][nfc] Remove a duplicated include. 2021-10-10 14:21:01 +02:00
ratio [libc++] Remove uses of _LIBCPP_HAS_NO_VARIABLE_TEMPLATES 2021-09-23 08:53:59 -04:00
regex [libc++] Add an option to disable wide character support in libc++ 2021-10-12 06:08:23 -04:00
scoped_allocator [libc++] P0433R2: add the remaining deduction guides. 2021-10-28 11:09:51 -07:00
semaphore [libc++] Fix hang in counting_semaphore::try_acquire 2021-11-05 15:57:46 -04:00
set [libc++] P0433R2: test that deduction guides are properly SFINAEd away. 2021-11-09 09:32:24 -08:00
setjmp.h [libc++] NFC: Normalize `#endif //` comment indentation 2021-04-20 12:03:32 -04:00
shared_mutex [libc++] Alphabetize and include-what-you-use. NFCI. 2021-05-29 19:54:48 -04:00
span [libc++] Implement LWG3369, tweak CTAD for std::span. 2021-10-29 14:15:41 -06:00
sstream [libc++] Remove some _LIBCPP_CXX03_LANG from iostreams headers. 2021-06-28 12:55:26 -04:00
stack [libc++][NFC] Rename _EnableIf to __enable_if_t for consistency 2021-09-08 15:20:58 -04:00
stdbool.h [libc++] NFC: Normalize `#endif //` comment indentation 2021-04-20 12:03:32 -04:00
stddef.h [libc++] NFC: Normalize `#endif //` comment indentation 2021-04-20 12:03:32 -04:00
stdexcept [libc++] Alphabetize and include-what-you-use. NFCI. 2021-05-29 19:54:48 -04:00
stdint.h [libc++] NFC: Normalize `#endif //` comment indentation 2021-04-20 12:03:32 -04:00
stdio.h [libc++] NFC: Normalize `#endif //` comment indentation 2021-04-20 12:03:32 -04:00
stdlib.h [libc++] Remove _LIBCPP_HAS_NO_LONG_LONG in favour of using_if_exists 2021-09-03 14:26:59 -04:00
streambuf [libc++] Alphabetize and include-what-you-use. NFCI. 2021-05-29 19:54:48 -04:00
string [libc++] Add an option to disable wide character support in libc++ 2021-10-12 06:08:23 -04:00
string.h [libc++] NFC: Normalize `#endif //` comment indentation 2021-04-20 12:03:32 -04:00
string_view [libc++] Add an option to disable wide character support in libc++ 2021-10-12 06:08:23 -04:00
strstream [libc++] Alphabetize and include-what-you-use. NFCI. 2021-05-29 19:54:48 -04:00
system_error [libc++][ABI Break] Make is_error_condition_enum_v and is_error_code_enum_v bool, not size_t 2021-10-28 15:38:17 -04:00
tgmath.h [libc++] NFC: Normalize `#endif //` comment indentation 2021-04-20 12:03:32 -04:00
thread [libc++][NFC] Fix include guard for decay_copy.h and remove underscores from the header 2021-08-27 12:45:53 -04:00
tuple [libc++][spaceship] Implement std::tuple::operator<=> 2021-10-08 16:24:28 -07:00
type_traits [libc++] Remove Clang-11 support. 2021-10-30 12:50:22 +02:00
typeindex [libcxx][functional][modular] splices <functional> into modular headers 2021-07-01 14:01:49 -04:00
typeinfo [libc++] Remove unnecessary reinterpret_cast from typeinfo 2021-06-28 10:00:33 -04:00
unordered_map [libc++] P0433R2: test that deduction guides are properly SFINAEd away. 2021-11-09 09:32:24 -08:00
unordered_set [libc++] P0433R2: test that deduction guides are properly SFINAEd away. 2021-11-09 09:32:24 -08:00
utility [libc++] P0433R2: add the remaining deduction guides. 2021-10-28 11:09:51 -07:00
valarray [libc++] P0433R2: add the remaining deduction guides. 2021-10-28 11:09:51 -07:00
variant [libc++][NFCI] Remove uses of _LIBCPP_INLINE_VAR 2021-09-22 16:03:00 -04:00
vector [libc++] P0433R2: test that deduction guides are properly SFINAEd away. 2021-11-09 09:32:24 -08:00
version [libc++][NFC] Remove header name from <version> 2021-10-04 13:34:26 -04:00
wchar.h [libc++] Add an option to disable wide character support in libc++ 2021-10-12 06:08:23 -04:00
wctype.h [libc++] Add an option to disable wide character support in libc++ 2021-10-12 06:08:23 -04:00