From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 18AEC396E850; Thu, 23 Jul 2020 07:56:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 18AEC396E850 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1595490969; bh=eKxOMdVLi7foAPecMJPnypRGHkmKdpZWeQGAD2zvbAs=; h=From:To:Subject:Date:From; b=oP0CefuHpkL+3clj0T8YK93+knj2A+jmQE9LKkLdCGJs9QLAGBGUyoCKM8hqLzgNh uhv8Nn5YxXDlkCHXguty6KzB2S9gIY8COekHwbyR/Db7DjjU26vPTBEBzQSxWPfM7Z 7Fpgkay7xOTq9ovNLrnyA1tTWX9ocVifUmtqYxCY= From: "vries at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/96295] New: Wmaybe-uninitialized warning for range operator with empty range struct Date: Thu, 23 Jul 2020 07:56:08 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 11.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: vries at gcc dot gnu.org 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: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: 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: Thu, 23 Jul 2020 07:56:09 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D96295 Bug ID: 96295 Summary: Wmaybe-uninitialized warning for range operator with empty range struct Product: gcc Version: 11.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: vries at gcc dot gnu.org Target Milestone: --- Consider test-case tui-winsource.c (minimized from gdb sources, filed as gd= b PR https://sourceware.org/bugzilla/show_bug.cgi?id=3D26282): ... struct tui_source_window_iterator { public: typedef tui_source_window_iterator self_type; typedef void *value_type; explicit tui_source_window_iterator (void *it, void *end) {} explicit tui_source_window_iterator (void *it) {} bool operator!=3D (const self_type &other) const { return false; } value_type operator* () const { return (value_type)0; } self_type &operator++ () { return *this; } }; struct tui_source_windows { tui_source_window_iterator begin () const { return tui_source_window_iterator ((void *)0, (void *)0); } tui_source_window_iterator end () const { return tui_source_window_iterator ((void*)0); } }; void foo (void) { for (void *win : tui_source_windows ()) { (void)win; } } ... With gcc-10, we have: ... $ g++-10 -x c++ -Wall -O0 -g -c tui-winsource.c ... And with gcc-11 (g++-11 (SUSE Linux) 11.0.0 20200720 (experimental) [revisi= on 8764e9a3fc43f1117db77d1f056b6c3f15a29db3]): ... $ g++-11 -x c++ -Wall -O0 -g -c tui-winsource.c tui-winsource.c: In function =E2=80=98void foo()=E2=80=99: tui-winsource.c:34:40: warning: =E2=80=98=E2=80=99 may be used uni= nitialized [-Wmaybe-uninitialized] 34 | for (void *win : tui_source_windows ()) | ^ tui-winsource.c:20:30: note: by argument 1 of type =E2=80=98const tui_sourc= e_windows*=E2=80=99 to =E2=80=98tui_source_window_iterator tui_source_windows::begin() const=E2= =80=99 declared here 20 | tui_source_window_iterator begin () const | ^~~~~ tui-winsource.c:34:40: note: =E2=80=98=E2=80=99 declared here 34 | for (void *win : tui_source_windows ()) | ^ ... At gimple, we have: ... struct tui_source_windows & __for_range; struct tui_source_windows D.2465; try { __for_range =3D &D.2465; tui_source_windows::begin (__for_range); tui_source_windows::end (__for_range); ... So, strictly speaking the warning is correct, because &D.2465 is not initialized, and consequently __for_range is not initialized when it is pas= sed as argument to tui_source_windows::begin. But it shouldn't matter, because struct tui_source_windows is an empty stru= ct. Workaround is to add: ... struct tui_source_windows { + tui_source_windows () {} tui_source_window_iterator begin () const ... which gives us: ... struct tui_source_windows & __for_range; struct tui_source_windows D.2469; try { tui_source_windows::tui_source_windows (&D.2469); __for_range =3D &D.2469; tui_source_windows::begin (__for_range); tui_source_windows::end (__for_range); ...=