<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 - clang-cl never diagnoses use of forward-declared enums"
href="https://bugs.llvm.org/show_bug.cgi?id=32736">32736</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>clang-cl never diagnoses use of forward-declared enums
</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>Driver
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>nicolasweber@gmx.de
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>This errors out with clang and gcc as it should:
$ cat test.cc
enum E; void f(E);
enum E {kA}; void f(E a) { if (a == kA) {}}
However, clang-cl always accepts it without a warning. This bit in SemaDecl.cpp
tries to emit ext_ms_forward_ref_enum for this:
// If this is an undefined enum, warn.
if (TUK != TUK_Definition && !Invalid) {
TagDecl *Def;
if ((getLangOpts().CPlusPlus11 || getLangOpts().ObjC2) &&
cast<EnumDecl>(New)->isFixed()) {
// C++0x: 7.2p2: opaque-enum-declaration.
// Conflicts are diagnosed above. Do nothing.
}
else if (PrevDecl && (Def = cast<EnumDecl>(PrevDecl)->getDefinition())) {
Diag(Loc, diag::ext_forward_ref_enum_def)
<< New;
Diag(Def->getLocation(), diag::note_previous_definition);
} else {
unsigned DiagID = diag::ext_forward_ref_enum;
if (getLangOpts().MSVCCompat)
DiagID = diag::ext_ms_forward_ref_enum;
else if (getLangOpts().CPlusPlus)
DiagID = diag::err_forward_ref_enum;
Diag(Loc, DiagID);
But:
1. ext_ms_forward_ref_enum is an Extension<> and clang-cl doesn't expose
-pedantic (it probably should be an ExtWarn<>)
2. Worse, isFixed() in the if above is true, so the lower else is never entered
in Microsoft mode.
That's due to this, also in SemaDecl.cpp:
if (getLangOpts().MSVCCompat || TUK == TUK_Definition) {
// Microsoft enums are always of int type.
EnumUnderlying = Context.IntTy.getTypePtr();
EnumUnderlyingIsImplicit = true;
}
This causes the EnumDecl to believe that it's IsFixed.
Last touched by majnemer in 249667, added by fpichet in 116704.
Probably need to pipe EnumUnderlyingIsImplicit to the diag block and diag if
that's set?</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>