[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
Fri Oct 18 05:12:12 PDT 2024


================
@@ -39,7 +39,8 @@ bool Sema::SetMemberAccessSpecifier(NamedDecl *MemberDecl,
                                     AccessSpecifier LexicalAS) {
   if (!PrevMemberDecl) {
     // Use the lexical access specifier.
-    MemberDecl->setAccess(LexicalAS);
----------------
a-tarasyuk wrote:

> The current diagnostic does not fit this case though and maybe it has to be tweaked some more.

@shafik Thanks for the feedback! I initially considered marking the new declaration invalid based on `TUK_Declaration`, but I wasn’t entirely sure because of its relation to the new declaration

https://github.com/llvm/llvm-project/blob/7be1dc0f32f43331c049725e0e2b902e74115779/clang/lib/Sema/SemaDecl.cpp#L17953-L17954

I’ve made changes to handle this case based on TUK_Declaration. If we need to add a diagnostic message (_something like a general message saying `"enum" cannot appear here`_), just let me know and I’ll add it...



https://github.com/llvm/llvm-project/pull/112424


More information about the cfe-commits mailing list