diff options
author | Aaron Ballman <aaron@aaronballman.com> | 2019-01-03 14:24:31 +0000 |
---|---|---|
committer | Aaron Ballman <aaron@aaronballman.com> | 2019-01-03 14:24:31 +0000 |
commit | ec8c48fb7d4ee1ee940ab3255f3e25b3e289ab8d (patch) | |
tree | 35b99c6fbdf0bf67e4dc4836a14a08cc28254026 /test/CXX | |
parent | 0e55e1c2d00e984de5fc3830649c5d2f8698e516 (diff) |
Diagnose an unused result from a call through a function pointer whose return type is marked [[nodiscard]].
When a function returns a type and that type was declared [[nodiscard]], we diagnose any unused results from that call as though the function were marked nodiscard. The same behavior should apply to calls through a function pointer.
This addresses PR31526.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@350317 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/CXX')
-rw-r--r-- | test/CXX/dcl.dcl/dcl.attr/dcl.attr.nodiscard/p2.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/test/CXX/dcl.dcl/dcl.attr/dcl.attr.nodiscard/p2.cpp b/test/CXX/dcl.dcl/dcl.attr/dcl.attr.nodiscard/p2.cpp index 49c418a687..43de9343bd 100644 --- a/test/CXX/dcl.dcl/dcl.attr/dcl.attr.nodiscard/p2.cpp +++ b/test/CXX/dcl.dcl/dcl.attr/dcl.attr.nodiscard/p2.cpp @@ -32,6 +32,35 @@ void g() { // OK, warning suppressed. (void)fp(); } + +namespace PR31526 { +typedef E (*fp1)(); +typedef S (*fp2)(); + +typedef S S_alias; +typedef S_alias (*fp3)(); + +typedef fp2 fp2_alias; + +void f() { + fp1 one; + fp2 two; + fp3 three; + fp2_alias four; + + one(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} + two(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} + three(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} + four(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} + + // These are all okay because of the explicit cast to void. + (void)one(); + (void)two(); + (void)three(); + (void)four(); +} +} // namespace PR31526 + #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}} |