[clang] [Clang] suppress deprecated field warnings in implicit special-member functions (PR #147400)
Shashi Shankar via cfe-commits
cfe-commits at lists.llvm.org
Tue Jul 8 06:55:51 PDT 2025
================
@@ -547,6 +547,15 @@ static void DoEmitAvailabilityWarning(Sema &S, AvailabilityResult K,
return;
}
case AR_Deprecated:
+ // Suppress -Wdeprecated-declarations in purely implicit special-member functions.
+ if (auto *MD = dyn_cast_if_present<CXXMethodDecl>(S.getCurFunctionDecl());
+ MD && MD->isImplicit() && MD->isDefaulted() &&
+ (isa<CXXConstructorDecl, CXXDestructorDecl>(MD) ||
+ MD->isCopyAssignmentOperator() ||
+ MD->isMoveAssignmentOperator())) {
+ return;
+ }
+
----------------
shashi1687 wrote:
**“dyn_cast_if_present<FunctionDeck>” causes compile errors**
There is no FunctionDeck class in Clang’s AST, so that cast will never compile. The correct cast here is to CXXMethodDecl (or at most to FunctionDecl). We’ve updated the code to use:
```
if (auto *MD = dyn_cast_if_present<CXXMethodDecl>(…);
MD && MD->isImplicit() /*…etc…*/ )
return;
```
This change compiles cleanly and continues to limit suppression to only the implicitly-generated special-member methods.
https://github.com/llvm/llvm-project/pull/147400
More information about the cfe-commits
mailing list