This revision was automatically updated to reflect the committed changes. Closed by commit rL316166: Fix nodiscard for volatile references (authored by erichkeane).
Changed prior to commit: https://reviews.llvm.org/D39075?vs=119535&id=119588#toc Repository: rL LLVM https://reviews.llvm.org/D39075 Files: cfe/trunk/lib/AST/Expr.cpp cfe/trunk/test/CXX/dcl.dcl/dcl.attr/dcl.attr.nodiscard/p2.cpp Index: cfe/trunk/test/CXX/dcl.dcl/dcl.attr/dcl.attr.nodiscard/p2.cpp =================================================================== --- cfe/trunk/test/CXX/dcl.dcl/dcl.attr/dcl.attr.nodiscard/p2.cpp +++ cfe/trunk/test/CXX/dcl.dcl/dcl.attr/dcl.attr.nodiscard/p2.cpp @@ -9,21 +9,33 @@ E get_e(); [[nodiscard]] int get_i(); +[[nodiscard]] volatile int &get_vi(); void f() { get_s(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} get_i(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} + get_vi(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} get_e(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} // Okay, warnings are not encouraged get_s_ref(); (void)get_s(); (void)get_i(); + (void)get_vi(); (void)get_e(); } +[[nodiscard]] volatile char &(*fp)(); +void g() { + fp(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} + + // OK, warning suppressed. + (void)fp(); +} #ifdef EXT // expected-warning@4 {{use of the 'nodiscard' attribute is a C++17 extension}} // expected-warning@8 {{use of the 'nodiscard' attribute is a C++17 extension}} // expected-warning@11 {{use of the 'nodiscard' attribute is a C++17 extension}} +// expected-warning@12 {{use of the 'nodiscard' attribute is a C++17 extension}} +// expected-warning@28 {{use of the 'nodiscard' attribute is a C++17 extension}} #endif Index: cfe/trunk/lib/AST/Expr.cpp =================================================================== --- cfe/trunk/lib/AST/Expr.cpp +++ cfe/trunk/lib/AST/Expr.cpp @@ -2298,7 +2298,8 @@ const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(CE->getSubExpr()->IgnoreParens()); if (!(DRE && isa<VarDecl>(DRE->getDecl()) && - cast<VarDecl>(DRE->getDecl())->hasLocalStorage())) { + cast<VarDecl>(DRE->getDecl())->hasLocalStorage()) && + !isa<CallExpr>(CE->getSubExpr()->IgnoreParens())) { return CE->getSubExpr()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx); }
Index: cfe/trunk/test/CXX/dcl.dcl/dcl.attr/dcl.attr.nodiscard/p2.cpp =================================================================== --- cfe/trunk/test/CXX/dcl.dcl/dcl.attr/dcl.attr.nodiscard/p2.cpp +++ cfe/trunk/test/CXX/dcl.dcl/dcl.attr/dcl.attr.nodiscard/p2.cpp @@ -9,21 +9,33 @@ E get_e(); [[nodiscard]] int get_i(); +[[nodiscard]] volatile int &get_vi(); void f() { get_s(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} get_i(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} + get_vi(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} get_e(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} // Okay, warnings are not encouraged get_s_ref(); (void)get_s(); (void)get_i(); + (void)get_vi(); (void)get_e(); } +[[nodiscard]] volatile char &(*fp)(); +void g() { + fp(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} + + // OK, warning suppressed. + (void)fp(); +} #ifdef EXT // expected-warning@4 {{use of the 'nodiscard' attribute is a C++17 extension}} // expected-warning@8 {{use of the 'nodiscard' attribute is a C++17 extension}} // expected-warning@11 {{use of the 'nodiscard' attribute is a C++17 extension}} +// expected-warning@12 {{use of the 'nodiscard' attribute is a C++17 extension}} +// expected-warning@28 {{use of the 'nodiscard' attribute is a C++17 extension}} #endif Index: cfe/trunk/lib/AST/Expr.cpp =================================================================== --- cfe/trunk/lib/AST/Expr.cpp +++ cfe/trunk/lib/AST/Expr.cpp @@ -2298,7 +2298,8 @@ const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(CE->getSubExpr()->IgnoreParens()); if (!(DRE && isa<VarDecl>(DRE->getDecl()) && - cast<VarDecl>(DRE->getDecl())->hasLocalStorage())) { + cast<VarDecl>(DRE->getDecl())->hasLocalStorage()) && + !isa<CallExpr>(CE->getSubExpr()->IgnoreParens())) { return CE->getSubExpr()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx); }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits