Menu

#1256 Invalid Warning Message When Using -O1 -O2 -O3

OTHER
closed
nobody
gcc (462)
out-of-date
Unknown
2014-08-18
2009-02-19
Jim Pattee
No

Using g++ 3.4.5 compiler

A statement where a pointer variable is initialized with a function, like this:
char* textOut = AStyleMain(cpp.text, options, errorHandler, memoryAlloc);

No problem if the options -O1 -O2 -O3 are NOT used.

When one of the options is used it gets the warning:
warning: 'textOut' might be used uninitialized in this function

Discussion

  • Jim Pattee

    Jim Pattee - 2009-02-19

    Actually, there seems to be more involved than a pointer variable initialized with a function.

    I am trying to create a test case that I will attach if I can get it to duplicate the problem.

     
  • Jim Pattee

    Jim Pattee - 2009-02-21

    Mingw test

     
  • Jim Pattee

    Jim Pattee - 2009-02-21

    Using Windows Vista
    gcc version 3.4.5 (mingw-vista special r3)
    GNU ld version 2.17.50 20060824
    Microsoft shell, (cmd.exe)

    Attached is a test case for the problem. I tried to create a small test case but was unable to deterine the exact cause of the problem. The source files are small and it should compile and run in less than a minute. The original compile got over 150 warnings. I have removed all but a few of them.

    The test can be compiled with the included "mingw-test.bat" file. You may need to change the variable "mingwdir" to the file path of your compiler. Then double click on the batch fle to compile.

    The warning messages are in the first two compiles. There is a pause statement after each compile. The first compile has the warning described originally. The second has the same warning but it is for mingw header files (stl_vector.h and stl_uninitialized.h).

    It you want to compile with an IDE, create a project with all the files in the folders src-astyle and src-unittest++ (including sub folders). Compile with the options -W and -O1. The options -O, -O2, and -O3 will also cause the warning. It disappears if the optimize options are not used. The debug option (-g) does not make a difference.

     
  • Sebastian Waschik

    While using Boost-Test there also a warning occur for a const int variable. The following text is for mingw at msys. The same also occurs for current CYGWIN_NT-5.1 1.5.25(0.156/4/2) (g++ 3.4.4, boost 1.33.1, "unit_test.hpp" changed to "unit_test_framework.hpp", "BOOST_TEST_CHECKPOINT" changed to "BOOST_CHECKPOINT").

    If I remove the second BOOST_CHECK_THROW the warning disappears. I have not checked to replace the macro completely but the expanded text, but I do not know any why it would be possible a const int value could be uninitialized (line 19).

    $ cat warning-test.cc
    #define BOOST_TEST_MODULE warning_test /* 1 */
    #define BOOST_AUTO_TEST_MAIN /* 2 */
    /* 3 */
    #include <boost/test/included/unit_test.hpp> /* 4 */
    #include <boost/test/auto_unit_test.hpp> /* 5 */
    /* 6 */
    /* 7 */
    class WarningException /* 8 */
    {}; /* 9 */
    int warningF(void) { /* 10 */
    return 1; /* 11 */
    } /* 12 */
    void warningG(int) { /* 13 */
    throw WarningException(); /* 14 */
    } /* 15 */
    void warningH(void) { /* 16 */
    BOOST_TEST_CHECKPOINT("TEST"); /* 17 */
    /* 18 */
    const int value(warningF()); /* 19 */
    /* 20 */
    BOOST_CHECK_THROW(warningG(value), /* 21 */
    WarningException); /* 22 */
    BOOST_CHECK_THROW(warningG(value), /* 23 */
    WarningException); /* 24 */
    } /* 25 */
    /* 26 */
    BOOST_AUTO_TEST_CASE(testFunct) /* 27 */
    { /* 28 */
    } /* 29 */

    $ g++ -I/usr/local/include -O -Wuninitialized warning-test.cc

    In file included from C:/msys/1.0/local/include/boost/test/included/unit_test.hpp:20,
    from warning-test.cc:4:
    C:/msys/1.0/local/include/boost/test/impl/framework.ipp: In function `void boost::unit_test::framework::run(boost::unit_test::test_unit_id, bool)':
    C:/msys/1.0/local/include/boost/test/impl/framework.ipp:363: warning: 'call_start_finish' might be used uninitialized in this function
    C:/msys/1.0/local/include/boost/test/impl/framework.ipp:364: warning: 'was_in_progress' might be used uninitialized in this function
    warning-test.cc: In function `void warningH()':
    warning-test.cc:19: warning: 'value' might be used uninitialized in this function

    $ g++ --version
    g++.exe (GCC) 3.4.5 (mingw-vista special r3)
    Copyright (C) 2004 Free Software Foundation, Inc.
    This is free software; see the source for copying conditions. There is NO
    warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

    $ uname -s -r -v -m -p -i -o
    MINGW32_NT-5.1 1.0.11(0.46/3/2) 2007-01-12 12:05 i686 unknown unknown Msys

    $ grep "define BOOST_LIB_VERSION" /usr/local/include/boost/version.hpp
    #define BOOST_LIB_VERSION "1_34_1"

     
  • Earnie Boyd

    Earnie Boyd - 2013-02-06
    • status: open --> closed
    • resolution: --> out-of-date
    • category: --> Unknown
    • milestone: --> OTHER