[clang-tools-extra] 987a215 - [clang-tidy] Use `hasCanonicalType()` matcher in `bugprone-unused-raii` check
Fabian Wolff via cfe-commits
cfe-commits at lists.llvm.org
Wed Dec 1 16:54:08 PST 2021
Author: Fabian Wolff
Date: 2021-12-02T01:53:12+01:00
New Revision: 987a21522f2c7d799d0c2a720b3315a4fb6d1e74
URL: https://github.com/llvm/llvm-project/commit/987a21522f2c7d799d0c2a720b3315a4fb6d1e74
DIFF: https://github.com/llvm/llvm-project/commit/987a21522f2c7d799d0c2a720b3315a4fb6d1e74.diff
LOG: [clang-tidy] Use `hasCanonicalType()` matcher in `bugprone-unused-raii` check
Fixes PR#52217.
Reviewed By: simon.giesecke
Differential Revision: https://reviews.llvm.org/D113429
Added:
Modified:
clang-tools-extra/clang-tidy/bugprone/UnusedRaiiCheck.cpp
clang-tools-extra/test/clang-tidy/checkers/bugprone-unused-raii.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clang-tidy/bugprone/UnusedRaiiCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/UnusedRaiiCheck.cpp
index 9b8d8d7bf5f4c..435c47348c7c0 100644
--- a/clang-tools-extra/clang-tidy/bugprone/UnusedRaiiCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/UnusedRaiiCheck.cpp
@@ -29,10 +29,11 @@ void UnusedRaiiCheck::registerMatchers(MatchFinder *Finder) {
Finder->addMatcher(
mapAnyOf(cxxConstructExpr, cxxUnresolvedConstructExpr)
.with(hasParent(compoundStmt().bind("compound")),
- anyOf(hasType(cxxRecordDecl(hasNonTrivialDestructor())),
- hasType(templateSpecializationType(
+ anyOf(hasType(hasCanonicalType(recordType(hasDeclaration(
+ cxxRecordDecl(hasNonTrivialDestructor()))))),
+ hasType(hasCanonicalType(templateSpecializationType(
hasDeclaration(classTemplateDecl(has(
- cxxRecordDecl(hasNonTrivialDestructor()))))))))
+ cxxRecordDecl(hasNonTrivialDestructor())))))))))
.bind("expr"),
this);
}
diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone-unused-raii.cpp b/clang-tools-extra/test/clang-tidy/checkers/bugprone-unused-raii.cpp
index 94643676f45ce..1b285768fdb33 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/bugprone-unused-raii.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone-unused-raii.cpp
@@ -82,6 +82,28 @@ void templatetest() {
(void)i;
}
+template <typename T>
+void aliastest() {
+ using X = Foo;
+ using Y = X;
+ using Z = Y;
+ Z(42);
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: object destroyed immediately after creation; did you mean to name the object?
+ // CHECK-FIXES: Z give_me_a_name(42);
+
+ typedef Z ZT;
+ ZT(42, 13);
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: object destroyed immediately after creation; did you mean to name the object?
+ // CHECK-FIXES: ZT give_me_a_name(42, 13);
+
+ using TT = TCtorDefaultArg<T>;
+ TT(42);
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: object destroyed immediately after creation; did you mean to name the object?
+ // CHECK-FIXES: TT give_me_a_name(42);
+
+ (void)0;
+}
+
void test() {
Foo(42);
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: object destroyed immediately after creation; did you mean to name the object?
More information about the cfe-commits
mailing list