[clang-tools-extra] [clang-tidy] Fix crash in modernize-use-designated-initializers check (PR #113688)

via cfe-commits cfe-commits at lists.llvm.org
Fri Oct 25 08:55:34 PDT 2024


https://github.com/z1nke updated https://github.com/llvm/llvm-project/pull/113688

>From a2184027393c9e9605aaa08f1d1eef4b11cd9be1 Mon Sep 17 00:00:00 2001
From: czn <iamczn.cpp at gmail.com>
Date: Fri, 25 Oct 2024 21:48:50 +0800
Subject: [PATCH 1/2] [clang-tidy] Fix crash in
 modernize-use-designated-initializers check

---
 .../modernize/UseDesignatedInitializersCheck.cpp          | 8 ++++++--
 .../checkers/modernize/use-designated-initializers.cpp    | 8 ++++++++
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/modernize/UseDesignatedInitializersCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseDesignatedInitializersCheck.cpp
index 2a0cc403b726e8..3132067f3d5ece 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseDesignatedInitializersCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseDesignatedInitializersCheck.cpp
@@ -80,9 +80,13 @@ unsigned getNumberOfDesignated(const InitListExpr *SyntacticInitList) {
   });
 }
 
-AST_MATCHER(CXXRecordDecl, isAggregate) { return Node.isAggregate(); }
+AST_MATCHER(CXXRecordDecl, isAggregate) {
+  return Node.hasDefinition() && Node.isAggregate();
+}
 
-AST_MATCHER(CXXRecordDecl, isPOD) { return Node.isPOD(); }
+AST_MATCHER(CXXRecordDecl, isPOD) {
+  return Node.hasDefinition() && Node.isPOD();
+}
 
 AST_MATCHER(InitListExpr, isFullyDesignated) {
   if (const InitListExpr *SyntacticForm =
diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-designated-initializers.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-designated-initializers.cpp
index 9b769ad0be23ca..db1fe3baa99d7c 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-designated-initializers.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-designated-initializers.cpp
@@ -201,3 +201,11 @@ DECLARE_S93;
 // CHECK-MESSAGES-MACROS: :[[@LINE-1]]:1: warning: use designated initializer list to initialize 'S9' [modernize-use-designated-initializers]
 // CHECK-MESSAGES-MACROS: :[[@LINE-4]]:28: note: expanded from macro 'DECLARE_S93'
 // CHECK-MESSAGES-MACROS: :[[@LINE-71]]:1: note: aggregate type is defined here
+
+// Issus #113652.
+struct S14;
+
+struct S15{
+  S15(S14& d):d{d}{}
+  S14& d;
+};
\ No newline at end of file

>From 2bff90592868f3ecd728510408d8c78dbd5f605e Mon Sep 17 00:00:00 2001
From: czn <iamczn.cpp at gmail.com>
Date: Fri, 25 Oct 2024 23:55:20 +0800
Subject: [PATCH 2/2] [clang-tidy] Fix typo

---
 .../checkers/modernize/use-designated-initializers.cpp        | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-designated-initializers.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-designated-initializers.cpp
index db1fe3baa99d7c..048665b2e54ac5 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-designated-initializers.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-designated-initializers.cpp
@@ -202,10 +202,10 @@ DECLARE_S93;
 // CHECK-MESSAGES-MACROS: :[[@LINE-4]]:28: note: expanded from macro 'DECLARE_S93'
 // CHECK-MESSAGES-MACROS: :[[@LINE-71]]:1: note: aggregate type is defined here
 
-// Issus #113652.
+// Issue #113652.
 struct S14;
 
 struct S15{
   S15(S14& d):d{d}{}
   S14& d;
-};
\ No newline at end of file
+};



More information about the cfe-commits mailing list