Skip to content

The Destructible concept fails for reference and array of known bound types #5

@tahonermann

Description

@tahonermann

Prior to commit 2aa1056, the Destructible concept was defined in terms of std::is_destructible. Following that commit, it is defined using a requires expression that uses an explicit destructor call and requires that a pointer to the type can be constructed.

The current Destructible concept fails for some types that are destructible according to the libstdc++ std::is_destructible implementation; specifically for reference types and arrays of known bound. The following example demonstrates this:

$ cat destructible.cpp

#include <type_traits>

template<typename T>
concept bool 
Destructible() 
{ 
#if USE_IS_DESTRUCTIBLE
  return std::is_destructible<T>::value;
#else
  return requires (T* t) { t->~T(); };
#endif
}

template<Destructible T>
void f();

void bar() {
    f<char[5]>(); // constraints not satisfied; ok with is_destructible
    f<int&>();    // constraints not satisfied; ok with is_destructible
}

$ g++ -c -std=c++1z -DUSE_IS_DESTRUCTIBLE destructible.cpp

<no errors>

$ g++ -c -std=c++1z destructible.cpp

destructible.cpp: In function ‘void bar()’:
destructible.cpp:18:16: error: cannot call function ‘void f() [with T = char [5]]’
     f<char[5]>(); // constraints not satisfied; ok with is_destructible
                ^

destructible.cpp:15:6: note:   constraints not satisfied
 void f();
      ^

destructible.cpp:15:6: note:   concept ‘Destructible<char [5]>()’ was not satisfied
destructible.cpp:19:13: error: cannot call function ‘void f() [with T = int&]’
     f<int&>();    // constraints not satisfied; ok with is_destructible
             ^

destructible.cpp:15:6: note:   constraints not satisfied
 void f();
      ^

destructible.cpp:15:6: note:   concept ‘Destructible<int&>()’ was not satisfied

I don't know what motivated the change to the Destructible concept definition. Unless there is good reason to avoid std::is_destructible, I recommend reverting the change to the concept definition.

Relevant C++ DRs:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions