public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/21678] Using inline disables warnings about missing return statements
       [not found] <bug-21678-4@http.gcc.gnu.org/bugzilla/>
@ 2021-11-07 15:33 ` mpolacek at gcc dot gnu.org
  2021-11-19  3:38 ` cvs-commit at gcc dot gnu.org
  2021-12-09 22:06 ` jason at gcc dot gnu.org
  2 siblings, 0 replies; 7+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2021-11-07 15:33 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=21678

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |mpolacek at gcc dot gnu.org

--- Comment #8 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
This came up again in
https://gcc.gnu.org/pipermail/gcc-patches/2021-November/583592.html

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/21678] Using inline disables warnings about missing return statements
       [not found] <bug-21678-4@http.gcc.gnu.org/bugzilla/>
  2021-11-07 15:33 ` [Bug c++/21678] Using inline disables warnings about missing return statements mpolacek at gcc dot gnu.org
@ 2021-11-19  3:38 ` cvs-commit at gcc dot gnu.org
  2021-12-09 22:06 ` jason at gcc dot gnu.org
  2 siblings, 0 replies; 7+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-11-19  3:38 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=21678

--- Comment #9 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Marek Polacek <mpolacek@gcc.gnu.org>:

https://gcc.gnu.org/g:0790c8aacdfb4fd096aa580dae0fe49172c43ab2

commit r12-5391-g0790c8aacdfb4fd096aa580dae0fe49172c43ab2
Author: Marek Polacek <polacek@redhat.com>
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:
    <https://gcc.gnu.org/pipermail/gcc-patches/2020-November/559162.html>
    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 = 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 fields
            that are not initialized.  When handling delegating constructors,
            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.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/21678] Using inline disables warnings about missing return statements
       [not found] <bug-21678-4@http.gcc.gnu.org/bugzilla/>
  2021-11-07 15:33 ` [Bug c++/21678] Using inline disables warnings about missing return statements mpolacek at gcc dot gnu.org
  2021-11-19  3:38 ` cvs-commit at gcc dot gnu.org
@ 2021-12-09 22:06 ` jason at gcc dot gnu.org
  2 siblings, 0 replies; 7+ messages in thread
From: jason at gcc dot gnu.org @ 2021-12-09 22:06 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=21678

Jason Merrill <jason at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jason at gcc dot gnu.org

--- Comment #10 from Jason Merrill <jason at gcc dot gnu.org> ---
(In reply to Richard Biener from comment #4)
> Actually with inline functions we don't reach building the cfg but throw
> away the function early:

I think that's a mistake; we shouldn't throw away the function until after
we've done enough to check for (some?) warnings.  Inline functions usually
aren't big enough for this to make a significant difference to compile time.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/21678] Using inline disables warnings about missing return statements
       [not found] <bug-21678-253@http.gcc.gnu.org/bugzilla/>
                   ` (2 preceding siblings ...)
  2006-10-17  9:20 ` rguenth at gcc dot gnu dot org
@ 2006-10-17  9:34 ` mueller at gcc dot gnu dot org
  3 siblings, 0 replies; 7+ messages in thread
From: mueller at gcc dot gnu dot org @ 2006-10-17  9:34 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from mueller at gcc dot gnu dot org  2006-10-17 09:34 -------
take a look at the testcase in bugreport 29485 - there it should have at least
instantiated the method


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21678


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/21678] Using inline disables warnings about missing return statements
       [not found] <bug-21678-253@http.gcc.gnu.org/bugzilla/>
  2006-10-16 17:04 ` pinskia at gcc dot gnu dot org
  2006-10-16 17:05 ` pinskia at gcc dot gnu dot org
@ 2006-10-17  9:20 ` rguenth at gcc dot gnu dot org
  2006-10-17  9:34 ` mueller at gcc dot gnu dot org
  3 siblings, 0 replies; 7+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2006-10-17  9:20 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from rguenth at gcc dot gnu dot org  2006-10-17 09:19 -------
Actually with inline functions we don't reach building the cfg but throw away
the function early:

Initial entry points:
Unit entry points:

Initial callgraph:

int fii(int*)/0: tree finalized
  called by:
  calls:

Reclaiming functions: int fii(int*)

Reclaimed callgraph:

...


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21678


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/21678] Using inline disables warnings about missing return statements
       [not found] <bug-21678-253@http.gcc.gnu.org/bugzilla/>
  2006-10-16 17:04 ` pinskia at gcc dot gnu dot org
@ 2006-10-16 17:05 ` pinskia at gcc dot gnu dot org
  2006-10-17  9:20 ` rguenth at gcc dot gnu dot org
  2006-10-17  9:34 ` mueller at gcc dot gnu dot org
  3 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-10-16 17:05 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from pinskia at gcc dot gnu dot org  2006-10-16 17:04 -------
*** Bug 29485 has been marked as a duplicate of this bug. ***


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |mueller at gcc dot gnu dot
                   |                            |org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21678


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/21678] Using inline disables warnings about missing return statements
       [not found] <bug-21678-253@http.gcc.gnu.org/bugzilla/>
@ 2006-10-16 17:04 ` pinskia at gcc dot gnu dot org
  2006-10-16 17:05 ` pinskia at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-10-16 17:04 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from pinskia at gcc dot gnu dot org  2006-10-16 17:04 -------
Actually for C++, any inline disables the warning:
inline int fii(int *other)
{
  if(!other)return 0;
}


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|Using inline + always_inline|Using inline disables
                   |disables warnings about     |warnings about missing
                   |missing return statements   |return statements


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21678


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2021-12-09 22:06 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-21678-4@http.gcc.gnu.org/bugzilla/>
2021-11-07 15:33 ` [Bug c++/21678] Using inline disables warnings about missing return statements mpolacek at gcc dot gnu.org
2021-11-19  3:38 ` cvs-commit at gcc dot gnu.org
2021-12-09 22:06 ` jason at gcc dot gnu.org
     [not found] <bug-21678-253@http.gcc.gnu.org/bugzilla/>
2006-10-16 17:04 ` pinskia at gcc dot gnu dot org
2006-10-16 17:05 ` pinskia at gcc dot gnu dot org
2006-10-17  9:20 ` rguenth at gcc dot gnu dot org
2006-10-17  9:34 ` mueller at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).