This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: c++/3167: Copyconstructor not called when entering function (var args)
- To: <philipp dot bachmann at obtree dot com>
- Subject: Re: c++/3167: Copyconstructor not called when entering function (var args)
- From: "Artem Khodush" <artem at duma dot gov dot ru>
- Date: Wed, 13 Jun 2001 20:02:55 +0400
- >Received: from artem by mailsrv.duma.gov.ru (SMI-8.6/SMI-SVR4)id UAA11864; Wed, 13 Jun 2001 20:05:57 +0400
- Cc: <gcc-gnats at gcc dot gnu dot org>, <gcc-bugs at gcc dot gnu dot org>
- References: <20010613142131.4125.qmail@sourceware.cygnus.com>
>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.