aboutsummaryrefslogtreecommitdiff
path: root/clang/test/SemaCXX/warn-unused-result.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'clang/test/SemaCXX/warn-unused-result.cpp')
-rw-r--r--clang/test/SemaCXX/warn-unused-result.cpp27
1 files changed, 26 insertions, 1 deletions
diff --git a/clang/test/SemaCXX/warn-unused-result.cpp b/clang/test/SemaCXX/warn-unused-result.cpp
index fe7d5ea..447654e 100644
--- a/clang/test/SemaCXX/warn-unused-result.cpp
+++ b/clang/test/SemaCXX/warn-unused-result.cpp
@@ -365,6 +365,31 @@ void id_print_name() {
}
} // namespace GH117975
+namespace inheritance {
+// Test that [[nodiscard]] is not inherited by derived class types,
+// but is inherited by member functions
+struct [[nodiscard]] E {
+ [[nodiscard]] explicit E(int);
+ explicit E(const char*);
+ [[nodiscard]] int f();
+};
+struct F : E {
+ using E::E;
+};
+E e();
+F f();
+void test() {
+ e(); // expected-warning {{ignoring return value of type 'E' declared with 'nodiscard' attribute}}
+ f(); // no warning: derived class type does not inherit the attribute
+ E(1); // expected-warning {{ignoring temporary created by a constructor declared with 'nodiscard' attribute}}
+ E("x"); // expected-warning {{ignoring temporary of type 'E' declared with 'nodiscard' attribute}}
+ F(1); // no warning: inherited constructor does not inherit the attribute either
+ F("x"); // no warning
+ e().f(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
+ f().f(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
+}
+} // namespace inheritance
+
namespace BuildStringOnClangScope {
[[clang::warn_unused_result("Discarded result")]]
@@ -381,4 +406,4 @@ void doGccThings() {
makeGccTrue(); // expected-warning {{ignoring return value of function declared with 'gnu::warn_unused_result' attribute}}
}
-}
+} // namespace BuildStringOnClangScope