<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 - Missing error message of "functions cannot be declared in an anonymous union""
href="https://bugs.llvm.org/show_bug.cgi?id=46365">46365</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Missing error message of "functions cannot be declared in an anonymous union"
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</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>Frontend
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>haoxintu@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org, neeilans@live.com, richard-llvm@metafoo.co.uk
</td>
</tr></table>
<p>
<div>
<pre>This code test.cc, clang-trunk can not emit the error message about a function
used in an anonymous union, while in clang-10 or lower versions do.
$cat test.cc
int main(){
static union { foo(int,int);};
return 0;
}
$clang++-trunk -w test.cc
test.cc:2:20: error: C++ requires a type specifier for all declarations
static union { foo(int,int);};
^
1 error generated.
$clang++-10 -w test.cc
test.cc:2:20: error: C++ requires a type specifier for all declarations
static union { foo(int,int);};
^
test.cc:2:20: error: functions cannot be declared in an anonymous union
2 errors generated.
Also in GCC, it can detect the anonymous union error.
$g++ -w test.cc
est.cc: In function ‘int main()’:
test.cc:2:20: error: ISO C++ forbids declaration of ‘foo’ with no type
[-fpermissive]
2 | static union { foo(int,int);};
| ^~~
test.cc:2:20: error: ‘int main()::<unnamed union>::foo(int, int)’ invalid; an
anonymous union can only have non-static data members [-fpermissive]
When I change line 2 into "static union {int foo(int,int);};", clang can emit
the "functions cannot be declared in an anonymous union" error, same as the
clang-10 do.
Should clang-trunk give two error messages in the test.cc like clang-10 or it's
the enhancement behavior of clang-trunk? I guess clang-trunk might stop
emitting errors after the first error or can not detect functions used in an
anonymous union correctly.</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>