-
Notifications
You must be signed in to change notification settings - Fork 15k
[clang-tidy] Add -std
argument in check_clang_tidy.py
for C files
#150791
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
20eb165
[clang-tidy] Stop ignoring `-std` argument in `check_clang_tidy.py` f…
localspook 216c2e8
`c23` -> `c23-or-later`
localspook ef0f044
Address feedback
localspook 0034ea6
Address feedback
localspook c51450c
Reduce whitespace
localspook eea0f21
Merge branch 'main' into c-std
localspook 0b5bb05
Remove more whitespace
localspook File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,8 @@ | |
|
||
// Special system calls. | ||
|
||
#if __STDC_VERSION__ < 202311L | ||
void other_call(); | ||
#endif | ||
|
||
#endif // _SYSTEM_OTHER_H_ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 5 additions & 5 deletions
10
clang-tools-extra/test/clang-tidy/checkers/bugprone/branch-clone-macro-crash.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...a/test/clang-tidy/checkers/bugprone/not-null-terminated-result-in-initialization-strlen.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...s-extra/test/clang-tidy/checkers/bugprone/not-null-terminated-result-memcpy-before-safe.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
clang-tools-extra/test/clang-tidy/checkers/bugprone/not-null-terminated-result-memcpy-safe.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...lang-tidy/checkers/bugprone/not-null-terminated-result-stdc-want-lib-ext1-not-a-literal.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
clang-tools-extra/test/clang-tidy/checkers/bugprone/not-null-terminated-result-strlen.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...a/test/clang-tidy/checkers/bugprone/not-null-terminated-result-undef-stdc-want-lib-ext1.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
clang-tools-extra/test/clang-tidy/checkers/bugprone/signed-char-misuse-c23.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
clang-tools-extra/test/clang-tidy/checkers/bugprone/sizeof-expression.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
clang-tools-extra/test/clang-tidy/checkers/misc/static-assert.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 6 additions & 2 deletions
8
clang-tools-extra/test/clang-tidy/checkers/misc/unused-parameters.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,23 @@ | ||
// RUN: %check_clang_tidy %s misc-unused-parameters %t -- -- -Wno-strict-prototypes -xc | ||
// RUN: %check_clang_tidy %s misc-unused-parameters %t -- -- -Wno-strict-prototypes | ||
|
||
// Basic removal | ||
// ============= | ||
void a(int i) {;} | ||
// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: parameter 'i' is unused [misc-unused-parameters] | ||
// CHECK-FIXES: {{^}}void a(int i) {;}{{$}} | ||
|
||
static void b(); // In C, forward declarations can leave out parameters. | ||
#if __STDC_VERSION__ < 202311L | ||
static void b(); // In C before C23, forward declarations can leave out parameters. | ||
#endif | ||
static void b(int i) {;} | ||
// CHECK-MESSAGES: :[[@LINE-1]]:19: warning: parameter 'i' is unused [misc-unused-parameters] | ||
// CHECK-FIXES: {{^}}static void b() {;}{{$}} | ||
|
||
// Unchanged cases | ||
// =============== | ||
#if __STDC_VERSION__ < 202311L | ||
void h(i, c, d) int i; char *c, *d; {} // Don't mess with K&R style | ||
#endif | ||
|
||
// Do not warn on naked functions. | ||
__attribute__((naked)) void nakedFunction(int a, int b) { ; } |
2 changes: 1 addition & 1 deletion
2
clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr-c23.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 1 addition & 2 deletions
3
clang-tools-extra/test/clang-tidy/checkers/readability/bitint-no-crash.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
// RUN: %check_clang_tidy %s readability-magic-numbers %t -- | ||
// RUN: %check_clang_tidy -std=c23-or-later %s readability-magic-numbers %t | ||
|
||
// Don't crash | ||
|
||
_BitInt(128) A = 4533629751480627964421wb; | ||
// CHECK-MESSAGES: warning | ||
vbvictor marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm only a little worried since C++ headers may also be
.h
(even though Clang-Tidy is not supposed to be run directly on headers anyway -- I think it can still happen in some cases). What do you think?Some C++ projects also use
.cxx
, what happens then? Will this list need to stay updated for all common possible C++ file extensions?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In those cases, the tests will break if they don't specify
-std
. The script will try to invoke something likeclang foo.cxx -std=c99
, which will error out, saying that you can't specify a C standard for a C++ file. Same thing with C++.h
files, but note that in that case, users already have to specify-x c++
, because clang won't understand that this is a C++ file otherwise. We'll need to keep the list updated if we want the default behaviour to Just Work (I could update this PR to add some extensions).(Also, I think my PR description was a bit misleading, so I want to be clear;
-std
being ignored is a problem that applies not just to C, but to any file with an extension other than.cpp
,.hpp
, or.mm
.)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense, thanks!
I also think I misread this the first time and thought it applied more broadly.