Skip to content

Commit d1a24ba

Browse files
committed
[clang-tidy] Fix the potential infinite loop in recordIsTriviallyDefaultConstructible.
Summary: The recordIsTriviallyDefaultConstructible may cause an infinite loop when running on an ill-formed decl. Reviewers: gribozavr Subscribers: nemanjai, xazax.hun, kbarton, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D66874 llvm-svn: 370200
1 parent 4046e1e commit d1a24ba

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

clang-tools-extra/clang-tidy/utils/TypeTraits.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ bool recordIsTriviallyDefaultConstructible(const RecordDecl &RecordDecl,
5454
// Non-C++ records are always trivially constructible.
5555
if (!ClassDecl)
5656
return true;
57+
// It is impossible to detemine whether an ill-formed decl is trivially
58+
// constructible.
59+
if (RecordDecl.isInvalidDecl())
60+
return false;
5761
// A class with a user-provided default constructor is not trivially
5862
// constructible.
5963
if (ClassDecl->hasUserProvidedDefaultConstructor())
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// RUN: %check_clang_tidy -expect-clang-tidy-error %s cppcoreguidelines-pro-type-member-init %t
2+
3+
struct X {
4+
X x;
5+
// CHECK-MESSAGES: :[[@LINE-1]]:5: error: field has incomplete type 'X' [clang-diagnostic-error]
6+
int a = 10;
7+
};

0 commit comments

Comments
 (0)