https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105849
--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> --- (In reply to David Binderman from comment #0) > Standard practice is to have virtual destructor in the presence of virtual > functions. Or a protected destructor, or to make the class final. int_range cannot be final, but it looks as though value_range_equiv can be. But I think the warning for int_range<1> is a false positive anyway. The warning comes from instantiating finalizer<int_range<1>> in ggc_alloc, but it's not actually used, because that class has a trivial destructor. So this should work: diff --git a/gcc/ggc.h b/gcc/ggc.h index aeec1bafb9b..af0a4c005d7 100644 --- a/gcc/ggc.h +++ b/gcc/ggc.h @@ -160,14 +160,7 @@ extern void dump_ggc_loc_statistics (); ((T *) ggc_realloc ((P), (N) * sizeof (T) MEM_STAT_INFO)) template<typename T> -void -finalize (void *p) -{ - static_cast<T *> (p)->~T (); -} - -template<typename T> -inline bool +constexpr bool need_finalization_p () { #if GCC_VERSION >= 4003 @@ -177,6 +170,19 @@ need_finalization_p () #endif } +template<typename T> +typename std::enable_if<need_finalization_p<T> ()>::type +finalize (void *p) +{ + static_cast<T *> (p)->~T (); +} + +template<typename T> +typename std::enable_if<!need_finalization_p<T> ()>::type +finalize (void *) +{ +} + template<typename T> inline T * ggc_alloc (ALONE_CXX_MEM_STAT_INFO) diff --git a/gcc/value-range-equiv.h b/gcc/value-range-equiv.h index 0a52d1372a1..95a129124b2 100644 --- a/gcc/value-range-equiv.h +++ b/gcc/value-range-equiv.h @@ -24,7 +24,7 @@ along with GCC; see the file COPYING3. If not see /* Note value_range_equiv cannot currently be used with GC memory, only value_range is fully set up for this. */ -class GTY((user)) value_range_equiv : public value_range +class GTY((user)) value_range_equiv final : public value_range { public: value_range_equiv () : value_range () { m_equiv = NULL; } (It would be better to use "if constexpr" in ggc_alloc, but that's a C++17 feature, so overloading with std::enable_if is needed for C++11.)