[clang] [Clang] prevent setting default lexical access specifier for missing primary declarations (PR #112424)
Oleksandr T. via cfe-commits
cfe-commits at lists.llvm.org
Tue Oct 15 12:44:32 PDT 2024
https://github.com/a-tarasyuk created https://github.com/llvm/llvm-project/pull/112424
Fixes #112208
>From a22c6bae4f42f42e67f8e0c2b1f914e50d140099 Mon Sep 17 00:00:00 2001
From: Oleksandr T <oleksandr.tarasiuk at outlook.com>
Date: Tue, 15 Oct 2024 22:43:24 +0300
Subject: [PATCH] [Clang] prevent setting default lexical access specifier for
missing primary declarations
---
clang/docs/ReleaseNotes.rst | 2 ++
clang/lib/Sema/SemaAccess.cpp | 3 ++-
clang/test/SemaCXX/enum.cpp | 8 ++++++++
3 files changed, 12 insertions(+), 1 deletion(-)
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 817e3abef8d566..64ffdcde045a3a 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -517,6 +517,8 @@ Bug Fixes to C++ Support
certain situations. (#GH47400), (#GH90896)
- Fix erroneous templated array size calculation leading to crashes in generated code. (#GH41441)
- During the lookup for a base class name, non-type names are ignored. (#GH16855)
+- Fixed an assertion failure when the default lexical access specifier was set for missing
+ primary declarations. (#GH112208)
Bug Fixes to AST Handling
^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/clang/lib/Sema/SemaAccess.cpp b/clang/lib/Sema/SemaAccess.cpp
index df6edb21a50dee..8b4a5b70669d84 100644
--- a/clang/lib/Sema/SemaAccess.cpp
+++ b/clang/lib/Sema/SemaAccess.cpp
@@ -39,7 +39,8 @@ bool Sema::SetMemberAccessSpecifier(NamedDecl *MemberDecl,
AccessSpecifier LexicalAS) {
if (!PrevMemberDecl) {
// Use the lexical access specifier.
- MemberDecl->setAccess(LexicalAS);
+ if (LexicalAS != AS_none)
+ MemberDecl->setAccess(LexicalAS);
return false;
}
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