From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Artem Khodush" To: nobody@gcc.gnu.org Cc: gcc-prs@gcc.gnu.org Subject: Re: c++/3167: Copyconstructor not called when entering function (var args) Date: Wed, 13 Jun 2001 09:16:00 -0000 Message-id: <20010613161601.7305.qmail@sourceware.cygnus.com> X-SW-Source: 2001-06/msg00566.html List-Id: The following reply was made to PR c++/3167; it has been noted by GNATS. From: "Artem Khodush" To: Cc: , Subject: Re: c++/3167: Copyconstructor not called when entering function (var args) Date: Wed, 13 Jun 2001 20:02:55 +0400 >Subject: c++/3167: Copyconstructor not called when entering function (var args) This is not a bug. [Quote from the C++ standard begins] 5.2.2 - Function call [expr.call] -6- A function can be declared to accept fewer arguments (by declaring default arguments (dcl.fct.default)) or more arguments (by using the ellipsis, ... dcl.fct) than the number of parameters in the function definition (dcl.fct.def). [Note: this implies that, except where the ellipsis (...) is used, a parameter is available for each argument. ] -7- When there is no parameter for a given argument, the argument is passed in such a way that the receiving function can obtain the value of the argument by invoking va_arg (lib.support.runtime). The lvalue-to-rvalue (conv.lval), array-to-pointer (conv.array), and function-to-pointer (conv.func) standard conversions are performed on the argument expression. After these conversions, if the argument does not have arithmetic, enumeration, pointer, pointer to member, or class type, the program is ill-formed. If the argument has a non-POD class type (clause class), the behavior is undefined. [Quote from the C++ standard ends] You've observed two kinds of undefined behaviour: with gcc, neither constructor nor destructor is called, with sun cc, only the constructor is called. The desired 'correct' behaviour can not be implemented in general case, because va_arg and constructors do not mix.