Skip to content

Commit b89f09f

Browse files
authored
[Clang] Enhance handling of [[deprecated]] attribute diagnostics for local variables (#113575)
Fixes #90073
1 parent 18f4b7e commit b89f09f

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,8 @@ Improvements to Clang's diagnostics
424424
name was a reserved name, which we improperly allowed to suppress the
425425
diagnostic.
426426

427+
- Clang now diagnoses ``[[deprecated]]`` attribute usage on local variables (#GH90073).
428+
427429
Improvements to Clang's time-trace
428430
----------------------------------
429431

clang/lib/Sema/SemaAvailability.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,12 @@ static bool ShouldDiagnoseAvailabilityInContext(
182182
return false;
183183
}
184184

185+
if (K == AR_Deprecated) {
186+
if (const auto *VD = dyn_cast<VarDecl>(OffendingDecl))
187+
if (VD->isLocalVarDeclOrParm() && VD->isDeprecated())
188+
return true;
189+
}
190+
185191
// Checks if we should emit the availability diagnostic in the context of C.
186192
auto CheckContext = [&](const Decl *C) {
187193
if (K == AR_NotYetIntroduced) {

clang/test/SemaCXX/deprecated.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,5 +260,25 @@ namespace ArrayComp {
260260
bool b7 = arr1 == +f();
261261
}
262262

263+
namespace GH90073 {
264+
[[deprecated]] int f1() { // expected-note {{'f1' has been explicitly marked deprecated here}}
265+
[[deprecated]] int a; // expected-note {{'a' has been explicitly marked deprecated here}} \
266+
// expected-note {{'a' has been explicitly marked deprecated here}}
267+
a = 0; // expected-warning {{'a' is deprecated}}
268+
return a; // expected-warning {{'a' is deprecated}}
269+
}
270+
271+
[[deprecated]] void f2([[deprecated]] int x) { // expected-note {{'f2' has been explicitly marked deprecated here}} \
272+
// expected-note {{'x' has been explicitly marked deprecated here}}
273+
x = 4; // expected-warning {{'x' is deprecated}}
274+
}
275+
276+
int main() {
277+
f1(); // expected-warning {{'f1' is deprecated}}
278+
f2(1); // expected-warning {{'f2' is deprecated}}
279+
return 0;
280+
}
281+
}
282+
263283
# 1 "/usr/include/system-header.h" 1 3
264284
void system_header_function(void) throw();

0 commit comments

Comments
 (0)