Skip to content

Commit e90fb82

Browse files
committed
[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
1 parent 27d1910 commit e90fb82

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

clang/lib/Sema/SemaDecl.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12554,12 +12554,17 @@ void Sema::ActOnUninitializedDecl(Decl *RealDecl) {
1255412554
InitializationSequence InitSeq(*this, Entity, Kind, None);
1255512555
ExprResult Init = InitSeq.Perform(*this, Entity, Kind, None);
1255612556

12557-
// If default-init fails, leave var uninitialized but valid, for recovery.
12558-
1255912557
if (Init.get()) {
1256012558
Var->setInit(MaybeCreateExprWithCleanups(Init.get()));
1256112559
// This is important for template substitution.
1256212560
Var->setInitStyle(VarDecl::CallInit);
12561+
} else if (Init.isInvalid()) {
12562+
// If default-init fails, attach a recovery-expr initializer to track
12563+
// that initialization was attempted and failed.
12564+
auto RecoveryExpr =
12565+
CreateRecoveryExpr(Var->getLocation(), Var->getLocation(), {});
12566+
if (RecoveryExpr.get())
12567+
Var->setInit(RecoveryExpr.get());
1256312568
}
1256412569

1256512570
CheckCompleteVariableDeclaration(Var);

clang/lib/Sema/SemaDeclCXX.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15002,6 +15002,10 @@ ExprResult Sema::BuildCXXDefaultInitExpr(SourceLocation Loc, FieldDecl *Field) {
1500215002

1500315003
void Sema::FinalizeVarWithDestructor(VarDecl *VD, const RecordType *Record) {
1500415004
if (VD->isInvalidDecl()) return;
15005+
// If initializing the variable failed, don't also diagnose problems with
15006+
// the desctructor, they're likely related.
15007+
if (VD->getInit() && VD->getInit()->containsErrors())
15008+
return;
1500515009

1500615010
CXXRecordDecl *ClassDecl = cast<CXXRecordDecl>(Record->getDecl());
1500715011
if (ClassDecl->isInvalidDecl()) return;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// RUN: %clang_cc1 %s -fsyntax-only -frecovery-ast -verify -std=c++11
2+
3+
// NOTE: the test can be merged into existing tests once -frecovery-ast is on
4+
// by default.
5+
6+
struct Foo { // expected-note {{candidate constructor (the implicit copy constructor) not viable}}
7+
Foo(int); // expected-note {{candidate constructor not viable}}
8+
~Foo() = delete;
9+
};
10+
11+
void test() {
12+
// we expect the "attempt to use a deleted function" diagnostic is suppressed.
13+
Foo foo; // expected-error {{no matching constructor for initialization of}}
14+
}

0 commit comments

Comments
 (0)