Skip to content

Commit 5c78e2a

Browse files
committed
fold false C++20 branch into isLiteralType function
1 parent 3faa5be commit 5c78e2a

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

clang-tools-extra/clang-tidy/modernize/UseConstexprCheck.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "UseConstexprCheck.h"
1010
#include "../utils/ASTUtils.h"
1111
#include "../utils/LexerUtils.h"
12+
#include "clang/AST/Decl.h"
1213
#include "clang/AST/RecursiveASTVisitor.h"
1314
#include "clang/ASTMatchers/ASTMatchers.h"
1415
#include "llvm/ADT/STLExtras.h"
@@ -141,6 +142,17 @@ static bool isLiteralType(const Type *T, const ASTContext &Ctx,
141142
return true;
142143

143144
if (const CXXRecordDecl *Rec = T->getAsCXXRecordDecl()) {
145+
if (!Rec->hasDefinition())
146+
return false;
147+
148+
if (!Rec->hasTrivialDestructor())
149+
return false;
150+
151+
if (!llvm::all_of(Rec->fields(), [&](const FieldDecl *Field) {
152+
return isLiteralType(Field->getType(), Ctx, ConservativeLiteralType);
153+
}))
154+
return false;
155+
144156
if (llvm::any_of(Rec->ctors(), [](const CXXConstructorDecl *Ctor) {
145157
return !Ctor->isCopyOrMoveConstructor() &&
146158
Ctor->isConstexprSpecified();
@@ -350,19 +362,7 @@ AST_MATCHER_P(VarDecl, satisfiesVariableProperties, bool,
350362
return Func && Func->isConstexpr();
351363
}();
352364

353-
if (Node.isStaticLocal() && IsDeclaredInsideConstexprFunction)
354-
return false;
355-
356-
if (!Ctx.getLangOpts().CPlusPlus20)
357-
return true;
358-
359-
const CXXRecordDecl *RDecl = T->getAsCXXRecordDecl();
360-
const Type *const ArrayOrPtrElement = T->getPointeeOrArrayElementType();
361-
if (ArrayOrPtrElement)
362-
RDecl = ArrayOrPtrElement->getAsCXXRecordDecl();
363-
364-
return !(RDecl &&
365-
(!RDecl->hasDefinition() || !RDecl->hasConstexprDestructor()));
365+
return !(Node.isStaticLocal() && IsDeclaredInsideConstexprFunction);
366366
}
367367
} // namespace
368368

0 commit comments

Comments
 (0)