diff options
| author | Richard Smith <richard-llvm@metafoo.co.uk> | 2019-09-29 05:08:46 +0000 |
|---|---|---|
| committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2019-09-29 05:08:46 +0000 |
| commit | 2b4fa5348ee157b6b1a1af44d0137ca8c7a71573 (patch) | |
| tree | b3ac8e6a34f562040ad1ac1e7876eceac4f40a52 /clang/lib/Sema | |
| parent | ac5969933ab7e43d26209ae6c15669842bc86104 (diff) | |
| download | bcm5719-llvm-2b4fa5348ee157b6b1a1af44d0137ca8c7a71573.tar.gz bcm5719-llvm-2b4fa5348ee157b6b1a1af44d0137ca8c7a71573.zip | |
For P0784R7: compute whether a variable has constant destruction if it
has a constexpr destructor.
For constexpr variables, reject if the variable does not have constant
destruction. In all cases, do not emit runtime calls to the destructor
for variables with constant destruction.
llvm-svn: 373159
Diffstat (limited to 'clang/lib/Sema')
| -rw-r--r-- | clang/lib/Sema/SemaDeclCXX.cpp | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp index c03e4dc66f8..d21d2689123 100644 --- a/clang/lib/Sema/SemaDeclCXX.cpp +++ b/clang/lib/Sema/SemaDeclCXX.cpp @@ -13398,6 +13398,19 @@ void Sema::FinalizeVarWithDestructor(VarDecl *VD, const RecordType *Record) { } if (Destructor->isTrivial()) return; + + // If the destructor is constexpr, check whether the variable has constant + // destruction now. + if (Destructor->isConstexpr() && VD->evaluateValue()) { + SmallVector<PartialDiagnosticAt, 8> Notes; + if (!VD->evaluateDestruction(Notes) && VD->isConstexpr()) { + Diag(VD->getLocation(), + diag::err_constexpr_var_requires_const_destruction) << VD; + for (unsigned I = 0, N = Notes.size(); I != N; ++I) + Diag(Notes[I].first, Notes[I].second); + } + } + if (!VD->hasGlobalStorage()) return; // Emit warning for non-trivial dtor in global scope (a real global, |

