[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#487075: warning: will never be executed



Package: libstdc++6-4.1-dev in etch of architecture i386

When compiling programs which use "/usr/include/c++/4.1.2/bits/streambuf_iterator.h" with gcc, and including the flag "-Wunreachable-code", the compiler informs me that the header file contains unreachable code. Now I know this is not an "error", but maybe one could optimize the code found in the header based on the compilers suggestions.

I am using:
Linux 2.6.18-6-686 i686 GNU/Linux (Debian Etch)

Sample code (taken from "http://www2.roguewave.com/support/docs/leif/sourcepro/html/stdlibref/istreambuf-iterator.html";):

//
//  istreambuf_iterator.cpp
//
 
#include <iostream>   // for cout, endl
#include <fstream>    // for ofstream, istreambuf_iterator

#include <stdio.h>    // for tmpnam () and remove ()

int main ( )
{
    // create a temporary filename
    const char *fname = tmpnam (0);

    if (!fname)
        return 1;

    // open the file is_iter.out for reading and writing
    std::ofstream out (fname, std::ios::out | std::ios::in | 
                              std::ios::trunc);

    // output the example sentence into the file
    out << "Ceci est un simple exemple pour démontrer le\n"
           "fonctionnement de istreambuf_iterator.";

    // seek to the beginning of the file
    out.seekp (0);

    // construct an istreambuf_iterator pointing to
    // the ofstream object underlying streambuffer
    std::istreambuf_iterator<char, std::char_traits<char> > 
                             iter (out.rdbuf ());

    // construct an end of stream iterator
    const std::istreambuf_iterator<char, 
                                   std::char_traits<char> > end;

    std::cout << std::endl;

    // output the content of the file
    while (!iter.equal (end)) {

        // use both operator++ and operator*
        std::cout << *iter++;
    }

    std::cout << std::endl; 

    // remove temporary file
    remove (fname);

    return 0;
}

Sample compiling run:

g++ -Wunreachable-code -o prog main.cpp
/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/fstream: In constructor &#8216;std::basic_ofstream<_CharT, _Traits>::basic_ofstream(const char*, std::_Ios_Openmode) [with _CharT = char, _Traits = std::char_traits<char>]&#8217;:
/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/fstream:573: warning: will never be executed
/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/fstream:573: warning: will never be executed
/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/fstream:573: warning: will never be executed
/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/fstream:573: warning: will never be executed
/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/fstream:575: warning: will never be executed
/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/fstream:576: warning: will never be executed
/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/basic_ios.h: In constructor &#8216;std::basic_ios<_CharT, _Traits>::basic_ios() [with _CharT = char, _Traits = std::char_traits<char>]&#8217;:
/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/basic_ios.h:447: warning: will never be executed
/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/ostream: In constructor &#8216;std::basic_ostream<_CharT, _Traits>::basic_ostream() [with _CharT = char, _Traits = std::char_traits<char>]&#8217;:
/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/ostream:341: warning: will never be executed
/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/ostream:341: warning: will never be executed
/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/ostream:341: warning: will never be executed
/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/ostream:341: warning: will never be executed
/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/ostream:341: warning: will never be executed
/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/ostream: In destructor &#8216;std::basic_ostream<_CharT, _Traits>::~basic_ostream() [with _CharT = char, _Traits = std::char_traits<char>]&#8217;:
/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/ostream:113: warning: will never be executed
/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/ostream:113: warning: will never be executed
/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/ostream:113: warning: will never be executed
/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/streambuf_iterator.h: In constructor &#8216;std::istreambuf_iterator<_CharT, _Traits>::istreambuf_iterator(std::basic_streambuf<_CharT, _Traits>*) [with _CharT = char, _Traits = std::char_traits<char>]&#8217;:
/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/streambuf_iterator.h:87: warning: will never be executed
/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/streambuf_iterator.h: In constructor &#8216;std::istreambuf_iterator<_CharT, _Traits>::istreambuf_iterator() [with _CharT = char, _Traits = std::char_traits<char>]&#8217;:
/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/streambuf_iterator.h:79: warning: will never be executed
/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/fstream: In destructor &#8216;std::basic_ofstream<_CharT, _Traits>::~basic_ofstream() [with _CharT = char, _Traits = std::char_traits<char>]&#8217;:
/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/fstream:586: warning: will never be executed
/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/fstream:586: warning: will never be executed
/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/fstream:586: warning: will never be executed
/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/fstream:586: warning: will never be executed
/tmp/ccqvH2F0.o: In function `main':
main.cpp:(.text+0x8f): warning: the use of `tmpnam' is dangerous, better use `mkstemp'




Reply to: