Skip to content

Commit 82eb9bf

Browse files
authored
Merge pull request #55 from rianquinn/bsl-tidy
Fix bugs and add some additional checks
2 parents 001f157 + f5eb552 commit 82eb9bf

File tree

56 files changed

+4666
-979
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+4666
-979
lines changed

clang-tools-extra/clang-tidy/bsl/AssignOpDeclRefQualifierCheck.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,23 @@ namespace tidy {
1717
namespace bsl {
1818

1919
void AssignOpDeclRefQualifierCheck::registerMatchers(MatchFinder *Finder) {
20-
Finder->addMatcher(cxxMethodDecl(hasAnyOverloadedOperatorName(
21-
"=", "+=", "-=", "*=", "/=", "%=", "^=",
22-
"&=", "|=", ">>=", "<<="))
23-
.bind("assign"),
24-
this);
20+
Finder->addMatcher(
21+
cxxMethodDecl(
22+
hasAnyOverloadedOperatorName("=", "+=", "-=", "*=", "/=", "%=", "^=", "&=", "|=", ">>=", "<<="),
23+
unless(
24+
isImplicit()
25+
)
26+
).bind("assign"),
27+
this
28+
);
2529
}
2630

2731
void AssignOpDeclRefQualifierCheck::check(
2832
const MatchFinder::MatchResult &Result) {
2933
const auto *MatchedDecl = Result.Nodes.getNodeAs<CXXMethodDecl>("assign");
30-
if (MatchedDecl->getRefQualifier() == RQ_LValue)
31-
return;
32-
diag(MatchedDecl->getLocation(),
33-
"assignment operators should be declared with the ref-qualifier &");
34+
if (MatchedDecl->getRefQualifier() == RQ_None)
35+
diag(MatchedDecl->getLocation(),
36+
"assignment operators should be declared with the ref-qualifier &");
3437
}
3538

3639
} // namespace bsl

clang-tools-extra/clang-tidy/bsl/AutoTypeUsageCheck.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ void AutoTypeUsageCheck::registerMatchers(MatchFinder *Finder) {
2727
valueDecl(hasType(autoType()), hasDescendant(cxxStdInitializerListExpr()))
2828
.bind("list"),
2929
this);
30-
30+
3131
Finder->addMatcher(valueDecl(hasType(autoType()), isFundamentalType(),
3232
unless(has(callExpr())))
3333
.bind("decl"),
@@ -52,7 +52,7 @@ void AutoTypeUsageCheck::check(const MatchFinder::MatchResult &Result) {
5252
"auto cannot be used to declare variable of fundamental type");
5353

5454
const auto *MatchedTempDecl = Result.Nodes.getNodeAs<FunctionDecl>("trail");
55-
if (MatchedTempDecl) {
55+
if (MatchedTempDecl && !MatchedTempDecl->getReturnType()->isVoidType()) {
5656
if (isa<CXXMethodDecl>(MatchedTempDecl)) {
5757
if (!cast<CXXMethodDecl>(MatchedTempDecl)->isLambdaStaticInvoker())
5858
diag(MatchedTempDecl->getLocation(),

clang-tools-extra/clang-tidy/bsl/BslTidyModule.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@
2222
#include "ConstObjStdMoveCheck.h"
2323
#include "DeclForbiddenCheck.h"
2424
#include "DestructorAccessSpecifierCheck.h"
25+
#include "DocumentationCheck.h"
2526
#include "ElseRequiredAfterIfCheck.h"
27+
#include "EmptyIfElseCheck.h"
2628
#include "EnumExplicitCheck.h"
2729
#include "EnumInitCheck.h"
2830
#include "EnumScopedCheck.h"
@@ -32,17 +34,21 @@
3234
#include "FunctionNameUseCheck.h"
3335
#include "FunctionNoexceptCheck.h"
3436
#include "IdentifierTypographicallyUnambiguousCheck.h"
37+
#include "ImplicitConversionsForbiddenCheck.h"
3538
#include "LambdaImplicitCaptureCheck.h"
3639
#include "LambdaParamListCheck.h"
3740
#include "LiteralsAsciiOnlyCheck.h"
3841
#include "LiteralsDigitSeparatorCheck.h"
3942
#include "LiteralsNoOctalCheck.h"
4043
#include "LiteralsUnsignedSuffixCheck.h"
4144
#include "LiteralsUserDefinedCheck.h"
45+
#include "NameCaseCheck.h"
46+
#include "NamePrefixesCheck.h"
4247
#include "NamespaceGlobalCheck.h"
4348
#include "NodiscardCheck.h"
4449
#include "NonPodClassdefCheck.h"
4550
#include "NonPodStaticCheck.h"
51+
#include "NonSafeIntegralTypesAreForbiddenCheck.h"
4652
#include "OpBitwiseOperandsCheck.h"
4753
#include "OpConditionalSubexprCheck.h"
4854
#include "OpEqualityVirtMemfnNullptrCheck.h"
@@ -62,8 +68,10 @@
6268
#include "TypesFixedWidthIntsCheck.h"
6369
#include "TypesNoWideCharCheck.h"
6470
#include "UnusedReturnValueCheck.h"
71+
#include "UserDefinedTypeNamesMatchHeaderNameCheck.h"
6572
#include "UsingDeclScopeCheck.h"
6673
#include "UsingIdentUniqueNamespaceCheck.h"
74+
#include "UsingNamespaceForbiddenCheck.h"
6775
#include "VarBracedInitCheck.h"
6876

6977
namespace clang {
@@ -99,8 +107,12 @@ class BslModule : public ClangTidyModule {
99107
"bsl-decl-forbidden");
100108
CheckFactories.registerCheck<DestructorAccessSpecifierCheck>(
101109
"bsl-destructor-access-specifier");
110+
CheckFactories.registerCheck<DocumentationCheck>(
111+
"bsl-documentation");
102112
CheckFactories.registerCheck<ElseRequiredAfterIfCheck>(
103113
"bsl-else-required-after-if");
114+
CheckFactories.registerCheck<EmptyIfElseCheck>(
115+
"bsl-empty-if-else");
104116
CheckFactories.registerCheck<EnumExplicitCheck>(
105117
"bsl-enum-explicit");
106118
CheckFactories.registerCheck<EnumInitCheck>(
@@ -119,6 +131,8 @@ class BslModule : public ClangTidyModule {
119131
"bsl-function-noexcept");
120132
CheckFactories.registerCheck<IdentifierTypographicallyUnambiguousCheck>(
121133
"bsl-identifier-typographically-unambiguous");
134+
CheckFactories.registerCheck<ImplicitConversionsForbiddenCheck>(
135+
"bsl-implicit-conversions-forbidden");
122136
CheckFactories.registerCheck<LambdaImplicitCaptureCheck>(
123137
"bsl-lambda-implicit-capture");
124138
CheckFactories.registerCheck<LambdaParamListCheck>(
@@ -127,6 +141,10 @@ class BslModule : public ClangTidyModule {
127141
"bsl-literals-digit-separator");
128142
CheckFactories.registerCheck<LiteralsUserDefinedCheck>(
129143
"bsl-literals-user-defined");
144+
CheckFactories.registerCheck<NameCaseCheck>(
145+
"bsl-name-case");
146+
CheckFactories.registerCheck<NamePrefixesCheck>(
147+
"bsl-name-prefixes");
130148
CheckFactories.registerCheck<NamespaceGlobalCheck>(
131149
"bsl-namespace-global");
132150
CheckFactories.registerCheck<NodiscardCheck>(
@@ -135,6 +153,8 @@ class BslModule : public ClangTidyModule {
135153
"bsl-non-pod-classdef");
136154
CheckFactories.registerCheck<NonPodStaticCheck>(
137155
"bsl-non-pod-static");
156+
CheckFactories.registerCheck<NonSafeIntegralTypesAreForbiddenCheck>(
157+
"bsl-non-safe-integral-types-are-forbidden");
138158
CheckFactories.registerCheck<OpBitwiseOperandsCheck>(
139159
"bsl-op-bitwise-operands");
140160
CheckFactories.registerCheck<OpConditionalSubexprCheck>(
@@ -179,10 +199,14 @@ class BslModule : public ClangTidyModule {
179199
"bsl-types-no-wide-char");
180200
CheckFactories.registerCheck<UnusedReturnValueCheck>(
181201
"bsl-unused-return-value");
202+
CheckFactories.registerCheck<UserDefinedTypeNamesMatchHeaderNameCheck>(
203+
"bsl-user-defined-type-names-match-header-name");
182204
CheckFactories.registerCheck<UsingDeclScopeCheck>(
183205
"bsl-using-decl-scope");
184206
CheckFactories.registerCheck<UsingIdentUniqueNamespaceCheck>(
185207
"bsl-using-ident-unique-namespace");
208+
CheckFactories.registerCheck<UsingNamespaceForbiddenCheck>(
209+
"bsl-using-namespace-forbidden");
186210
CheckFactories.registerCheck<VarBracedInitCheck>(
187211
"bsl-var-braced-init");
188212
}

clang-tools-extra/clang-tidy/bsl/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ add_clang_library(clangTidyBslModule
1616
ConstObjStdMoveCheck.cpp
1717
DeclForbiddenCheck.cpp
1818
DestructorAccessSpecifierCheck.cpp
19+
DocumentationCheck.cpp
1920
ElseRequiredAfterIfCheck.cpp
21+
EmptyIfElseCheck.cpp
2022
EnumExplicitCheck.cpp
2123
EnumInitCheck.cpp
2224
EnumScopedCheck.cpp
@@ -26,17 +28,21 @@ add_clang_library(clangTidyBslModule
2628
FunctionNameUseCheck.cpp
2729
FunctionNoexceptCheck.cpp
2830
IdentifierTypographicallyUnambiguousCheck.cpp
31+
ImplicitConversionsForbiddenCheck.cpp
2932
LambdaImplicitCaptureCheck.cpp
3033
LambdaParamListCheck.cpp
3134
LiteralsAsciiOnlyCheck.cpp
3235
LiteralsDigitSeparatorCheck.cpp
3336
LiteralsNoOctalCheck.cpp
3437
LiteralsUnsignedSuffixCheck.cpp
3538
LiteralsUserDefinedCheck.cpp
39+
NameCaseCheck.cpp
40+
NamePrefixesCheck.cpp
3641
NamespaceGlobalCheck.cpp
3742
NodiscardCheck.cpp
3843
NonPodClassdefCheck.cpp
3944
NonPodStaticCheck.cpp
45+
NonSafeIntegralTypesAreForbiddenCheck.cpp
4046
OpBitwiseOperandsCheck.cpp
4147
OpConditionalSubexprCheck.cpp
4248
OpEqualityVirtMemfnNullptrCheck.cpp
@@ -56,8 +62,10 @@ add_clang_library(clangTidyBslModule
5662
TypesFixedWidthIntsCheck.cpp
5763
TypesNoWideCharCheck.cpp
5864
UnusedReturnValueCheck.cpp
65+
UserDefinedTypeNamesMatchHeaderNameCheck.cpp
5966
UsingDeclScopeCheck.cpp
6067
UsingIdentUniqueNamespaceCheck.cpp
68+
UsingNamespaceForbiddenCheck.cpp
6169
VarBracedInitCheck.cpp
6270

6371
LINK_LIBS

clang-tools-extra/clang-tidy/bsl/DestructorAccessSpecifierCheck.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ namespace clang {
1616
namespace tidy {
1717
namespace bsl {
1818

19+
AST_MATCHER(CXXDestructorDecl, isUnion) {
20+
return Node.getParent()->isUnion();
21+
}
22+
1923
AST_MATCHER(CXXDestructorDecl, isPublicVirtual) {
2024
return Node.getAccess() == AS_public && Node.isVirtual();
2125
}
@@ -25,10 +29,17 @@ AST_MATCHER(CXXDestructorDecl, isProtectedNonVirtual) {
2529
}
2630

2731
void DestructorAccessSpecifierCheck::registerMatchers(MatchFinder *Finder) {
28-
Finder->addMatcher(cxxDestructorDecl(unless(anyOf(isPublicVirtual(),
29-
isProtectedNonVirtual())))
30-
.bind("destructor"),
31-
this);
32+
Finder->addMatcher(
33+
cxxDestructorDecl(
34+
unless(
35+
anyOf(
36+
isUnion(),
37+
isPublicVirtual(),
38+
isProtectedNonVirtual()
39+
)
40+
)
41+
).bind("destructor"),
42+
this);
3243
}
3344

3445
void DestructorAccessSpecifierCheck::check(

0 commit comments

Comments
 (0)