[Bug c++/21678] Using inline disables warnings about missing return statements

2021-12-09 Thread jason at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=21678

Jason Merrill  changed:

   What|Removed |Added

 CC||jason at gcc dot gnu.org

--- Comment #10 from Jason Merrill  ---
(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.

[Bug c++/21678] Using inline disables warnings about missing return statements

2021-11-18 Thread cvs-commit at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=21678

--- 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 = 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 
int *p;
int a;
B() : r(a), p(), 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.
   

[Bug c++/21678] Using inline disables warnings about missing return statements

2021-11-07 Thread mpolacek at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=21678

Marek Polacek  changed:

   What|Removed |Added

 CC||mpolacek at gcc dot gnu.org

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

[Bug c++/21678] Using inline disables warnings about missing return statements

2019-02-03 Thread msebor at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=21678

Martin Sebor  changed:

   What|Removed |Added

 CC||msebor at gcc dot gnu.org
  Known to fail|4.1.0   |4.1.3, 4.3.5, 4.4.7, 4.8.5,
   ||4.9.4, 5.4.0, 6.4.0, 7.3.0,
   ||8.2.0, 9.0

--- Comment #7 from Martin Sebor  ---
No change in GCC 9.  The problem affects both C and C++.

$ cat pr21678.C && gcc -S -Wall -Wextra -xc pr21678.C
static inline __attribute__((always_inline)) int foo(int a)
{
  if (a==0)
 return 0;
}


Clang issues the expected diagnostic in both modes:

$ clang -S pr21678.C 
pr21678.C:5:1: warning: control may reach end of non-void function
  [-Wreturn-type]
}
^
1 warning generated.

[Bug c++/21678] Using inline disables warnings about missing return statements

2019-02-03 Thread msebor at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=21678

Martin Sebor  changed:

   What|Removed |Added

 CC||skvadrik at gmail dot com

--- Comment #6 from Martin Sebor  ---
*** Bug 80458 has been marked as a duplicate of this bug. ***

[Bug c++/21678] Using inline disables warnings about missing return statements

2006-10-17 Thread rguenth at gcc dot gnu dot org


--- 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



[Bug c++/21678] Using inline disables warnings about missing return statements

2006-10-17 Thread mueller at gcc dot gnu dot org


--- 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



[Bug c++/21678] Using inline disables warnings about missing return statements

2006-10-16 Thread pinskia at gcc dot gnu dot org


--- 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



[Bug c++/21678] Using inline disables warnings about missing return statements

2006-10-16 Thread pinskia at gcc dot gnu dot org


--- 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