Skip to content

Commit df9769e

Browse files
authored
[Clang] prevent setting default lexical access specifier for missing primary declarations (llvm#112424)
This PR resolves a crash triggered by a forward reference to an enum type in a function parameter list. The fix includes setting `Invalid` when `TagUseKind` is `Declaration` to ensure correct error handling. Fixes llvm#112208
1 parent 8e37727 commit df9769e

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

clang/docs/ReleaseNotes.rst

+1
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,7 @@ Bug Fixes to C++ Support
589589
- Fixed an assertion failure in range calculations for conditional throw expressions. (#GH111854)
590590
- Clang now correctly ignores previous partial specializations of member templates explicitly specialized for
591591
an implicitly instantiated class template specialization. (#GH51051)
592+
- Fixed an assertion failure caused by invalid enum forward declarations. (#GH112208)
592593

593594
Bug Fixes to AST Handling
594595
^^^^^^^^^^^^^^^^^^^^^^^^^

clang/lib/Sema/SemaDecl.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -17955,6 +17955,8 @@ Sema::ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK, SourceLocation KWLoc,
1795517955
<< Name;
1795617956
Invalid = true;
1795717957
}
17958+
if (TUK == TagUseKind::Declaration)
17959+
Invalid = true;
1795817960
} else if (!PrevDecl) {
1795917961
Diag(Loc, diag::warn_decl_in_param_list) << Context.getTagDeclType(New);
1796017962
}

clang/test/SemaCXX/enum.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -143,3 +143,11 @@ struct PR28903 {
143143
})
144144
};
145145
};
146+
147+
namespace GH112208 {
148+
class C {
149+
enum E { e = 0 };
150+
void f(int, enum E;); // expected-error {{ISO C++ forbids forward references to 'enum' types}} \
151+
// expected-error {{unexpected ';' before ')'}}
152+
};
153+
}

0 commit comments

Comments
 (0)