|
9 | 9 | #include "UseConstexprCheck.h" |
10 | 10 | #include "../utils/ASTUtils.h" |
11 | 11 | #include "../utils/LexerUtils.h" |
| 12 | +#include "clang/AST/Decl.h" |
12 | 13 | #include "clang/AST/RecursiveASTVisitor.h" |
13 | 14 | #include "clang/ASTMatchers/ASTMatchers.h" |
14 | 15 | #include "llvm/ADT/STLExtras.h" |
@@ -141,6 +142,17 @@ static bool isLiteralType(const Type *T, const ASTContext &Ctx, |
141 | 142 | return true; |
142 | 143 |
|
143 | 144 | 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 | + |
144 | 156 | if (llvm::any_of(Rec->ctors(), [](const CXXConstructorDecl *Ctor) { |
145 | 157 | return !Ctor->isCopyOrMoveConstructor() && |
146 | 158 | Ctor->isConstexprSpecified(); |
@@ -350,19 +362,7 @@ AST_MATCHER_P(VarDecl, satisfiesVariableProperties, bool, |
350 | 362 | return Func && Func->isConstexpr(); |
351 | 363 | }(); |
352 | 364 |
|
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); |
366 | 366 | } |
367 | 367 | } // namespace |
368 | 368 |
|
|
0 commit comments