This is an archive of the discontinued LLVM Phabricator instance.

[libc++] Add clang-tidy check for version checks
ClosedPublic

Authored by philnik on Feb 17 2023, 5:27 AM.

Details

Reviewers
ldionne
Mordante
Group Reviewers
Restricted Project
Commits
rG07efa28314ce: [libc++] Add clang-tidy check for version checks
Summary

This check flags code which uses _LIBCPP_STD_VER the wrong way, or tries to use __cplusplus. It flags cases where we use _LIBCPP_STD_VER > instead of _LIBCPP_STD_VER >= and where wrong values are used (e.g. _LIBCPP_STD_VER >= 24).

Diff Detail

Event Timeline

philnik created this revision.Feb 17 2023, 5:27 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 17 2023, 5:27 AM
philnik requested review of this revision.Feb 17 2023, 5:27 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 17 2023, 5:27 AM
Herald added a reviewer: Restricted Project. · View Herald Transcript

Are we running clang-tidy only on our headers or also on our test suite?

libcxx/test/tools/clang_tidy_checks/CMakeLists.txt
6–15

This should be 16 for the CI. IIRC 17 is not installed by the CI.
I ran issues with this while testing locally with Clang-tidy, I am looking at the issue where cmake fails to run a second time and I have a solution, but I want to test a bit further before making a patch.

Are we running clang-tidy only on our headers or also on our test suite?

Only in our headers currently, not even in src/.

libcxx/test/tools/clang_tidy_checks/CMakeLists.txt
6–15

This diff shouldn't be here. The problem is that find_package(Clang 16...17) isn't "use Clang version 16 or 17", like one would expect. I'm not sure what it actually is, but AFAICT we have to use

find_package(Clang 16)
if (NOT Clang_FOUND)
  find_package(Clang 17)
endif()

to fix this.

LGTM, but I like to see the CI green before approving.

libcxx/test/tools/clang_tidy_checks/CMakeLists.txt
6–15

I have a fix for running CMake twice and can address this issue in the same patch, so let's revert this hunk in this patch.

ldionne accepted this revision.Mar 6 2023, 8:12 AM

LGTM w/ green CI. Please also provide a short description of the check being added in the commit message. Add clang-tidy check for version checks is not self-explanatory.

This revision is now accepted and ready to land.Mar 6 2023, 8:12 AM
philnik edited the summary of this revision. (Show Details)Mar 7 2023, 8:07 AM
philnik updated this revision to Diff 503053.Mar 7 2023, 8:09 AM
philnik marked an inline comment as done.

Rebased

This revision was automatically updated to reflect the committed changes.