diff options
author | Aaron Ballman <aaron@aaronballman.com> | 2025-04-29 07:58:00 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-04-29 07:58:00 -0400 |
commit | 2f976956e5ccef566418853015fb6b31257aa69f (patch) | |
tree | c5ff6c928bb4d1296c20a4f58c33fdbadce2234e /clang/lib/AST/DeclBase.cpp | |
parent | 5e4ec04063e0f04311b6e717c68cd968a0bb6d36 (diff) | |
download | llvm-2f976956e5ccef566418853015fb6b31257aa69f.zip llvm-2f976956e5ccef566418853015fb6b31257aa69f.tar.gz llvm-2f976956e5ccef566418853015fb6b31257aa69f.tar.bz2 |
[C] Diagnose declarations hidden in C++ (#137368)
This introduces a new diagnostic, -Wc++-hidden-decl, which is grouped
under -Wc++-compat, that diagnoses declarations which are valid in C but
invalid in C++ due to the type being at the wrong scope. e.g.,
```
struct S {
struct T {
int x;
} t;
};
struct T t; // Valid C, invalid C++
```
This is implementing the other half of #21898
Diffstat (limited to 'clang/lib/AST/DeclBase.cpp')
-rw-r--r-- | clang/lib/AST/DeclBase.cpp | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/clang/lib/AST/DeclBase.cpp b/clang/lib/AST/DeclBase.cpp index 1afda9a..fead99c 100644 --- a/clang/lib/AST/DeclBase.cpp +++ b/clang/lib/AST/DeclBase.cpp @@ -1422,7 +1422,18 @@ bool DeclContext::Encloses(const DeclContext *DC) const { return getPrimaryContext()->Encloses(DC); for (; DC; DC = DC->getParent()) - if (!isa<LinkageSpecDecl>(DC) && !isa<ExportDecl>(DC) && + if (!isa<LinkageSpecDecl, ExportDecl>(DC) && + DC->getPrimaryContext() == this) + return true; + return false; +} + +bool DeclContext::LexicallyEncloses(const DeclContext *DC) const { + if (getPrimaryContext() != this) + return getPrimaryContext()->LexicallyEncloses(DC); + + for (; DC; DC = DC->getLexicalParent()) + if (!isa<LinkageSpecDecl, ExportDecl>(DC) && DC->getPrimaryContext() == this) return true; return false; |