uninitialized var in list

This is a discussion on uninitialized var in list within the C++ Programming forums, part of the General Programming Boards category; Code: #include <list> #include <string> using namespace std; int main () { list<string> mylist; mylist.push_back("test"); } Generates this warning. ..\include\c++.4.5\bits\stl_list.h:435: ...

  1. #1
    Registered Abuser
    Join Date
    Jun 2006
    Location
    Toronto
    Posts
    591

    uninitialized var in list

    Code:
    #include <list>
    #include <string>
    using namespace std;
    int main ()
    {
      list<string> mylist;
      mylist.push_back("test");
    }
    Generates this warning.
    ..\include\c++\3.4.5\bits\stl_list.h:435: warning: '__p' might be used uninitialized in this function
    Now I'm not inclined to surf through cryptic library code, but I'm assuming the most basic use of a list should at least compile warning-free.

  2. #2
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,183
    What compiler and what version?

    gcc 4.2.3 on Linux gives me no warning/error even with "-Wall -pedantic -ansi".

  3. #3
    Registered Abuser
    Join Date
    Jun 2006
    Location
    Toronto
    Posts
    591
    occurs in both MingW 3.4.4 and 3.4.5 with -w and -pedantic -errors
    I wonder if this is why I get so many retarded warnings with C++....

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,914
    Strangely (and yet as expected), I get no warnings when I compile that program with the MinGW port of g++ 3.4.5 on Windows XP SP3.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Registered Abuser
    Join Date
    Jun 2006
    Location
    Toronto
    Posts
    591
    Hmm yeah, I've just tried invoking mingw32-g++ -w -pedantic directly from the command shell and all seems well....

    Well I thought my IDE was purely evil, until I disabled optimizations, and bingo!
    So I tried:
    Code:
    mingw32-g++ test.cpp -Wall -s -Os -O3 -fexpensive-optimizations
    and got it to repro.
    Maybe it's common knowledge, but I was under the impression that compiler optimizations should have no affect on compile-time standards compliance.

  6. #6
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,047
    FWIW: with a few different versions of g++ (4.1, 4.2, and 4.3) under Linux, I get no such warning.
    Code:
    $ cat list.cpp
    #include <list>
    #include <string>
    using namespace std;
    int main ()
    {
      list<string> mylist;
      mylist.push_back("test");
    }
    $ g++
    g++      g++-4.1  g++-4.2  g++-4.3
    $ g++ --version
    g++ (Debian 4.3.1-9) 4.3.1
    Copyright (C) 2008 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.
    
    $ g++ -Wall -s -Os -O3 -fexpensive-optimizations list.cpp -o list
    $ g++-4.2 -Wall -s -Os -O3 -fexpensive-optimizations list.cpp -o list
    $ g++-4.1 -Wall -s -Os -O3 -fexpensive-optimizations list.cpp -o list
    $
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  7. #7
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    Yeah, GCC only gives such warnings if it computes control and data flow, which it does only when optimizing.

    Possibly 3.4.5's standard library has a bug. The problem of the MinGW project is that they're so far behind in the supported compiler version.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  8. #8
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,183
    I always use this distribution when I'm on Windows

    http://nuwen.net/mingw.html

    They have gcc 4.2.1 and includes several common libraries (boost, SDL, etc).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Following CTools
    By EstateMatt in forum C Programming
    Replies: 5
    Last Post: 06-26-2008, 10:10 AM
  2. instantiated from here: errors...
    By advocation in forum C++ Programming
    Replies: 5
    Last Post: 03-27-2005, 08:01 AM
  3. How can I traverse a huffman tree
    By carrja99 in forum C++ Programming
    Replies: 3
    Last Post: 04-28-2003, 05:46 PM
  4. List class
    By SilasP in forum C++ Programming
    Replies: 0
    Last Post: 02-10-2002, 04:20 PM
  5. singly linked list
    By clarinetster in forum C Programming
    Replies: 2
    Last Post: 08-26-2001, 10:21 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21