From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id E0B1F387723D; Tue, 6 Dec 2022 14:04:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E0B1F387723D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1670335448; bh=ByY8xoywVkgFne+Bshkpr4D4bzKCItxD8z/dMzgJVDw=; h=From:To:Subject:Date:In-Reply-To:References:From; b=equOEIQi6MhpcX/cxIjrQkXMJmTEDSfV1KfJZIu0O2kkvi8l4gHJ4wKlDWPIqC384 UhdGVL0M/9PjYlOdr+8Uvq9ARTdW3b4vCoOjQLYy8MMJ2Swew4vp2LF4RVnyyBatRl Hb29VJGq9CuSYmqunAMY0kOuMSF3cNBkaU9KIgZ0= From: "aaron at aaronballman dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/107980] va_start does not warn about an arbitrary number of arguments in C2x mode Date: Tue, 06 Dec 2022 14:04:08 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Version: 13.0 X-Bugzilla-Keywords: diagnostic X-Bugzilla-Severity: normal X-Bugzilla-Who: aaron at aaronballman dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D107980 --- Comment #8 from Aaron Ballman --- (Sorry, I meant __VA_ARGS__ and not __VA_OPT__; C23 on the brain!) (In reply to Andrew Pinski from comment #6) > Maybe add a _Static_warn builtin instead which is like _Static_assert but > instead of an error, it is a warning. >=20 > That is: > #define va_start(ap, ...) (_Static_warn(__builtin_va_opt_count(__VA_OPT__) > <=3D 1, "More than one argument supplied to the macro va_start"), > __builtin_va_start(ap, 0)) >=20 >=20 > THe only issue is that message does not get translated. Huh, that's a really neat idea to consider! But _Static_assert is a declaration, not an expression, so we'd have to use a statement expression there instead of rely on the comma operator. But I could use that for both diagnosing passing > 2 args as well as passing < 2 args (we sometimes like = to warn "this feature is incompatible with standards before " in Clang). (In reply to Jakub Jelinek from comment #7) > Why do you need a builtin for counting number of arguments in __VA_OPT__? > That can be done in the preprocessor. All one needs is 1, 2 or more > arguments. Yes, you can beat the preprocessor into doing this for you, but a builtin t= hat counts the number of arguments in __VA_ARGS__ would solve a problem users h= ave (https://stackoverflow.com/questions/2124339/c-preprocessor-va-args-number-= of-arguments), so I figured it was better than preprocessor games.=