[llvm-bugs] [Bug 40464] New: Don't warn me for issues in system headers

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Jan 25 07:38:02 PST 2019


https://bugs.llvm.org/show_bug.cgi?id=40464

            Bug ID: 40464
           Summary: Don't warn me for issues in system headers
           Product: clang
           Version: unspecified
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: barry.revzin at gmail.com
                CC: blitzrakete at gmail.com, dgregor at apple.com,
                    erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
                    richard-llvm at metafoo.co.uk

Simple example demonstrating the issue.

include/foo.h, a normal C header that does normal C things, like casting
arbitrarily without any concern for what types mean:

#pragma once

struct sockaddr {
    unsigned short sa_family;
    char sa_data[14];
};

struct sockaddr_in {
    short sin_family;
    unsigned short sin_port;
    unsigned long s_addr;
    char sin_zero[8];
};

typedef union __attribute__((__may_alias__)) {
  struct sockaddr    sa;
  struct sockaddr_in sin;
} U;

#define GET_PORT(sa) ((unsigned short)((U*)(sa))->sin.sin_port)
unsigned short get_port(struct sockaddr const* sa) { return GET_PORT(sa); }

foo_macro.cxx:

#include <foo.h>

int get(sockaddr const* s) {
    return GET_PORT(s);
}

foo_function.cxx, the same as above but just using the function version instead
of the macro version

#include <foo.h>

int get(sockaddr const* s) {
    return get_port(s);
}

When I compile with all warnings and treating the include as a system header:

$ clang++ -std=c++17 -Wall -Wextra -Wcast-qual -Wno-system-headers -isystem
include -c foo_function.cxx
$ 

$ clang++ -std=c++17 -Wall -Wextra -Wcast-qual -Wno-system-headers -isystem
include -c foo_macro.cxx 
foo_macro.cxx:4:12: warning: cast from 'const sockaddr *' to 'U *' drops const
qualifier [-Wcast-qual]
    return GET_PORT(s);
           ^
include/foo.h:20:44: note: expanded from macro 'GET_PORT'
#define GET_PORT(sa) ((unsigned short)((U*)(sa))->sin.sin_port)
                                           ^
1 warning generated.


I do not want to see this warning for the macro case - it's a system header,
please don't warn me about it. The behavior for foo_function.cxx is the correct
expected behavior. gcc correctly doesn't warn in either case. clang 4.0 did not
warn here, clang 5.0 and onward does.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20190125/98007b01/attachment.html>


More information about the llvm-bugs mailing list