Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
tahonermann opened this issue Jan 9, 2016 · 0 comments

Comments

@tahonermann
Copy link

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:

tahonermann added a commit to tahonermann/origin that referenced this issue Jan 18, 2016
Commit 2aa1056 changed Origin's
definition of the Destructible concept in terms of the validity
or a pseudo destructor expression rather than std::is_destructible.
That change resulted in reference and array of known bound types
failing to model the Destructible concept as required by C++14 via
the resolution of DR 2049 [1].  This regression is tracked at [2].
This change reverts the change made to the Destructible concept in
that commit.

[1]: http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2049
[2]: asutton#5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant