From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 55BF8385800F; Fri, 19 Nov 2021 03:38:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 55BF8385800F From: "cvs-commit at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/21678] Using inline disables warnings about missing return statements Date: Fri, 19 Nov 2021 03:38:29 +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: unknown X-Bugzilla-Keywords: diagnostic X-Bugzilla-Severity: normal X-Bugzilla-Who: cvs-commit at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 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 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: Fri, 19 Nov 2021 03:38:30 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D21678 --- Comment #9 from CVS Commits --- The trunk branch has been updated by Marek Polacek : https://gcc.gnu.org/g:0790c8aacdfb4fd096aa580dae0fe49172c43ab2 commit r12-5391-g0790c8aacdfb4fd096aa580dae0fe49172c43ab2 Author: Marek Polacek Date: Tue Nov 10 20:07:24 2020 -0500 c++: Implement -Wuninitialized for mem-initializers (redux) [PR19808] 2021 update: Last year I posted a version of this patch: but it didn't make it in. The main objection seemed to be that the patch tried to do too much, and overlapped with the ME uninitialized warnings. Since the patch used walk_tree without any data flow info, it issued false positives for things like a(0 ? b : 42) and similar. I'll admit I've been dreading resurrecting this because of the lack of clarity about where we should warn about what. On the other hand, I think we really should do something about this. So I've simplified the original patch as much as it seemed reasonable. For instance, it doesn't even attempt to handle cases like "a((b =3D 42)), c(b)" -- for these I simply give up for the whole mem-initializer (but who writes code like that, anyway?). I also give up when a member is initialized with a function call, because we don't know what the call could do. See Wuninitialized-17.C, for which clang emits a false positive but we don't. I remember having a hard time dealing with initializer lists in my previous patch, so now I only handle simple a{b} cases, but no more. It turned out that this abridged version still warns about 90% cases where users would expect a warning. More complicated cases are left for the ME, which, for unused inline functions, will only warn with -fkeep-inline-functions, but so be it. (This is bug 21678.) This patch implements the long-desired -Wuninitialized warning for member initializer lists, so that the front end can detect bugs like struct A { int a; int b; A() : b(1), a(b) { } }; where the field 'b' is used uninitialized because the order of member initializers in the member initializer list is irrelevant; what matters is the order of declarations in the class definition. I've implemented this by keeping a hash set holding fields that are not initialized yet, so at first it will be {a, b}, and after initializing 'a' it will be {b} and so on. Then I use walk_tree to walk the initializer and if we see that an uninitialized object is used, we warn. Of course, when we use the address of the object, we may not warn: struct B { int &r; int *p; int a; B() : r(a), p(&a), a(1) { } // ok }; Likewise, don't warn in unevaluated contexts such as sizeof. Classes without an explicit initializer may still be initialized by their default constructors; whether or not something is considered initialized is handled in perform_member_init, see member_initialized_p. PR c++/19808 PR c++/96121 gcc/cp/ChangeLog: * init.c (perform_member_init): Remove a forward declaration. Walk the initializer using find_uninit_fields_r. New parameter to track uninitialized fields. If a member is initialized, remove it from the hash set. (perform_target_ctor): Return the initializer. (struct find_uninit_data): New class. (find_uninit_fields_r): New function. (find_uninit_fields): New function. (emit_mem_initializers): Keep and initialize a set holding fiel= ds that are not initialized. When handling delegating constructor= s, walk the constructor tree using find_uninit_fields_r. Also when initializing base clases. Pass uninitialized down to perform_member_init. gcc/ChangeLog: * doc/invoke.texi: Update documentation for -Wuninitialized. * tree.c (stabilize_reference): Set location. gcc/testsuite/ChangeLog: * g++.dg/warn/Wuninitialized-14.C: New test. * g++.dg/warn/Wuninitialized-15.C: New test. * g++.dg/warn/Wuninitialized-16.C: New test. * g++.dg/warn/Wuninitialized-17.C: New test. * g++.dg/warn/Wuninitialized-18.C: New test. * g++.dg/warn/Wuninitialized-19.C: New test. * g++.dg/warn/Wuninitialized-20.C: New test. * g++.dg/warn/Wuninitialized-21.C: New test. * g++.dg/warn/Wuninitialized-22.C: New test. * g++.dg/warn/Wuninitialized-23.C: New test. * g++.dg/warn/Wuninitialized-24.C: New test. * g++.dg/warn/Wuninitialized-25.C: New test. * g++.dg/warn/Wuninitialized-26.C: New test. * g++.dg/warn/Wuninitialized-27.C: New test. * g++.dg/warn/Wuninitialized-28.C: New test. * g++.dg/warn/Wuninitialized-29.C: New test. * g++.dg/warn/Wuninitialized-30.C: New test.=