From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22994 invoked by alias); 30 Sep 2011 19:41:37 -0000 Received: (qmail 22975 invoked by uid 22791); 30 Sep 2011 19:41:35 -0000 X-SWARE-Spam-Status: No, hits=-2.9 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 30 Sep 2011 19:41:22 +0000 From: "joseph at codesourcery dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/50581] stdarg doesn't support array types Date: Fri, 30 Sep 2011 20:13:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: joseph at codesourcery dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2011-09/txt/msg02423.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50581 --- Comment #1 from joseph at codesourcery dot com 2011-09-30 19:41:17 UTC --- There is no possible valid use of passing arrays to va_arg. In C99, it is never possible for an array to be passed by value to a function because it will have decayed to a pointer before the call. Thus, any execution of va_arg with such an argument type results in undefined behavior, just like calling it with "char" or "float", and generating a runtime abort (with a compile-time warning) might be appropriate, as is done for "char" and "float". In C90, it is technically possible to use va_arg in this case without undefined behavior. The argument passed to the function would have to be a non-lvalue array - for example, an array in a structure returned from another function. The result of va_arg would itself be a non-lvalue array, which it is not possible to convert to a pointer, so it is not possible to access the values in the array in any way; all that can be done is to discard the value (call va_arg for its side effects) or to pass it to another variadic function. As far as I know this obscure C90-only use case works correctly (so you can access arguments after the non-lvalue array using va_arg again, for example). If you have problems with it, please provide a bug report with a valid C90 testcase. E.g., #include typedef char array[1]; struct s { array a; }; struct s f (void); void g (int a, ...); void h (void) { g (0, f().a); } void g (int a, ...) { va_list ap; va_start (ap, a); va_arg (ap, array); va_end (ap); }