When turning -Wunreachable-code to get warning about code that might never be
executed, I noticed that gcc throws warnings on all the calls to htons.

This seems to be because htons is expanded as a macro, and indeed a function
written as

uint16_t my_htons(uint16_t val) {
  return htons(val);
}

is expanded by the preprocessor to

uint16_t my_htons(uint16_t val) {
  return (__extension__ ({ register unsigned short int __v, __x = (val); if
(__builtin_constant_p (__x)) __v = ((((__x) >> 8) & 0xff) | (((__x) & 0xff) <<
8)); else __asm__ ("rorw $8, %w0" : "=r" (__v) : "0" (__x) : "cc"); __v; }));
}

I guess the problem here is with the __builtin_constant_p() branch of the macro
since of course val is no constant.

I admit I'm not sure if this is fixable, but it certainly adds a lot of false
positive to -Wunreachable-code (which would otherwise be very useful at least
for C code).


-- 
           Summary: -Wunreachable-code warns for system headers macros
           Product: gcc
           Version: 4.3.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: flameeyes at gentoo dot org
 GCC build triplet: x86_64-pc-linux-gnu
  GCC host triplet: x86_64-pc-linux-gnu
GCC target triplet: x86_64-pc-linux-gnu


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

Reply via email to