[clang] e90fb82 - [AST] Suppress the spammy "attempt to use a deleted fucntion" diagnostic.
Haojian Wu via cfe-commits
cfe-commits at lists.llvm.org
Tue Apr 21 00:44:08 PDT 2020
Author: Haojian Wu
Date: 2020-04-21T09:43:46+02:00
New Revision: e90fb82f0f760703c14eafbad96c08b6019a2f0f
URL: https://github.com/llvm/llvm-project/commit/e90fb82f0f760703c14eafbad96c08b6019a2f0f
DIFF: https://github.com/llvm/llvm-project/commit/e90fb82f0f760703c14eafbad96c08b6019a2f0f.diff
LOG: [AST] Suppress the spammy "attempt to use a deleted fucntion" diagnostic.
Summary:
This patch fixes the regression diagnostic, which was introduced in
https://reviews.llvm.org/D77395.
Reviewers: sammccall
Reviewed By: sammccall
Subscribers: rsmith, adamcz, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D78100
Added:
clang/test/SemaCXX/recovery-default-init.cpp
Modified:
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaDeclCXX.cpp
Removed:
################################################################################
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 27c8365ab8be..6241162fd992 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -12554,12 +12554,17 @@ void Sema::ActOnUninitializedDecl(Decl *RealDecl) {
InitializationSequence InitSeq(*this, Entity, Kind, None);
ExprResult Init = InitSeq.Perform(*this, Entity, Kind, None);
- // If default-init fails, leave var uninitialized but valid, for recovery.
-
if (Init.get()) {
Var->setInit(MaybeCreateExprWithCleanups(Init.get()));
// This is important for template substitution.
Var->setInitStyle(VarDecl::CallInit);
+ } else if (Init.isInvalid()) {
+ // If default-init fails, attach a recovery-expr initializer to track
+ // that initialization was attempted and failed.
+ auto RecoveryExpr =
+ CreateRecoveryExpr(Var->getLocation(), Var->getLocation(), {});
+ if (RecoveryExpr.get())
+ Var->setInit(RecoveryExpr.get());
}
CheckCompleteVariableDeclaration(Var);
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 8f04f5ae5dea..bf0c84447b5f 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -15002,6 +15002,10 @@ ExprResult Sema::BuildCXXDefaultInitExpr(SourceLocation Loc, FieldDecl *Field) {
void Sema::FinalizeVarWithDestructor(VarDecl *VD, const RecordType *Record) {
if (VD->isInvalidDecl()) return;
+ // If initializing the variable failed, don't also diagnose problems with
+ // the desctructor, they're likely related.
+ if (VD->getInit() && VD->getInit()->containsErrors())
+ return;
CXXRecordDecl *ClassDecl = cast<CXXRecordDecl>(Record->getDecl());
if (ClassDecl->isInvalidDecl()) return;
diff --git a/clang/test/SemaCXX/recovery-default-init.cpp b/clang/test/SemaCXX/recovery-default-init.cpp
new file mode 100644
index 000000000000..8ba3d8df58a3
--- /dev/null
+++ b/clang/test/SemaCXX/recovery-default-init.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 %s -fsyntax-only -frecovery-ast -verify -std=c++11
+
+// NOTE: the test can be merged into existing tests once -frecovery-ast is on
+// by default.
+
+struct Foo { // expected-note {{candidate constructor (the implicit copy constructor) not viable}}
+ Foo(int); // expected-note {{candidate constructor not viable}}
+ ~Foo() = delete;
+};
+
+void test() {
+ // we expect the "attempt to use a deleted function" diagnostic is suppressed.
+ Foo foo; // expected-error {{no matching constructor for initialization of}}
+}
More information about the cfe-commits
mailing list