Skip to content

Commit 31db0f0

Browse files
authored
[Clang] Suppress deprecated field warnings in implicit functions definitions (llvm#147400)
Do not warn on deprecated member used in an implicit definition (such as a defaulted special member function). Co-authored-by: Corentin Jabot <[email protected]> Fixes llvm#147293
1 parent b4edd82 commit 31db0f0

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -988,6 +988,7 @@ Bug Fixes to C++ Support
988988
non-empty initializer list. (#GH147949)
989989
- Fixed constant evaluation of equality comparisons of constexpr-unknown references. (#GH147663)
990990
- Diagnose binding a reference to ``*nullptr`` during constant evaluation. (#GH48665)
991+
- Suppress -Wdeprecated-declarations in implicitly generated functions. (#GH147293)
991992

992993
Bug Fixes to AST Handling
993994
^^^^^^^^^^^^^^^^^^^^^^^^^

clang/lib/Sema/SemaAvailability.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,12 @@ static void DoEmitAvailabilityWarning(Sema &S, AvailabilityResult K,
547547
return;
548548
}
549549
case AR_Deprecated:
550+
// Suppress -Wdeprecated-declarations in implicit
551+
// functions.
552+
if (const auto *FD = dyn_cast_or_null<FunctionDecl>(S.getCurFunctionDecl());
553+
FD && FD->isImplicit())
554+
return;
555+
550556
if (ObjCPropertyAccess)
551557
diag = diag::warn_property_method_deprecated;
552558
else if (S.currentEvaluationContext().IsCaseExpr)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// RUN: %clang_cc1 -std=c++20 -Wdeprecated-declarations -verify %s
2+
3+
struct A {
4+
[[deprecated("use something else")]] int x = 42; // expected-note {{marked deprecated here}}
5+
};
6+
7+
A makeDefaultA() { return {}; } // ctor is implicit → no warn
8+
A copyA(const A &a) { return a; } // copy-ctor implicit → no warn
9+
10+
void assignA() {
11+
A a, b;
12+
a = b; // copy-assign implicit → no warn
13+
}
14+
15+
void useA() {
16+
A a;
17+
(void)a.x; // expected-warning {{is deprecated}}
18+
}
19+
20+
// Explicitly-defaulted ctor – now silent
21+
struct B {
22+
[[deprecated]] int y;
23+
B() = default; // no warning under new policy
24+
};

0 commit comments

Comments
 (0)