It would seem that what you expect is the behavior defined by the standard.
Template functions do not prevent the creation of copy constructors/assignment operators. So template functions don't prevent a class from being considered "trivially copyable". However, they do participate in overload resolution when it comes time to actually copy them, so they can interfere. And since a
in this example is a non-const l-value, it better fits the signature A(A&)
than it does A(const A&)
. So it calls the template function.
(Though why you didn't bother to explain all of this in your question eludes me, since you obviously did your research.)
However, considering how small of a corner-case this is, I wouldn't go around relying on this behavior to force trivially copyable classes into not being trivially copied.
...
intended to be the varargs syntax or simply a placeholder for "stuff"? – HeterocliteA a = new A();
? Otherwisea
would benull
, not an instance... – FowlA* a = new A
) or automatic (A a
). C++ is more powerful in this regard, and you're having an uneducated reaction to it. – Gressorial[...] The lvalue-to-rvalue (4.1), [...] standard conversions are performed on the argument expression.
, 4.1/2:[...] Otherwise, if the glvalue has a class type, the conversion copy-initializes a temporary of type T from the glvalue [...]
. – Braasch