From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id E969B3858D3C; Sat, 21 Jan 2023 12:17:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E969B3858D3C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1674303463; bh=iVPDmGxJ0iYxMEbeJTrDLBIeYWdnfqGfWK3B9XxhsyA=; h=From:To:Subject:Date:In-Reply-To:References:From; b=u8qrBhVKtUHCiJF/dAR0LQAjzkPzRGogebv/FHIW7L70S2xGZIkz14qgCZI5SdmD4 C5LkM7Rndk1HwKWzG2PIuHSzc+V7PCTUFK8tQuSNVT2m9fUfFYz75paC9Emh0TUa52 1I59y0u0B5BlVnTfpQ5t8+UysoeXJUfhl/VZXlK4= From: "jakub at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/108483] gcc warns about suspicious constructs for unevaluted ?: operand Date: Sat, 21 Jan 2023 12:17:43 +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: 10.2.1 X-Bugzilla-Keywords: diagnostic X-Bugzilla-Severity: enhancement X-Bugzilla-Who: jakub at gcc dot gnu.org X-Bugzilla-Status: NEW 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=3D108483 --- Comment #7 from Jakub Jelinek --- If it needs to be used in constant expression and you want warnings for the non-void * cases with pointers, not arrays and errors for use of void * pointers except for NULL, then maybe: typedef __SIZE_TYPE__ size_t; typedef __UINTPTR_TYPE__ uintptr_t; #define NULL ((void *) 0) #define ARRAY_SIZE_MAYBENULL(x) _Generic((x), void*: (size_t) (uintptr_t) ((char (*) [__builtin_constant_p (x) && (x) =3D=3D 0 ? 1 : _Generic((x), vo= id*: -1, default: 1)]) 0), default: \ sizeof(x)/sizeof(_Generic((x), void*: (x), default:*(x)))) int a[10]; int *q; void *r; int p[] =3D { ARRAY_SIZE_MAYBENULL (a), ARRAY_SIZE_MAYBENULL (NULL), ARRAY_SIZE_MAYBENULL ((const void *) 0), ARRAY_SIZE_MAYBENULL ((volatile void *) 0), ARRAY_SIZE_MAYBENULL ((void *restrict) 0), ARRAY_SIZE_MAYBENULL ((const volatile void *) 0), ARRAY_SIZE_MAYBENULL (q), ARRAY_SIZE_MAYBENULL (r), ARRAY_SIZE_MAYBENULL ((void *) (uintptr_t) 0x1234abc) }; This warns -Wsizeof-pointer-div on the const void *, volatile void *, const volatile void * and q cases and errors on the last 2. clang seems to also emit those 4 -Wsizeof-pointer-div warnings, but doesn't emit any errors nor warnings on the last 2.=