davide created this revision.
davide added reviewers: nlewycky, rsmith.
davide added a subscriber: cfe-commits.
davide set the repository for this revision to rL LLVM.

This is an attempt to fix a FIXME from a previous commits, and now the testcase 
in PR24260 emits the following diagnostics:

std.cpp:8:5: error: call to implicitly-deleted default constructor of 'Y'
  Y y;
    ^
std.cpp:5:5: note: default constructor of 'Y' is implicitly deleted because 
field
      'x' has an inaccessible destructor
  X x;
    ^
std.cpp:2:3: note: destructor is declared here
  ~X();  // private
  ^
1 error generated.

I didn't put the name of the class in the note, because it seems pretty obvious 
from SourceLoc. I can change that, if needed.

Repository:
  rL LLVM

http://reviews.llvm.org/D11517

Files:
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/Sema/SemaDeclCXX.cpp
  test/CXX/special/class.copy/implicit-move.cpp
  test/CXX/special/class.copy/p11.0x.copy.cpp
  test/CXX/special/class.copy/p11.0x.move.cpp
  test/CXX/special/class.ctor/p5-0x.cpp
  test/CXX/special/class.dtor/p5-0x.cpp
  test/SemaCXX/defaulted-private-dtor.cpp

Index: test/SemaCXX/defaulted-private-dtor.cpp
===================================================================
--- test/SemaCXX/defaulted-private-dtor.cpp
+++ test/SemaCXX/defaulted-private-dtor.cpp
@@ -2,7 +2,7 @@
 
 class BadDtor {
   // A private, but nonetheless trivial, destructor.
-  ~BadDtor() = default; // expected-note 9{{here}}
+  ~BadDtor() = default; // expected-note 10{{here}}
   friend class K;
 };
 void f() {
Index: test/CXX/special/class.dtor/p5-0x.cpp
===================================================================
--- test/CXX/special/class.dtor/p5-0x.cpp
+++ test/CXX/special/class.dtor/p5-0x.cpp
@@ -7,7 +7,7 @@
   ~DeletedDtor() = delete; // expected-note 5 {{deleted here}}
 };
 class InaccessibleDtor {
-  ~InaccessibleDtor() = default;
+  ~InaccessibleDtor() = default; // expected-note 2 {{destructor is declared here}}
 };
 
 // A defaulted destructor for a class X is defined as deleted if:
Index: test/CXX/special/class.ctor/p5-0x.cpp
===================================================================
--- test/CXX/special/class.ctor/p5-0x.cpp
+++ test/CXX/special/class.ctor/p5-0x.cpp
@@ -5,7 +5,7 @@
 struct DeletedDefCtor { DeletedDefCtor() = delete; DeletedDefCtor(int); }; // expected-note {{explicitly marked deleted here}}
 class PrivateDefCtor { PrivateDefCtor() = default; public: PrivateDefCtor(int); };
 struct DeletedDtor { ~DeletedDtor() = delete; }; // expected-note 4{{explicitly marked deleted here}}
-class PrivateDtor { ~PrivateDtor() = default; };
+class PrivateDtor { ~PrivateDtor() = default; }; // expected-note 2{{destructor is declared here}}
 class Friend {
   Friend() = default; ~Friend() = default;
   friend struct NotDeleted6c;
Index: test/CXX/special/class.copy/p11.0x.move.cpp
===================================================================
--- test/CXX/special/class.copy/p11.0x.move.cpp
+++ test/CXX/special/class.copy/p11.0x.move.cpp
@@ -109,7 +109,7 @@
 struct NoAccessDtor {
   NoAccessDtor(NoAccessDtor&&); // expected-note{{copy constructor is implicitly deleted because 'NoAccessDtor' has a user-declared move constructor}}
 private:
-  ~NoAccessDtor();
+  ~NoAccessDtor(); // expected-note{{destructor is declared here}}
   friend struct HasAccessDtor;
 };
 
Index: test/CXX/special/class.copy/p11.0x.copy.cpp
===================================================================
--- test/CXX/special/class.copy/p11.0x.copy.cpp
+++ test/CXX/special/class.copy/p11.0x.copy.cpp
@@ -97,7 +97,7 @@
 //    a destructor that is deleted or inaccessible
 struct NoAccessDtor {
 private:
-  ~NoAccessDtor();
+  ~NoAccessDtor(); // expected-note {{destructor is declared here}}
   friend struct HasAccessDtor;
 };
 
Index: test/CXX/special/class.copy/implicit-move.cpp
===================================================================
--- test/CXX/special/class.copy/implicit-move.cpp
+++ test/CXX/special/class.copy/implicit-move.cpp
@@ -84,7 +84,7 @@
   PrivateDestructor(const PrivateDestructor &) noexcept(false);
   PrivateDestructor(PrivateDestructor &&) noexcept;
 private:
-  ~PrivateDestructor() noexcept;
+  ~PrivateDestructor() noexcept; // expected-note{{destructor is declared here}}
 };
 
 struct InheritsPrivateDestructor : PrivateDestructor {}; // expected-note{{base class 'PrivateDestructor' has an inaccessible destructor}}
Index: lib/Sema/SemaDeclCXX.cpp
===================================================================
--- lib/Sema/SemaDeclCXX.cpp
+++ lib/Sema/SemaDeclCXX.cpp
@@ -5570,7 +5570,16 @@
 
     if (DiagKind == 1)
       S.NoteDeletedFunction(Decl);
-    // FIXME: Explain inaccessibility if DiagKind == 3.
+    if (DiagKind == 3) {
+      // Explain the reasons of inaccessibility.
+      if (Field) {
+        if (CXXRecordDecl *C = Field->getType()->getAsCXXRecordDecl()) {
+          CXXDestructorDecl *D = S.LookupDestructor(C);
+          if (D && !D->isImplicit())
+            S.Diag(D->getLocStart(), diag::note_destructor_here);
+        }
+      }
+    }
   }
 
   return true;
Index: include/clang/Basic/DiagnosticSemaKinds.td
===================================================================
--- include/clang/Basic/DiagnosticSemaKinds.td
+++ include/clang/Basic/DiagnosticSemaKinds.td
@@ -1466,6 +1466,7 @@
   "type %1 of the object being destroyed">;
 def note_destructor_type_here : Note<
   "type %0 is declared here">;
+def note_destructor_here : Note<"destructor is declared here">;
 
 def err_destructor_template : Error<
   "destructor cannot be declared as a template">;
_______________________________________________
cfe-commits mailing list
cfe-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to