<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 - typeof(const members of struct), -std=gnu89, and -Wduplicate-decl-specifier vs gcc7.1"
href="https://bugs.llvm.org/show_bug.cgi?id=32985">32985</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>typeof(const members of struct), -std=gnu89, and -Wduplicate-decl-specifier vs gcc7.1
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>4.0
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>All
</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>libclang
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>ndesaulniers@google.com
</td>
</tr>
<tr>
<th>CC</th>
<td>klimek@google.com, llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>Created <span class=""><a href="attachment.cgi?id=18425" name="attach_18425" title="test case">attachment 18425</a> <a href="attachment.cgi?id=18425&action=edit" title="test case">[details]</a></span>
test case
when I compile the attached code with the following flags, I get a warning w/
clang 4.0 & clang 3.8, but not gcc 7.1.
➜ tmp clang test_case.c -Wduplicate-decl-specifier -std=gnu89
test_case.c:10:5: warning: duplicate 'const' declaration specifier
[-Wduplicate-decl-specifier]
const typeof( ((const struct x*)0)->member ) *__mptr = (z);
^
1 warning generated.
it seems that if I remove either `const` declarations in front of NULL point
cast within typeof(), or the `const` declaration of the member 'member', this
warning does not go away. But if I remove both `const` declarations, this goes
away.
It seems like a bug in clang to me; we're trying to get the typeof the member,
so whatever we cast 0 to should not matter if it's const or not.
Changing the const-ness of the cast does not change the warning (expected), but
neither does changing the const-ness of member on its own (unexpected). It's
only when making both changes does this change (unexpected).
The warning also goes away when I don't use the `-std=gnu89` flag, so maybe
there's a difference in gnu89 interpretation between gcc7.1 and clang4.0?
This is making it difficult to compile the linux kernel with Clang 4.0, since
the container_of() macro used in A LOT of places uses this kind of code. My
test case was the furthest I could pair down for an example.
godbolt.org is useful in testing gcc7.1.</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>