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

Eric Gallager <egallager at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2017-08-18
                 CC|                            |egallager at gcc dot gnu.org
     Ever confirmed|0                           |1

--- Comment #2 from Eric Gallager <egallager at gcc dot gnu.org> ---
(In reply to matferib from comment #0)
> This code issues a warning:
> 
> g++ -Wall
> int i = 5 + i;
> warning: ā€˜iā€™ may be used uninitialized in this function
> 
> This code does not:
> string s = string("str") + s;
> 
> Neither this:
> string s(string("str") + s);
> 
> Shouldnt the 2 last ones issue warnings too?

(In reply to Jonathan Wakely from comment #1)
> The string case calls a function (the overloaded operator+ or std::string)
> so is actually closer to:
> 
>   int f(int);
>   int i = f(i);
> 
> which doesn't warn either (although it should do, ideally)
> 
> This is similar to PR 48483, maybe even a dup.

So, I combined all the snippets into a single testcase, and g++ doesn't even
warn on the first one anymore:

$ cat 48829.cc
#include <string>

using namespace std;

int i = 5 + i;

string s = string("str") + s;

string ss(string("str") + ss);

int f(int);
int ii = f(ii);
$ /usr/local/bin/g++ -c -Wall -Wextra -pedantic -Wuninitialized -Winit-self
-Weffc++ -O2 48829.cc
$ 

Same with all other optimization levels I tried. So, confirmed.

Reply via email to