r204825 - -Wglobal-constructors: Don't warn on trivial defaulted dtors

Richard Smith richard at metafoo.co.uk
Wed Mar 26 15:10:28 PDT 2014


On Wed, Mar 26, 2014 at 9:36 AM, Stephan Tolksdorf <st at quanttec.com> wrote:

> Hi Reid,
>
> Did you overlook that I had assigned PR19253 to myself and posted a patch
> to this list (D3190)? :-)
>
> I think that fixing HasIrrelevantDestructor (as I did in my patch) would
> be a better solution for this issue.


I agree that we should fix HasIrrelevantDestructor. But... we shouldn't
warn on a trivial destructor no matter whether it's public or whether it
calls non-public destructors. hasIrrelevantDestructor is supposed to just
be an optimization, and shouldn't affect our semantics. => We want both
fixes :)

Another test case, should not warn (under either of the two 'global
destructor' warnings):

class A {
  friend struct B;
  ~A() = default;
};
struct B {
  ~B() = default;
} b;

Reid Kleckner wrote:
>
>> Author: rnk
>> Date: Wed Mar 26 10:58:20 2014
>> New Revision: 204825
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=204825&view=rev
>> Log:
>> -Wglobal-constructors: Don't warn on trivial defaulted dtors
>>
>> Fixes PR19253.
>>
>> Modified:
>>      cfe/trunk/lib/Sema/SemaDeclCXX.cpp
>>      cfe/trunk/test/SemaCXX/warn-global-constructors.cpp
>>
>> Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/
>> SemaDeclCXX.cpp?rev=204825&r1=204824&r2=204825&view=diff
>> ============================================================
>> ==================
>> --- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
>> +++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Wed Mar 26 10:58:20 2014
>> @@ -10470,7 +10470,7 @@ void Sema::FinalizeVarWithDestructor(Var
>>     Diag(VD->getLocation(), diag::warn_exit_time_destructor);
>>
>
This warning seems to have the same issue.


>     // TODO: this should be re-enabled for static locals by !CXAAtExit
>> -  if (!VD->isStaticLocal())
>> +  if (!Destructor->isTrivial() && !VD->isStaticLocal())
>>       Diag(VD->getLocation(), diag::warn_global_destructor);
>>   }
>>
>>
>> Modified: cfe/trunk/test/SemaCXX/warn-global-constructors.cpp
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/
>> SemaCXX/warn-global-constructors.cpp?rev=204825&
>> r1=204824&r2=204825&view=diff
>> ============================================================
>> ==================
>> --- cfe/trunk/test/SemaCXX/warn-global-constructors.cpp (original)
>> +++ cfe/trunk/test/SemaCXX/warn-global-constructors.cpp Wed Mar 26
>> 10:58:20 2014
>> @@ -1,4 +1,4 @@
>> -// RUN: %clang_cc1 -fsyntax-only -Wglobal-constructors %s -verify
>> +// RUN: %clang_cc1 -std=c++11 -fsyntax-only -Wglobal-constructors %s
>> -verify
>>
>>   int opaque_int();
>>
>> @@ -101,3 +101,11 @@ namespace referencemember {
>>     int a;
>>     A b = { a };
>>   }
>> +
>> +namespace pr19253 {
>> +  struct A { ~A() = default; };
>> +  A a;
>> +  struct B { ~B() {} };
>> +  struct C : B { ~C() = default; };
>> +  C c; // expected-warning {{global destructor}}
>> +}
>>
>>
>> _______________________________________________
>> cfe-commits mailing list
>> cfe-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>>
>>  _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140326/eaa483e4/attachment.html>


More information about the cfe-commits mailing list