[PATCH] D78100: [AST] Suppress the spammy "attempt to use a deleted fucntion" diagnostic.
Haojian Wu via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Apr 21 01:03:21 PDT 2020
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe90fb82f0f76: [AST] Suppress the spammy "attempt to use a deleted fucntion" diagnostic. (authored by hokein).
Changed prior to commit:
https://reviews.llvm.org/D78100?vs=257689&id=258918#toc
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D78100/new/
https://reviews.llvm.org/D78100
Files:
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaDeclCXX.cpp
clang/test/SemaCXX/recovery-default-init.cpp
Index: clang/test/SemaCXX/recovery-default-init.cpp
===================================================================
--- /dev/null
+++ 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}}
+}
Index: clang/lib/Sema/SemaDeclCXX.cpp
===================================================================
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -15002,6 +15002,10 @@
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;
Index: clang/lib/Sema/SemaDecl.cpp
===================================================================
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -12554,12 +12554,17 @@
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);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D78100.258918.patch
Type: text/x-patch
Size: 2361 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200421/72c40c9b/attachment.bin>
More information about the cfe-commits
mailing list