================
@@ -18521,6 +18521,27 @@ Sema::ActOnTag(Scope *S, unsigned TagSpec, TagUseKind
TUK, SourceLocation KWLoc,
Diag(PrevTagDecl->getLocation(), diag::note_previous_declaration);
}
+ // C++ [class.local]p3:
+ // A class nested within a local class is a local class. A member of
+ // a local class X shall be declared only in the definition of X or,
+ // if the member is a nested class, in the nearest enclosing block
+ // scope of X.
+ if (TUK == TagUseKind::Definition && SS.isValid()) {
+ if (const auto *OutermostClass = dyn_cast<CXXRecordDecl>(PrevDecl)) {
+ while (const auto *ParentClass =
+ dyn_cast<CXXRecordDecl>(OutermostClass->getParent()))
+ OutermostClass = ParentClass;
+
+ if (OutermostClass->isLocalClass() &&
+ !S->isDeclScope(OutermostClass)) {
+ Diag(NameLoc, diag::err_local_nested_class_invalid_scope)
+ << Name << OutermostClass;
+ Diag(OutermostClass->getLocation(), diag::note_previous_decl)
----------------
cor3ntin wrote:
```suggestion
Diag(OutermostClass->getLocation(), diag::note_defined_here)
```
https://github.com/llvm/llvm-project/pull/197863
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits