From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 38B6A385B836; Tue, 31 Mar 2020 02:34:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 38B6A385B836 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1585622052; bh=5rglBze3kLExS10oO1yfNpZVMZ6SI3vc0lZHVonoPpA=; h=From:To:Subject:Date:In-Reply-To:References:From; b=W90PwW9o47m6VSGqM+SCncJgB6lJmopd83Xiee2DQ9vyQNMRBWM375VRal2TDRorm uzIa1VfRGSelDXeU6ljJs6ViQbMnTYAG9aOHEvXtxnecSP7U1+JxgSaI77ZKK/lCkd KLeQ3vd/dYaJV15ZwGyCZt7BwK2EMOKcu/n0OxkY= From: "modchipv12 at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/89990] request warning: Use of out of scope compound literals Date: Tue, 31 Mar 2020 02:34:12 +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: 9.0 X-Bugzilla-Keywords: diagnostic X-Bugzilla-Severity: enhancement X-Bugzilla-Who: modchipv12 at gmail dot com 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: cc 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 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 31 Mar 2020 02:34:12 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D89990 Andrew D'Addesio changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |modchipv12 at gmail dot com --- Comment #5 from Andrew D'Addesio --- GCC already warns about this at compile time, but the warning sometimes doe= sn't appear (due to PR88058, as Andrew Pinski just mentioned). Plus, the warning= is a bit confusing and could be reworded. For example, create the following files: foo.c: int foo(const unsigned char *buf) { (void)buf; /* unused parameter */ return 1; } test.c: int foo(const unsigned char *buf); struct mytype { char c; }; static struct mytype d =3D { 42 }; int test(int x) { const unsigned char buf[32]; const struct mytype *ptr =3D &d; if (x !=3D 0) ptr =3D &(const struct mytype){ 43 }; foo(buf); #ifdef CALL_FOO_TWICE foo(buf); #endif return ptr->c; } int main() { return test(1); /* returns 43 on GCC8, 0 on GCC9+ */ } Compiling with one foo() call gives us a warning: $ gcc -std=3Dc99 -Wall -Wextra -pedantic -O1 -o test test.c foo.c test.c: In function =E2=80=98main=E2=80=99: test.c:26:15: warning: =E2=80=98.c=E2=80=99 is used uninitialize= d in this function [-Wuninitialized] 26 | return ptr->c; | ~~~^~~ $ ./test $ echo $? 0 However, compiling with two foo() calls makes the warning disappear, for so= me reason: $ gcc -DCALL_FOO_TWICE -std=3Dc99 -Wall -Wextra -pedantic -O1 -o test t= est.c foo.c $ ./test $ echo $? 0 My GCC version is 9.3.1 20200317 (Red Hat 9.3.1-1) on Fedora 31 x86-64.=