This is an archive of the discontinued LLVM Phabricator instance.

[clang-tidy] Add a useful note about -std=c++11-or-later
ClosedPublic

Authored by steakhal on May 17 2022, 6:09 AM.

Details

Summary

I and @whisperity spent some time debugging a LIT test case using the
-std=c++11-or-later check_clang_tidy.py flag when the test had
fixits.

It turns out if the test wants to report a diagnostic into a header
file AND into the test file as well, one needs to first copy the header
somewhere under the build directory.
It needs to be copied since clang-tidy sorts the reports into
alphabetical order, thus to have a deterministic order relative to the
diagnostic in the header AND the diagnostic in the test cpp file.

There is more to this story.

The -std=c++11-or-later turns out executes the test with multiple
-std=XX version substitution and each execution will also have the
-fix tidy parameter. This means that the freshly copied header file I
stated in the previous paragraph gets fixed up and the very next tidy
execution will fail miserably.

Following @whisperity's advice, I'm leaving a reminder about such
shared state in the related doc comment.

Diff Detail

Event Timeline

steakhal created this revision.May 17 2022, 6:09 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 17 2022, 6:09 AM
steakhal requested review of this revision.May 17 2022, 6:09 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 17 2022, 6:09 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
martong added inline comments.May 17 2022, 6:32 AM
clang-tools-extra/test/clang-tidy/check_clang_tidy.py
31

typo

steakhal updated this revision to Diff 430069.May 17 2022, 8:14 AM
steakhal marked an inline comment as done.

fix typo withing -> within

I thought there wasn't any support for validating fixits applied to header files?

I thought there wasn't any support for validating fixits applied to header files?

It is not specifically about the fixits, but diagnostics as a whole. It was not clear that if you say -std=c++11-or-later it will actually run multiple executions without giving you the ability to observe the contents of the files.

Technically, you can always match a diagnostic that is positioned into a header from the TU that is producing that diagnostic, because // CHECK-MESSAGES: does a regular expression-like matching. For example, misc-unused-parameters does the following:

#include "header.h"
// CHECK-MESSAGES: header.h:1:38: warning

And because LIT can execute arbitrary commands, you can always go about your way running FileCheck and everything else manually.

But it is good to be reminded early on that -or-later will result in execution of potentially changed code outside of your (test file's) control. Saves the debugging time which we had to endure!

Tbh the whole testing infrastructure for clang-tidy is a mess. When I have wanted to verify fixes and diagnostics for header files, I find manually invoking clang-tidy is better than using the check_clang_tidy script.
I don't have the time right now, but a verify mode like with clang is something that we should move to in the future.

Tbh the whole testing infrastructure for clang-tidy is a mess. When I have wanted to verify fixes and diagnostics for header files, I find manually invoking clang-tidy is better than using the check_clang_tidy script.
I don't have the time right now, but a verify mode like with clang is something that we should move to in the future.

I had a change, literally years ago at this point, that provided support for verifying header files, but it got bogged down in review nits and never landed.

clang-tools-extra/test/clang-tidy/check_clang_tidy.py
22

These aren't the only two valid options for this argument.... Valid values are:

  • c++98-or-later
  • c++11-or-later
  • c++14-or-later
  • c++17-or-later
  • c++20-or-later

and of course all the specific standard versions:

  • c++98
  • c++11
  • c++14
  • c++17
  • c++20
30

Probably need to explain the -or-later argument option more generally here and not just for C++11

steakhal updated this revision to Diff 431028.May 20 2022, 12:40 PM
steakhal marked 2 inline comments as done.

Generalized the flag help text to all supported standard versions.

clang-tools-extra/test/clang-tidy/check_clang_tidy.py
31

It's only the -or-later variants that cause multiple runs, so we should explain this more explicitly.

steakhal updated this revision to Diff 431141.May 21 2022, 9:00 AM
steakhal marked an inline comment as done.

Make the note more precise.

clang-tools-extra/test/clang-tidy/check_clang_tidy.py
31

Oh, true!

This revision is now accepted and ready to land.May 21 2022, 1:01 PM

Thanks for the review, sorry about the mistakes I made on this trivial change.

This revision was automatically updated to reflect the committed changes.