diff options
Diffstat (limited to 'clang/lib/Sema/SemaExpr.cpp')
-rw-r--r-- | clang/lib/Sema/SemaExpr.cpp | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 4b8817529e3..54dcced5ba9 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -76,10 +76,14 @@ bool Sema::CanUseDecl(NamedDecl *D) { static void DiagnoseUnusedOfDecl(Sema &S, NamedDecl *D, SourceLocation Loc) { // Warn if this is used but marked unused. - if (D->hasAttr<UnusedAttr>()) { - const Decl *DC = cast_or_null<Decl>(S.getCurObjCLexicalContext()); - if (DC && !DC->hasAttr<UnusedAttr>()) - S.Diag(Loc, diag::warn_used_but_marked_unused) << D->getDeclName(); + if (const auto *A = D->getAttr<UnusedAttr>()) { + // [[maybe_unused]] should not diagnose uses, but __attribute__((unused)) + // should diagnose them. + if (A->getSemanticSpelling() != UnusedAttr::CXX11_maybe_unused) { + const Decl *DC = cast_or_null<Decl>(S.getCurObjCLexicalContext()); + if (DC && !DC->hasAttr<UnusedAttr>()) + S.Diag(Loc, diag::warn_used_but_marked_unused) << D->getDeclName(); + } } } |