aboutsummaryrefslogtreecommitdiff
path: root/test/SemaCXX/warn-unused-value.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'test/SemaCXX/warn-unused-value.cpp')
-rw-r--r--test/SemaCXX/warn-unused-value.cpp34
1 files changed, 31 insertions, 3 deletions
diff --git a/test/SemaCXX/warn-unused-value.cpp b/test/SemaCXX/warn-unused-value.cpp
index 4e1347cc307a..efabd5063068 100644
--- a/test/SemaCXX/warn-unused-value.cpp
+++ b/test/SemaCXX/warn-unused-value.cpp
@@ -39,13 +39,13 @@ namespace test2 {
void method() const {
X* x;
&x[0]; // expected-warning {{expression result unused}}
- }
+ }
};
typedef basic_string<char> string;
- void func(const std::string& str) {
+ void func(const std::string& str) {
str.method(); // expected-note {{in instantiation of member function}}
}
- }
+ }
}
}
@@ -69,3 +69,31 @@ void f() {
Unused(1, 1); // expected-warning {{expression result unused}}
}
}
+
+namespace std {
+ struct type_info {};
+}
+
+namespace test4 {
+struct Good { Good &f(); };
+struct Bad { virtual Bad& f(); };
+
+void f() {
+ int i = 0;
+ (void)typeid(++i); // expected-warning {{expression with side effects has no effect in an unevaluated context}}
+
+ Good g;
+ (void)typeid(g.f()); // Ok; not a polymorphic use of a glvalue.
+
+ // This is a polymorphic use of a glvalue, which results in the typeid being
+ // evaluated instead of unevaluated.
+ Bad b;
+ (void)typeid(b.f()); // expected-warning {{expression with side effects will be evaluated despite being used as an operand to 'typeid'}}
+
+ // A dereference of a volatile pointer is a side effecting operation, however
+ // since it is idiomatic code, and the alternatives induce higher maintenance
+ // costs, it is allowed.
+ int * volatile x;
+ (void)sizeof(*x); // Ok
+}
+}