Skip to content

Commit 0bac7e0

Browse files
committed
[libc++][CI] Reenables clang-tidy.
This is currently a test patch; locally clang-tidy seems to be used in the Docker image.
1 parent 1a2a1fb commit 0bac7e0

File tree

5 files changed

+47
-11
lines changed

5 files changed

+47
-11
lines changed

libcxx/modules/std/chrono.inc

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,11 @@ export namespace std {
190190
using std::chrono::make12;
191191
using std::chrono::make24;
192192

193-
#if !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM) && \
194-
!defined(_LIBCPP_HAS_NO_LOCALIZATION)
193+
#ifdef _LIBCPP_ENABLE_EXPERIMENTAL
194+
195+
# if !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM) && \
196+
!defined(_LIBCPP_HAS_NO_LOCALIZATION)
195197

196-
# ifdef _LIBCPP_ENABLE_EXPERIMENTAL
197198
// [time.zone.db], time zone database
198199
using std::chrono::tzdb;
199200
using std::chrono::tzdb_list;
@@ -213,11 +214,16 @@ export namespace std {
213214
using std::chrono::ambiguous_local_time;
214215
using std::chrono::nonexistent_local_time;
215216
# endif // if 0
217+
# endif // !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM) &&
218+
// !defined(_LIBCPP_HAS_NO_LOCALIZATION)
216219

217220
// [time.zone.info], information classes
218221
using std::chrono::local_info;
219222
using std::chrono::sys_info;
220223

224+
# if !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM) && \
225+
!defined(_LIBCPP_HAS_NO_LOCALIZATION)
226+
221227
# if 0
222228
// [time.zone.timezone], class time_zone
223229
using std::chrono::choose;
@@ -246,9 +252,9 @@ export namespace std {
246252
// [time.format], formatting
247253
using std::chrono::local_time_format;
248254
# endif
249-
# endif // _LIBCPP_ENABLE_EXPERIMENTAL
250-
#endif // !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM) &&
251-
// !defined(_LIBCPP_HAS_NO_LOCALIZATION)
255+
# endif // !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM) &&
256+
// !defined(_LIBCPP_HAS_NO_LOCALIZATION)
257+
#endif // _LIBCPP_ENABLE_EXPERIMENTAL
252258

253259
} // namespace chrono
254260

libcxx/modules/std/ranges.inc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,6 @@ export namespace std {
138138
}
139139
#endif // _LIBCPP_HAS_NO_LOCALIZATION
140140

141-
#if _LIBCPP_STD_VER >= 23
142-
// [range.adaptor.object], range adaptor objects
143-
using std::ranges::range_adaptor_closure;
144141
// Note: This declaration not in the synopsis or explicitly in the wording.
145142
// However it is needed for the range adaptors.
146143
// [range.adaptor.object]/3
@@ -151,7 +148,11 @@ export namespace std {
151148
// involving an object of type cv D as an operand to the | operator is
152149
// undefined if overload resolution selects a program-defined operator|
153150
// function.
151+
// This is used internally in C++20 mode.
154152
using std::ranges::operator|;
153+
#if _LIBCPP_STD_VER >= 23
154+
// [range.adaptor.object], range adaptor objects
155+
using std::ranges::range_adaptor_closure;
155156
#endif
156157

157158
// [range.all], all view

libcxx/test/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
include(HandleLitArguments)
22
add_subdirectory(tools)
3+
# When the tools add clang-tidy support, the dependencies need to be updated.
4+
# This cannot be done in the tools CMakeLists.txt since that does not update
5+
# the status in this (a parent) directory.
6+
if(TARGET cxx-tidy)
7+
list(APPEND LIBCXX_TEST_DEPS cxx-tidy)
8+
endif()
39

410
# By default, libcxx and libcxxabi share a library directory.
511
if (NOT LIBCXX_CXX_ABI_LIBRARY_PATH)

libcxx/test/libcxx/clang_tidy.gen.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
// The GCC compiler flags are not always compatible with clang-tidy.
2727
// UNSUPPORTED: gcc
2828
29+
// Clang 17 has false positives.
30+
// UNSUPPORTED: clang-17
31+
2932
{lit_header_restrictions.get(header, '')}
3033
3134
// TODO: run clang-tidy with modules enabled once they are supported

libcxx/test/tools/clang_tidy_checks/CMakeLists.txt

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,28 @@ if(NOT HAS_CLANG_TIDY_HEADERS)
6464
"clang-tidy headers are not present.")
6565
return()
6666
endif()
67+
68+
# The clangTidy plugin uses C++20, so ensure that we support C++20 when using libstdc++.
69+
# This is required because some versions of libstdc++ used as a system library on build platforms
70+
# we support do not support C++20 yet.
71+
# Note it has not been tested whether version 11 works.
72+
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/test.cpp" "
73+
#include <version>
74+
#if defined(_GLIBCXX_RELEASE) && _GLIBCXX_RELEASE < 12
75+
# error The libstdc++ version is too old.
76+
#endif
77+
int main(){}
78+
")
79+
try_compile(HAS_NEWER_STANDARD_LIBRARY
80+
"${CMAKE_CURRENT_BINARY_DIR}"
81+
"${CMAKE_CURRENT_BINARY_DIR}/test.cpp"
82+
LINK_LIBRARIES clangTidy)
83+
84+
if(NOT HAS_NEWER_STANDARD_LIBRARY)
85+
message(STATUS "Clang-tidy tests are disabled due to using "
86+
"stdlibc++ older than version 12")
87+
return()
88+
endif()
6789
message(STATUS "Clang-tidy tests are enabled.")
6890

6991
set(SOURCES
@@ -88,5 +110,3 @@ set_target_properties(cxx-tidy PROPERTIES
88110

89111
set_target_properties(cxx-tidy PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
90112
set(CMAKE_SHARED_MODULE_SUFFIX_CXX .plugin) # Use a portable suffix to simplify how we can find it from Lit
91-
92-
list(APPEND LIBCXX_TEST_DEPS cxx-tidy)

0 commit comments

Comments
 (0)