I have the following code:
#include <iostream> class A; int main() { std::cout << std::is_constructible<A>::value << std::endl; }
When I use GCC 8.3, this code compiles. However, when I use Clang 8.0, I get a compilation error that incomplete types cannot be used in type traits.
Which one is correct? Am I allowed to use is_constructible
on an incomplete type (with an expected value of false
), or am I not allowed to?
An incomplete type can be: 1 A structure type whose members you have not yet specified. 2 A union type whose members you have not yet specified. 3 An array type whose dimension you have not yet specified. More ...
For this class, a constructible type is a type that can be constructed using a particular set of arguments. is_constructible inherits from integral_constant as being either true_type or false_type, depending on whether T is constructible with the list of arguments Args. A complete type, or void (possible cv-qualified), or an array of unknown bound.
Args> struct is_constructible; For this class, a constructible type is a type that can be constructed using a particular set of arguments. is_constructible inherits from integral_constant as being either true_type or false_type, depending on whether T is constructible with the list of arguments Args.
To create an incomplete array type, declare an array type without specifying its repetition count. For example: To complete an incomplete array type, declare the same name later in the same scope with its repetition count specified, as in
The behavior is undefined.
[meta.unary.prop]
template <class T, class... Args> struct is_constructible;
T
and all types in the parameter packArgs
shall be complete types, (possibly cv-qualified) void, or arrays of unknown bound.
That's a precondition of the meta-function. A contract that your code violates. libc++ is being generous by notifying you.
Mind you, that putting that precondition there and leaving it undefined otherwise is for a reason. A program where two points of instantiation of a template have different meanings is ill-formed NDR. The only sane course of action is demand complete types. And after all, that's when the trait is most useful anyway.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With