public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/50276] New: Wrong "used uninitialized in this function" warning [C++0x]
@ 2011-09-02 12:45 bisqwit at iki dot fi
  2011-09-02 13:05 ` [Bug c++/50276] " bisqwit at iki dot fi
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: bisqwit at iki dot fi @ 2011-09-02 12:45 UTC (permalink / raw)
  To: gcc-bugs

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

             Bug #: 50276
           Summary: Wrong "used uninitialized in this function" warning
                    [C++0x]
    Classification: Unclassified
           Product: gcc
           Version: 4.6.1
            Status: UNCONFIRMED
          Severity: minor
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: bisqwit@iki.fi


For this example code, GCC mistakenly produces the following warning:
tmp.cc:10:5: warning: 'value' is used uninitialized in this function
[-Wuninitialized]
The warning is wrongly given, because there is no execution path that does not
assign a well-defined value to the variable. In fact, there are no branches at
all between the declaring and the assigning of the variable.

template<typename T>
unsigned testfun(const T& func)
{
    return func();
}

template<int i>
unsigned test()
{
    if(unsigned value = testfun( [] () { return 0; }))
    {
        return value;
    }
    return i;
}

int main()
{
    return test<1>();
}

The warning being wrongly given depends on the following conditions:
- "test()" being a template function: changing "i" into an actual parameter
removes the warning
- "func" being a functor: changing it into an integer parameter removes the
warning
- the variable "value" being declared and assigned to in the if-condition:
declaring and assigning it separately removes the warning.
- the "func" parameter being a lambda function: changing it into a static
method of a class removes the warning.

The following aspects do not affect the warning:
- "testfun()" being a template function: changing "T" into an explicit int(*)()
retains the warning
- whether "i" is used within "test()" or not
- adding "static" or "inline" attributes to any function did not change the
warning.

Tested on GCC 4.5.3 and GCC 4.6.1, on x86_64-linux-gnu in both 32-bit and
64-bit mode on all optimization modes.


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

* [Bug c++/50276] Wrong "used uninitialized in this function" warning [C++0x]
  2011-09-02 12:45 [Bug c++/50276] New: Wrong "used uninitialized in this function" warning [C++0x] bisqwit at iki dot fi
@ 2011-09-02 13:05 ` bisqwit at iki dot fi
  2011-09-14 21:11 ` [Bug c++/50276] [C++0x] Wrong "used uninitialized in this function" warning paolo.carlini at oracle dot com
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: bisqwit at iki dot fi @ 2011-09-02 13:05 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Joel Yliluoma <bisqwit at iki dot fi> 2011-09-02 13:04:31 UTC ---
Even this produces the warning. Changing any of the "0"s into "1" did not
affect the warning.

static inline unsigned testfun(void*)
{
    return 0;
}

template<int i>
static inline unsigned test()
{
    if(unsigned value = testfun( []() { return 0; } ))
        return value;
    return 0;
}

int main()
{
    return test<0>();
}


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

* [Bug c++/50276] [C++0x] Wrong "used uninitialized in this function" warning
  2011-09-02 12:45 [Bug c++/50276] New: Wrong "used uninitialized in this function" warning [C++0x] bisqwit at iki dot fi
  2011-09-02 13:05 ` [Bug c++/50276] " bisqwit at iki dot fi
@ 2011-09-14 21:11 ` paolo.carlini at oracle dot com
  2012-01-03 22:46 ` paolo.carlini at oracle dot com
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: paolo.carlini at oracle dot com @ 2011-09-14 21:11 UTC (permalink / raw)
  To: gcc-bugs

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

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2011-09-14
                 CC|                            |jason at gcc dot gnu.org
            Summary|Wrong "used uninitialized   |[C++0x] Wrong "used
                   |in this function" warning   |uninitialized in this
                   |[C++0x]                     |function" warning
     Ever Confirmed|0                           |1
           Severity|minor                       |normal

--- Comment #2 from Paolo Carlini <paolo.carlini at oracle dot com> 2011-09-14 21:03:48 UTC ---
Note: -Wuninitialized required.


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

* [Bug c++/50276] [C++0x] Wrong "used uninitialized in this function" warning
  2011-09-02 12:45 [Bug c++/50276] New: Wrong "used uninitialized in this function" warning [C++0x] bisqwit at iki dot fi
  2011-09-02 13:05 ` [Bug c++/50276] " bisqwit at iki dot fi
  2011-09-14 21:11 ` [Bug c++/50276] [C++0x] Wrong "used uninitialized in this function" warning paolo.carlini at oracle dot com
@ 2012-01-03 22:46 ` paolo.carlini at oracle dot com
  2012-01-03 23:02 ` paolo.carlini at oracle dot com
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: paolo.carlini at oracle dot com @ 2012-01-03 22:46 UTC (permalink / raw)
  To: gcc-bugs

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

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |wrong-code

--- Comment #3 from Paolo Carlini <paolo.carlini at oracle dot com> 2012-01-03 22:46:33 UTC ---
If I consider Comment #1, and maybe I tweak it a bit like this:

