summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaStmt.cpp
diff options
context:
space:
mode:
authorAaron Ballman <aaron@aaronballman.com>2019-07-20 07:56:34 +0000
committerAaron Ballman <aaron@aaronballman.com>2019-07-20 07:56:34 +0000
commit3bef014e7d79b7aa58d968fd24e20669ac63d956 (patch)
tree8a9371f455736af9da9f1132ff98ac92de7a6a3f /clang/lib/Sema/SemaStmt.cpp
parent41affad967d48b8223dd8cfee254ee787b87a7e6 (diff)
downloadbcm5719-llvm-3bef014e7d79b7aa58d968fd24e20669ac63d956.tar.gz
bcm5719-llvm-3bef014e7d79b7aa58d968fd24e20669ac63d956.zip
Implement P1301R4, which allows specifying an optional message on the [[nodiscard]] attribute.
This also bumps the attribute feature test value and introduces the notion of a C++2a extension warning. llvm-svn: 366626
Diffstat (limited to 'clang/lib/Sema/SemaStmt.cpp')
-rw-r--r--clang/lib/Sema/SemaStmt.cpp15
1 files changed, 12 insertions, 3 deletions
diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp
index 480155df899..3400f7d3fea 100644
--- a/clang/lib/Sema/SemaStmt.cpp
+++ b/clang/lib/Sema/SemaStmt.cpp
@@ -258,8 +258,13 @@ void Sema::DiagnoseUnusedExprResult(const Stmt *S) {
if (E->getType()->isVoidType())
return;
- if (const Attr *A = CE->getUnusedResultAttr(Context)) {
- Diag(Loc, diag::warn_unused_result) << A << R1 << R2;
+ if (const auto *A = cast_or_null<WarnUnusedResultAttr>(
+ CE->getUnusedResultAttr(Context))) {
+ StringRef Msg = A->getMessage();
+ if (!Msg.empty())
+ Diag(Loc, diag::warn_unused_result_msg) << A << Msg << R1 << R2;
+ else
+ Diag(Loc, diag::warn_unused_result) << A << R1 << R2;
return;
}
@@ -290,7 +295,11 @@ void Sema::DiagnoseUnusedExprResult(const Stmt *S) {
const ObjCMethodDecl *MD = ME->getMethodDecl();
if (MD) {
if (const auto *A = MD->getAttr<WarnUnusedResultAttr>()) {
- Diag(Loc, diag::warn_unused_result) << A << R1 << R2;
+ StringRef Msg = A->getMessage();
+ if (!Msg.empty())
+ Diag(Loc, diag::warn_unused_result_msg) << A << Msg << R1 << R2;
+ else
+ Diag(Loc, diag::warn_unused_result) << A << R1 << R2;
return;
}
}
OpenPOWER on IntegriCloud