diff options
author | Stefan Gränitz <stefan.graenitz@gmail.com> | 2024-03-07 14:27:04 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-07 14:27:04 +0100 |
commit | 4b70d17bcffaffd75a5d8c420396f8dc755b4652 (patch) | |
tree | dc0e10a86c18a13597048ceeb51a1ba33f00dacc /clang/lib/AST/DeclBase.cpp | |
parent | 464d9d96b3565ead06396ffb8d02b4dcf9cb9556 (diff) | |
download | llvm-4b70d17bcffaffd75a5d8c420396f8dc755b4652.zip llvm-4b70d17bcffaffd75a5d8c420396f8dc755b4652.tar.gz llvm-4b70d17bcffaffd75a5d8c420396f8dc755b4652.tar.bz2 |
[clang-repl] Names declared in if conditions and for-init statements are local to the inner context (#84150)
Make TopLevelStmtDecl a DeclContext so that variables defined in statements
are attached to the TopLevelDeclContext. This fixes redefinition errors
from variables declared in if conditions and for-init statements. These
must be local to the inner context (C++ 3.3.2p4), but they had generated
definitions on global scope instead.
This PR makes the TopLevelStmtDecl looking more like a FunctionDecl and
that's fine because the FunctionDecl is very close in terms of semantics.
Additionally, ActOnForStmt() requires a CompoundScope when processing a
NullStmt body.
---------
Co-authored-by: Vassil Vassilev <v.g.vassilev@gmail.com>
Diffstat (limited to 'clang/lib/AST/DeclBase.cpp')
-rw-r--r-- | clang/lib/AST/DeclBase.cpp | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/clang/lib/AST/DeclBase.cpp b/clang/lib/AST/DeclBase.cpp index 10fe8bb..fcedb3c 100644 --- a/clang/lib/AST/DeclBase.cpp +++ b/clang/lib/AST/DeclBase.cpp @@ -1352,6 +1352,7 @@ DeclContext *DeclContext::getPrimaryContext() { case Decl::ExternCContext: case Decl::LinkageSpec: case Decl::Export: + case Decl::TopLevelStmt: case Decl::Block: case Decl::Captured: case Decl::OMPDeclareReduction: |