Opened 6 years ago
Closed 5 years ago
#12285 closed Bugs (fixed)
type_traits must assert type completeness for some traits
| Reported by: | Antony Polukhin | Owned by: | John Maddock |
|---|---|---|---|
| Milestone: | To Be Determined | Component: | type_traits |
| Version: | Boost 1.61.0 | Severity: | Problem |
| Keywords: | Cc: |
Description
Without that check hard detectable errors are possible:
#include <boost/type_traits.hpp>
struct foo;
void kill_sanity() {
(void)boost::is_constructible<foo, foo>::value;
}
struct foo{};
int main() {
static_assert(boost::is_constructible<foo, foo>::value, "foo must be constructible from foo"); // Ooops
}
All the is_*constructible, is_base_of, is_convertible, is_destructible, is_*swappable, has_virtual_destructor traits must assert completeness.
Solution could be to create an asserting structure (pseudocode):
template <class T>
struct assert_complete {
template <class U> yes_type test(mpl::int_<sizeof(U)>* = 0);
template <class U> no_type test(...);
static_assert(sizeof(test<T>(0)) == sizeof(yes_type), "T must be a complete type!");
};
Note:
See TracTickets
for help on using tickets.

Nod, there were a few traits which gave incorrect results when instantiated with an incomplete type, fixed in https://github.com/boostorg/type_traits/commit/ac351390b215b73d8a9e16d2ca37ba2d9d88a14f (plus a few subsequent commits for older compiler workarounds).