https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116417

            Bug ID: 116417
           Summary: SFINAE on std::is_destructible cannot handle
                    destructor of scalar type
           Product: gcc
           Version: 14.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: amy at amyspark dot me
  Target Milestone: ---

Hi all,

I have the following test case that compiles in Clang 20.0.0 commit
7d5281a66d5d42c65cfb9d95eaf9aa01afb089fb :

```c++
#include <type_traits>

namespace _impl {
        template<typename _Ty, typename =
decltype(std::declval<_Ty&>().~_Ty())>
        constexpr auto _try_is_destructible(int) -> std::true_type;
        template<typename>
        constexpr auto _try_is_destructible(...) -> std::false_type;
}

template<typename _Ty>
struct is_destructible : std::conditional_t<
        !std::is_void_v<_Ty> && !std::is_unbounded_array_v<_Ty> &&
!std::is_function_v<_Ty>,
        std::conditional_t<
                std::is_reference_v<_Ty>,
                std::true_type,
                decltype(
                       
_impl::_try_is_destructible<std::remove_all_extents_t<_Ty>>(0)
                )
        >,
        std::false_type
> {};

template<typename _Ty>
inline constexpr bool is_destructible_v = is_destructible<_Ty>::value;

static_assert(is_destructible_v<int&>);


int main(int, char**) {
        return 0;
}
```

GCC 14.1 refuses to build with the following error:

```
<source>: In substitution of 'template<class _Ty, class> constexpr
std::true_type _impl::_try_is_destructible(int) [with _Ty = int&;
<template-parameter-1-2> = <missing>]':
<source>:17:63:   required from 'struct is_destructible<int&>'
   17 |                        
_impl::_try_is_destructible<std::remove_all_extents_t<_Ty>>(0)
      |                        
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
<source>:24:65:   required from 'constexpr const bool is_destructible_v<int&>'
   24 | inline constexpr bool is_destructible_v = is_destructible<_Ty>::value;
      |                                                                 ^~~~~
<source>:26:15:   required from here
   26 | static_assert(is_destructible_v<int&>);
      |               ^~~~~~~~~~~~~~~~~~~~~~~
<source>:4:74: error: 'std::declval<int&>()' is not of type 'int&'
    4 |         template<typename _Ty, typename =
decltype(std::declval<_Ty&>().~_Ty())>
      |                                                   
~~~~~~~~~~~~~~~~~~~~~~^~~
ASM generation compiler returned: 1
<source>: In substitution of 'template<class _Ty, class> constexpr
std::true_type _impl::_try_is_destructible(int) [with _Ty = int&;
<template-parameter-1-2> = <missing>]':
<source>:17:63:   required from 'struct is_destructible<int&>'
   17 |                        
_impl::_try_is_destructible<std::remove_all_extents_t<_Ty>>(0)
      |                        
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
<source>:24:65:   required from 'constexpr const bool is_destructible_v<int&>'
   24 | inline constexpr bool is_destructible_v = is_destructible<_Ty>::value;
      |                                                                 ^~~~~
<source>:26:15:   required from here
   26 | static_assert(is_destructible_v<int&>);
      |               ^~~~~~~~~~~~~~~~~~~~~~~
<source>:4:74: error: 'std::declval<int&>()' is not of type 'int&'
    4 |         template<typename _Ty, typename =
decltype(std::declval<_Ty&>().~_Ty())>
      |                                                   
~~~~~~~~~~~~~~~~~~~~~~^~~
Execution build compiler returned: 1
```

Looks like it's been found and worked around before, but no report has been
filed: https://stackoverflow.com/a/53458189

Godbolt here: https://godbolt.org/z/Edes1sjzo

Reply via email to