<html>
<head>
<base href="https://bugs.llvm.org/">
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW - Don't warn me for issues in system headers"
href="https://bugs.llvm.org/show_bug.cgi?id=40464">40464</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Don't warn me for issues in system headers
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>unspecified
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>enhancement
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>C++
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>barry.revzin@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>blitzrakete@gmail.com, dgregor@apple.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
</td>
</tr></table>
<p>
<div>
<pre>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.</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>