Skip to content

Commit

Permalink
[AST] Suppress the spammy "attempt to use a deleted fucntion" diagnos…
Browse files Browse the repository at this point in the history
…tic.

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
  • Loading branch information
hokein committed Apr 21, 2020
1 parent 27d1910 commit e90fb82
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
9 changes: 7 additions & 2 deletions clang/lib/Sema/SemaDecl.cpp
Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions clang/lib/Sema/SemaDeclCXX.cpp
Expand Up @@ -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;
Expand Down
14 changes: 14 additions & 0 deletions 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}}
}

0 comments on commit e90fb82

Please sign in to comment.