[PATCH] D37235: Let -Wdelete-non-virtual-dtor fire in system headers too.
Nico Weber via cfe-commits
cfe-commits at lists.llvm.org
Mon Aug 28 15:12:29 PDT 2017
I had compiled a bunch of code with this, but right after I sent this out
my local build of something failed with this:
../../buildtools/third_party/libc++/trunk/include/type_traits:2156:51:
error: destructor called on non-final
'Ice::VariableDeclaration::RelocInitializer' that has virtual functions but
non-virtual destructor [-Werror,-Wdelete-non-virtual-dtor]
typename
__is_destructible_apply<decltype(_VSTD::declval<_Tp1&>().~_Tp1())>::type
^
../../buildtools/third_party/libc++/trunk/include/__config:435:15: note:
expanded from macro '_VSTD'
#define _VSTD std::_LIBCPP_NAMESPACE
^
../../buildtools/third_party/libc++/trunk/include/type_traits:2156:76:
note: qualify call to silence this warning
typename
__is_destructible_apply<decltype(_VSTD::declval<_Tp1&>().~_Tp1())>::type
^
So I'll have to tweak the warning to not fire in unevaluated contexts
first. Feel free to ignore for now.
On Mon, Aug 28, 2017 at 6:08 PM, Nico Weber via Phabricator via cfe-commits
<cfe-commits at lists.llvm.org> wrote:
> thakis created this revision.
>
> Makes the warning useful again in a std::unique_ptr world, PR28460.
>
>
> https://reviews.llvm.org/D37235
>
> Files:
> include/clang/Basic/DiagnosticSemaKinds.td
> test/SemaCXX/destructor.cpp
>
>
> Index: test/SemaCXX/destructor.cpp
> ===================================================================
> --- test/SemaCXX/destructor.cpp
> +++ test/SemaCXX/destructor.cpp
> @@ -1,5 +1,31 @@
> // RUN: %clang_cc1 -std=c++11 -triple %itanium_abi_triple -fsyntax-only
> -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -fcxx-exceptions -verify %s
> // RUN: %clang_cc1 -std=c++11 -triple %ms_abi_triple -DMSABI
> -fsyntax-only -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -verify %s
> +
> +#if defined(BE_THE_HEADER)
> +
> +// Wdelete-non-virtual-dtor should warn about the delete from smart
> pointer
> +// classes in system headers (std::unique_ptr...) too.
> +
> +#pragma clang system_header
> +namespace dnvd {
> +template <typename T>
> +class simple_ptr {
> +public:
> + simple_ptr(T* t): _ptr(t) {}
> + ~simple_ptr() { delete _ptr; } // \
> + // expected-warning {{delete called on non-final 'dnvd::B' that has
> virtual functions but non-virtual destructor}} \
> + // expected-warning {{delete called on non-final 'dnvd::D' that has
> virtual functions but non-virtual destructor}}
> + T& operator*() const { return *_ptr; }
> +private:
> + T* _ptr;
> +};
> +}
> +
> +#else
> +
> +#define BE_THE_HEADER
> +#include __FILE__
> +
> class A {
> public:
> ~A();
> @@ -213,18 +239,6 @@
> struct VF final: VB {};
>
> template <typename T>
> -class simple_ptr {
> -public:
> - simple_ptr(T* t): _ptr(t) {}
> - ~simple_ptr() { delete _ptr; } // \
> - // expected-warning {{delete called on non-final 'dnvd::B' that has
> virtual functions but non-virtual destructor}} \
> - // expected-warning {{delete called on non-final 'dnvd::D' that has
> virtual functions but non-virtual destructor}}
> - T& operator*() const { return *_ptr; }
> -private:
> - T* _ptr;
> -};
> -
> -template <typename T>
> class simple_ptr2 {
> public:
> simple_ptr2(T* t): _ptr(t) {}
> @@ -451,3 +465,4 @@
> x.foo1();
> }
> }
> +#endif // BE_THE_HEADER
> Index: include/clang/Basic/DiagnosticSemaKinds.td
> ===================================================================
> --- include/clang/Basic/DiagnosticSemaKinds.td
> +++ include/clang/Basic/DiagnosticSemaKinds.td
> @@ -6414,12 +6414,12 @@
> def warn_delete_non_virtual_dtor : Warning<
> "%select{delete|destructor}0 called on non-final %1 that has "
> "virtual functions but non-virtual destructor">,
> - InGroup<DeleteNonVirtualDtor>, DefaultIgnore;
> + InGroup<DeleteNonVirtualDtor>, DefaultIgnore, ShowInSystemHeader;
> def note_delete_non_virtual : Note<
> "qualify call to silence this warning">;
> def warn_delete_abstract_non_virtual_dtor : Warning<
> "%select{delete|destructor}0 called on %1 that is abstract but has "
> - "non-virtual destructor">, InGroup<DeleteNonVirtualDtor>;
> + "non-virtual destructor">, InGroup<DeleteNonVirtualDtor>,
> ShowInSystemHeader;
> def warn_overloaded_virtual : Warning<
> "%q0 hides overloaded virtual %select{function|functions}1">,
> InGroup<OverloadedVirtual>, DefaultIgnore;
>
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170828/dab8dc13/attachment-0001.html>
More information about the cfe-commits
mailing list