bool testfun(void*)
{
  return true;
}

template<int i>
bool test()
{
  if (bool value = /* true */ testfun( []() { return 0; } ))
    return value;

  __builtin_abort();

  return false;
}

int main()
{
  test<0>();
}

I see what looks like a full fledged miscompilation: testfun always returns
true, thus test should simply return true!  Jason, what do you think?


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

* [Bug c++/50276] [C++0x] Wrong "used uninitialized in this function" warning
  2011-09-02 12:45 [Bug c++/50276] New: Wrong "used uninitialized in this function" warning [C++0x] bisqwit at iki dot fi
                   ` (2 preceding siblings ...)
  2012-01-03 22:46 ` paolo.carlini at oracle dot com
@ 2012-01-03 23:02 ` paolo.carlini at oracle dot com
  2012-01-03 23:16 ` bisqwit at iki dot fi
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: paolo.carlini at oracle dot com @ 2012-01-03 23:02 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Paolo Carlini <paolo.carlini at oracle dot com> 2012-01-03 23:01:53 UTC ---
But actually the test in Comment #1 (and #3) is rejected if test isn't a
template, thus looks like an accepts-invalid, miscompiled.

The first testcase is not. Probably the issues are related, though.


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

* [Bug c++/50276] [C++0x] Wrong "used uninitialized in this function" warning
  2011-09-02 12:45 [Bug c++/50276] New: Wrong "used uninitialized in this function" warning [C++0x] bisqwit at iki dot fi
                   ` (3 preceding siblings ...)
  2012-01-03 23:02 ` paolo.carlini at oracle dot com
@ 2012-01-03 23:16 ` bisqwit at iki dot fi
  2013-03-05 17:42 ` jason at gcc dot gnu.org
  2013-03-05 18:59 ` jason at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: bisqwit at iki dot fi @ 2012-01-03 23:16 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Joel Yliluoma <bisqwit at iki dot fi> 2012-01-03 23:16:07 UTC ---
It also accepts this code without complaints, which is another error:

template<int i>
bool test()
{
  if (bool value = this_identifier_has_not_been_declared( []() {} ))
    return value;

  __builtin_abort();

  return false;
}

int main()
{
  test<0>();
}

The wrong-code problem occurs also with this code:

template<int i>
bool test()
{
  if (bool value = []() { return 1; } )
    return value;

  __builtin_abort();

  return false;
}

int main()
{
  test<0>();
}


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

* [Bug c++/50276] [C++0x] Wrong "used uninitialized in this function" warning
  2011-09-02 12:45 [Bug c++/50276] New: Wrong "used uninitialized in this function" warning [C++0x] bisqwit at iki dot fi
                   ` (4 preceding siblings ...)
  2012-01-03 23:16 ` bisqwit at iki dot fi
@ 2013-03-05 17:42 ` jason at gcc dot gnu.org
  2013-03-05 18:59 ` jason at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: jason at gcc dot gnu.org @ 2013-03-05 17:42 UTC (permalink / raw)
  To: gcc-bugs


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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED
   Target Milestone|---                         |4.8.0

--- Comment #6 from Jason Merrill <jason at gcc dot gnu.org> 2013-03-05 17:41:39 UTC ---
This seems to have been fixed by one of my lambda patches for 4.8.


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

* [Bug c++/50276] [C++0x] Wrong "used uninitialized in this function" warning
  2011-09-02 12:45 [Bug c++/50276] New: Wrong "used uninitialized in this function" warning [C++0x] bisqwit at iki dot fi
                   ` (5 preceding siblings ...)
  2013-03-05 17:42 ` jason at gcc dot gnu.org
@ 2013-03-05 18:59 ` jason at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: jason at gcc dot gnu.org @ 2013-03-05 18:59 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #7 from Jason Merrill <jason at gcc dot gnu.org> 2013-03-05 18:58:41 UTC ---
Author: jason
Date: Tue Mar  5 18:58:36 2013
New Revision: 196472

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=196472
Log:
    PR c++/50276
    * g++.dg/cpp0x/lambda/lambda-template10.C: New.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-template10.C


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

end of thread, other threads:[~2013-03-05 18:59 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-09-02 12:45 [Bug c++/50276] New: Wrong "used uninitialized in this function" warning [C++0x] bisqwit at iki dot fi
2011-09-02 13:05 ` [Bug c++/50276] " bisqwit at iki dot fi
2011-09-14 21:11 ` [Bug c++/50276] [C++0x] Wrong "used uninitialized in this function" warning paolo.carlini at oracle dot com
2012-01-03 22:46 ` paolo.carlini at oracle dot com
2012-01-03 23:02 ` paolo.carlini at oracle dot com
2012-01-03 23:16 ` bisqwit at iki dot fi
2013-03-05 17:42 ` jason at gcc dot gnu.org
2013-03-05 18:59 ` jason at gcc dot gnu.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).