This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug middle-end/16502] inappropriate -Wunreachable-code warning from generic code


------- Additional Comments From sebor at roguewave dot com  2004-07-12 22:54 -------
If you experiment with some other compilers that issue a similar warning,
such as EDG eccp, you will find that they do not diagnose this case even
at the strictest setting and likely for the reason I gave -- because doing
so would make an otherwise helpful warning useless.

Incidentally, if it helps make my point, the warning happens to occur in
a textbook implementation of the std::uninitialized_fill_n() algorithm.
As an implementator of the template I have no idea whether the user-supplied
T can or cannot throw an exception but I am responsible for warnings coming
out of my code if users turn them on. My goal is to make sure user code
compiles cleanly with our implementation, regardless of the warning switches
they use.

$ cat t.cpp && g++ -Wunreachable-code -c t.cpp
#include <new>

namespace std {

template <class ForwardIterator, class Size, class T>
void uninitialized_fill_n (ForwardIterator first, Size n, const T& x)
{
    const ForwardIterator start = first;

    try {
        for (; n; --n, ++first)
            new (&*first) T (x);
    }
    catch (...) {
        while (start != first)
            start->~T ();
        throw;
    }
}

}

struct S { S () { } };

int main ()
{
    S s;

    std::uninitialized_fill_n (&s, 0, S ());
}

t.cpp: In function `void std::uninitialized_fill_n(ForwardIterator, Size, const
T&) [with ForwardIterator = S*, Size = int, T = S]':
t.cpp:29:   instantiated from here
t.cpp:14: warning: will never be executed
t.cpp:14: warning: will never be executed
t.cpp:14: warning: will never be executed
t.cpp:14: warning: will never be executed
t.cpp:14: warning: will never be executed
t.cpp:14: warning: will never be executed
t.cpp:14: warning: will never be executed
t.cpp:14: warning: will never be executed


-- 


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]