Hello,
A question popped up on SO today 1: the OP was quite surprised that he could write:
struct X {};
struct Y {
Y() = default;
X& x;
};
And not have any compiler complain about the above code.
Of course, as has been answered, only the instantiation of Y (and thus use of the default constructor) should actually cause an issue; and there is even a clause that the = default
can be turned automatically (semantically wise) in a = delete
in some cases (such as this one).
Still, even though this is probably very useful for template classes, it is surprising to say the least; and generally being warned earlier is better. Therefore I was wondering if there is a warning in Clang when an explicitly defaulted special member is deleted by the compiler.
I could not find it, if there is (but then there are many warnings to sift through so I might have missed it). Does anyone knows about it ?
– Matthieu
Hello,
A question popped up on SO today [1]: the OP was quite surprised that he could write:
struct X {};
struct Y {
Y() = default;
X& x;
};
And not have any compiler complain about the above code.
Of course, as has been answered, only the instantiation of Y (and thus use of the default constructor) should actually cause an issue; and there is even a clause that the = default
can be turned automatically (semantically wise) in a = delete
in some cases (such as this one).
Still, even though this is probably very useful for template classes, it is surprising to say the least; and generally being warned earlier is better. Therefore I was wondering if there is a warning in Clang when an explicitly defaulted special member is deleted by the compiler.
I could not find it, if there is (but then there are many warnings to sift through so I might have missed it). Does anyone knows about it ?
Off the cuff I don’t think there is one & it seems like it might be helpful.