[clang] df9769e - [Clang] prevent setting default lexical access specifier for missing primary declarations (#112424)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Oct 31 22:13:37 PDT 2024
Author: Oleksandr T.
Date: 2024-11-01T13:13:33+08:00
New Revision: df9769e14b79048331c33deeda1a93acc9a4a73e
URL: https://github.com/llvm/llvm-project/commit/df9769e14b79048331c33deeda1a93acc9a4a73e
DIFF: https://github.com/llvm/llvm-project/commit/df9769e14b79048331c33deeda1a93acc9a4a73e.diff
LOG: [Clang] prevent setting default lexical access specifier for missing primary declarations (#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 #112208
Added:
Modified:
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaDecl.cpp
clang/test/SemaCXX/enum.cpp
Removed:
################################################################################
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 4e542ee91a8b36..b99dd441db255c 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -589,6 +589,7 @@ Bug Fixes to C++ Support
- Fixed an assertion failure in range calculations for conditional throw expressions. (#GH111854)
- Clang now correctly ignores previous partial specializations of member templates explicitly specialized for
an implicitly instantiated class template specialization. (#GH51051)
+- Fixed an assertion failure caused by invalid enum forward declarations. (#GH112208)
Bug Fixes to AST Handling
^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index c56883a80c1c55..0cdace25aa792b 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -17955,6 +17955,8 @@ Sema::ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK, SourceLocation KWLoc,
<< Name;
Invalid = true;
}
+ if (TUK == TagUseKind::Declaration)
+ Invalid = true;
} else if (!PrevDecl) {
Diag(Loc, diag::warn_decl_in_param_list) << Context.getTagDeclType(New);
}
diff --git a/clang/test/SemaCXX/enum.cpp b/clang/test/SemaCXX/enum.cpp
index 9c398cc8da886c..44042d8bf5cfc8 100644
--- a/clang/test/SemaCXX/enum.cpp
+++ b/clang/test/SemaCXX/enum.cpp
@@ -143,3 +143,11 @@ struct PR28903 {
})
};
};
+
+namespace GH112208 {
+class C {
+ enum E { e = 0 };
+ void f(int, enum E;); // expected-error {{ISO C++ forbids forward references to 'enum' types}} \
+ // expected-error {{unexpected ';' before ')'}}
+};
+}
More information about the cfe-commits
mailing list