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 c++/16502] New: inappropriate -Wunreachable-code warning from generic code


I don't think the warning below is appropriate in generic code. The author
of foo rarely knows what type the template will be instantiated on in user
code, so there is little he can do to prevent the warning. Similarly, users
unaware of foo's implementation details who turn on the warning can do
little to prevent it if foo is in a third party header. Finally, even if
the warning were appropriate, emitting it once should be enough.

$ cat t.cpp && gcc --version && gcc -c -Wunreachable-code t.cpp
/*   1 */ #include <new>
/*   2 */ 
/*   3 */ template <class T>
/*   4 */ void foo (T *p)
/*   5 */ {
/*   6 */     try {
/*   7 */         new (p) T;
/*   8 */     }
/*   9 */     catch (...) {
/*  10 */         *p = T ();
/*  11 */     } 
/*  12 */ }
/*  13 */ 
/*  14 */ int main ()
/*  15 */ {
/*  16 */     int i;
/*  17 */     foo (&i);
/*  18 */ }
gcc (GCC) 3.4.0
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.

t.cpp: In function `void foo(T*) [with T = int]':
t.cpp:17:   instantiated from here
t.cpp:9: warning: will never be executed
t.cpp:9: warning: will never be executed
t.cpp:9: warning: will never be executed

-- 
           Summary: inappropriate -Wunreachable-code warning from generic
                    code
           Product: gcc
           Version: 3.4.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: sebor at roguewave dot com
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: *-*-*
  GCC host triplet: *-*-*
GCC target triplet: *-*-*


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]