[PATCH] Fix PR19253: Do not emit global destructor warning for trivial explicitly defaulted destructors

David Blaikie dblaikie at gmail.com
Wed Mar 26 08:03:50 PDT 2014


On Wed, Mar 26, 2014 at 7:51 AM, Stephan Tolksdorf <st at quanttec.com> wrote:
> Hi rsmith,
>
> This patch fixes the logic for setting CXXRecordDecl::DefinitionData::HasIrrelevantDestructor.
>
> http://llvm-reviews.chandlerc.com/D3190
>
> Files:
>   lib/AST/DeclCXX.cpp
>   test/SemaCXX/warn-global-constructors.cpp
>
> Index: lib/AST/DeclCXX.cpp
> ===================================================================
> --- lib/AST/DeclCXX.cpp
> +++ lib/AST/DeclCXX.cpp
> @@ -527,8 +527,11 @@
>    if (CXXDestructorDecl *DD = dyn_cast<CXXDestructorDecl>(D)) {
>      SMKind |= SMF_Destructor;
>
> -    if (!DD->isImplicit())
> +    if (DD->isUserProvided())
>        data().HasIrrelevantDestructor = false;
> +    // If the destructor is explicitly defaulted and not trivial or not public
> +    // or if the destructor is explicitly deleted, we clear
> +    // HasIrrelevantDestructor in finishedDefaultedOrDeletedMember.
>
>      // C++11 [class.dtor]p5:
>      //   A destructor is trivial if [...] the destructor is not virtual.
> @@ -936,9 +939,11 @@
>      else if (Constructor->isConstexpr())
>        // We may now know that the constructor is constexpr.
>        data().HasConstexprNonCopyMoveConstructor = true;
> -  } else if (isa<CXXDestructorDecl>(D))
> +  } else if (isa<CXXDestructorDecl>(D)) {
>      SMKind |= SMF_Destructor;
> -  else if (D->isCopyAssignmentOperator())
> +    data().HasIrrelevantDestructor =
> +        D->isTrivial() && D->getAccess() == AS_public && !D->isDeleted();
> +  } else if (D->isCopyAssignmentOperator())
>      SMKind |= SMF_CopyAssignment;
>    else if (D->isMoveAssignmentOperator())
>      SMKind |= SMF_MoveAssignment;
> Index: test/SemaCXX/warn-global-constructors.cpp
> ===================================================================
> --- test/SemaCXX/warn-global-constructors.cpp
> +++ test/SemaCXX/warn-global-constructors.cpp
> @@ -96,6 +96,39 @@
>    }
>  }
>
> +namespace pr19253 {
> +  struct A {
> +    ~A() = default; // expected-warning{{C++11 extension}}

You could probably disable the C++11 extension warning for this test
file or switch the file to just build as C++11.

> +  };
> +
> +  struct B {
> +  private:
> +    friend struct C;
> +    ~B() = default; // expected-warning{{C++11 extension}}
> +  };
> +
> +  struct C : B {
> +    ~C() = default; // expected-warning{{C++11 extension}}
> +    B b;
> +  };
> +
> +  struct D {
> +    ~D();
> +  };
> +
> +  struct E {
> +    D d;
> +    ~E() = default; // expected-warning{{C++11 extension}}
> +  };
> +
> +  // These variables do not require global destructors.
> +  A a;
> +  C c;
> +
> +  D d; // expected-warning {{global destructor}}
> +  E e; // expected-warning {{global destructor}}
> +}
> +
>  namespace referencemember {
>    struct A { int &a; };
>    int a;
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>



More information about the cfe-commits mailing list