Skip to content

Commit f8fe43f

Browse files
committed
fix
1 parent fb55ca3 commit f8fe43f

File tree

4 files changed

+19
-19
lines changed

4 files changed

+19
-19
lines changed

clang-tools-extra/clang-tidy/misc/UseInternalLinkageCheck.cpp

+8-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
//===--- UseInternalLinkageCheck.cpp - clang-tidy
2-
//---------------------------------===//
1+
//===--- UseInternalLinkageCheck.cpp - clang-tidy--------------------------===//
32
//
43
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
54
// See https://llvm.org/LICENSE.txt for license information.
@@ -13,6 +12,7 @@
1312
#include "clang/ASTMatchers/ASTMatchers.h"
1413
#include "clang/ASTMatchers/ASTMatchersMacros.h"
1514
#include "clang/Basic/Specifiers.h"
15+
#include "llvm/ADT/STLExtras.h"
1616

1717
using namespace clang::ast_matchers;
1818

@@ -27,11 +27,10 @@ AST_POLYMORPHIC_MATCHER(isFirstDecl,
2727
}
2828

2929
AST_MATCHER(Decl, isInMainFile) {
30-
for (const Decl *D : Node.redecls())
31-
if (!Finder->getASTContext().getSourceManager().isInMainFile(
32-
D->getLocation()))
33-
return false;
34-
return true;
30+
return llvm::all_of(Node.redecls(), [&](const Decl *D) {
31+
return Finder->getASTContext().getSourceManager().isInMainFile(
32+
D->getLocation());
33+
});
3534
}
3635

3736
AST_POLYMORPHIC_MATCHER(isExternStorageClass,
@@ -62,9 +61,8 @@ void UseInternalLinkageCheck::registerMatchers(MatchFinder *Finder) {
6261
}
6362

6463
static constexpr StringRef Message =
65-
"%0 %1 can be internal linkage, "
66-
"marking as static or using anonymous namespace can avoid external "
67-
"linkage.";
64+
"%0 %1 can be can be made static or moved into an anonymous namespace "
65+
"to enforce internal linkage.";
6866

6967
void UseInternalLinkageCheck::check(const MatchFinder::MatchResult &Result) {
7068
if (const auto *FD = Result.Nodes.getNodeAs<FunctionDecl>("fn")) {

clang-tools-extra/clang-tidy/misc/UseInternalLinkageCheck.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313

1414
namespace clang::tidy::misc {
1515

16-
/// Detects variable and function can be marked as static.
16+
/// Detects variables and functions that can be marked as static or moved into
17+
/// an anonymous namespace to enforce internal linkage.
1718
///
1819
/// For the user-facing documentation see:
1920
/// http://clang.llvm.org/extra/clang-tidy/checks/misc/use-internal-linkage.html

clang-tools-extra/docs/ReleaseNotes.rst

+6-5
Original file line numberDiff line numberDiff line change
@@ -145,17 +145,18 @@ New checks
145145
Finds initializer lists for aggregate types that could be
146146
written as designated initializers instead.
147147

148+
- New :doc:`misc-use-internal-linkage
149+
<clang-tidy/checks/misc/use-internal-linkage>` check.
150+
151+
Detects variables and functions that can be marked as static or moved into
152+
an anonymous namespace to enforce internal linkage.
153+
148154
- New :doc:`readability-enum-initial-value
149155
<clang-tidy/checks/readability/enum-initial-value>` check.
150156

151157
Enforces consistent style for enumerators' initialization, covering three
152158
styles: none, first only, or all initialized explicitly.
153159

154-
- New :doc:`misc-use-internal-linkage
155-
<clang-tidy/checks/misc/use-internal-linkage>` check.
156-
157-
Detects variable and function can be marked as static.
158-
159160
- New :doc:`readability-math-missing-parentheses
160161
<clang-tidy/checks/readability/math-missing-parentheses>` check.
161162

clang-tools-extra/docs/clang-tidy/checks/misc/use-internal-linkage.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
misc-use-internal-linkage
44
=========================
55

6-
Detects variable and function can be marked as static.
6+
Detects variables and functions that can be marked as static or moved into
7+
an anonymous namespace to enforce internal linkage.
78

89
Static functions and variables are scoped to a single file. Marking functions
910
and variables as static helps to better remove dead code. In addition, it gives
10-
the compiler more information and can help compiler make more aggressive
11-
optimizations.
11+
the compiler more information and allows for more aggressive optimizations.
1212

1313
Example:
1414

0 commit comments

Comments
 (0)