[Clang] Do not emit nodiscard warnings for the base expr of static me… · llvm/llvm-project@e3f0ce3 (original) (raw)
File tree
5 files changed
lines changed
- CXX/dcl.dcl/dcl.attr/dcl.attr.nodiscard
5 files changed
lines changed
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -10671,11 +10671,6 @@ class Sema final : public SemaBase { | ||
10671 | 10671 | SourceLocation EndLoc); |
10672 | 10672 | void ActOnForEachDeclStmt(DeclGroupPtrTy Decl); |
10673 | 10673 | |
10674 | - /// DiagnoseDiscardedExprMarkedNodiscard - Given an expression that is | |
10675 | - /// semantically a discarded-value expression, diagnose if any [[nodiscard]] | |
10676 | - /// value has been discarded. | |
10677 | - void DiagnoseDiscardedExprMarkedNodiscard(const Expr *E); | |
10678 | - | |
10679 | 10674 | /// DiagnoseUnusedExprResult - If the statement passed in is an expression |
10680 | 10675 | /// whose result is unused, warn. |
10681 | 10676 | void DiagnoseUnusedExprResult(const Stmt *S, unsigned DiagID); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1136,7 +1136,6 @@ Sema::BuildMemberReferenceExpr(Expr *BaseExpr, QualType BaseExprType, | ||
1136 | 1136 | if (Converted.isInvalid()) |
1137 | 1137 | return true; |
1138 | 1138 | BaseExpr = Converted.get(); |
1139 | -DiagnoseDiscardedExprMarkedNodiscard(BaseExpr); | |
1140 | 1139 | return false; |
1141 | 1140 | }; |
1142 | 1141 | auto ConvertBaseExprToGLValue = [&] { |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -413,10 +413,6 @@ void DiagnoseUnused(Sema &S, const Expr *E, std::optional DiagID) { | ||
413 | 413 | } |
414 | 414 | } // namespace |
415 | 415 | |
416 | -void Sema::DiagnoseDiscardedExprMarkedNodiscard(const Expr *E) { | |
417 | -DiagnoseUnused(*this, E, std::nullopt); | |
418 | -} | |
419 | - | |
420 | 416 | void Sema::DiagnoseUnusedExprResult(const Stmt *S, unsigned DiagID) { |
421 | 417 | if (const LabelStmt *Label = dyn_cast_if_present(S)) |
422 | 418 | S = Label->getSubStmt(); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -164,19 +164,21 @@ struct X { | ||
164 | 164 | |
165 | 165 | [[nodiscard]] X get_X(); |
166 | 166 | // cxx11-warning@-1 {{use of the 'nodiscard' attribute is a C++17 extension}} |
167 | +[[nodiscard]] X* get_Ptr(); | |
168 | +// cxx11-warning@-1 {{use of the 'nodiscard' attribute is a C++17 extension}} | |
167 | 169 | void f() { |
170 | +get_X(); // expected-warning{{ignoring return value of function declared with 'nodiscard' attribute}} | |
171 | + (void) get_X(); | |
168 | 172 | (void) get_X().variant_member; |
169 | 173 | (void) get_X().anonymous_struct_member; |
170 | 174 | (void) get_X().data_member; |
171 | 175 | (void) get_X().static_data_member; |
172 | -// expected-warning@-1 {{ignoring return value of function declared with 'nodiscard' attribute}} | |
173 | 176 | (void) get_X().unscoped_enum; |
174 | -// expected-warning@-1 {{ignoring return value of function declared with 'nodiscard' attribute}} | |
175 | 177 | (void) get_X().scoped_enum; |
176 | -// expected-warning@-1 {{ignoring return value of function declared with 'nodiscard' attribute}} | |
177 | 178 | (void) get_X().implicit_object_member_function(); |
178 | 179 | (void) get_X().static_member_function(); |
179 | -// expected-warning@-1 {{ignoring return value of function declared with 'nodiscard' attribute}} | |
180 | + (void) get_Ptr()->implicit_object_member_function(); | |
181 | + (void) get_Ptr()->static_member_function(); | |
180 | 182 | #if __cplusplus >= 202302L |
181 | 183 | (void) get_X().explicit_object_member_function(); |
182 | 184 | #endif |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -2,6 +2,7 @@ | ||
2 | 2 | // RUN: %clang_cc1 -triple=x86_64-pc-win32 -fms-compatibility -emit-pch -o %t -verify %s |
3 | 3 | // RUN: %clang_cc1 -triple=x86_64-pc-win32 -fms-compatibility -include-pch %t %s -ast-print -o - | FileCheck %s |
4 | 4 | // RUN: %clang_cc1 -fdeclspec -fsyntax-only -verify %s -std=c++23 |
5 | +// expected-no-diagnostics | |
5 | 6 | |
6 | 7 | #ifndef HEADER |
7 | 8 | #define HEADER |
@@ -103,7 +104,6 @@ struct X { | ||
103 | 104 | void f() { |
104 | 105 | (void) get_x().imp; |
105 | 106 | (void) get_x().st; |
106 | -// expected-warning@-1 {{ignoring return value of function declared with 'nodiscard' attribute}} | |
107 | 107 | #if __cplusplus >= 202302L |
108 | 108 | (void) get_x().exp; |
109 | 109 | #endif |