summaryrefslogtreecommitdiffstats
path: root/clang/test/SemaCXX/warn-unused-value-cxx11.cpp
diff options
context:
space:
mode:
authorAaron Ballman <aaron@aaronballman.com>2014-12-17 21:57:17 +0000
committerAaron Ballman <aaron@aaronballman.com>2014-12-17 21:57:17 +0000
commit6c93b3e29c56d14eab570ce62cd646a95f0c1403 (patch)
tree69fbc580587cf8545f536f5fda9b6663791920a5 /clang/test/SemaCXX/warn-unused-value-cxx11.cpp
parent4de56ef736fedb64d059fa6a922abd10b5f18690 (diff)
downloadbcm5719-llvm-6c93b3e29c56d14eab570ce62cd646a95f0c1403.tar.gz
bcm5719-llvm-6c93b3e29c56d14eab570ce62cd646a95f0c1403.zip
Adding a -Wunused-value warning for expressions with side effects used in an unevaluated expression context, such as sizeof(), or decltype(). Also adds a similar warning when the expression passed to typeid() *is* evaluated, since it is equally likely that the user would expect the expression operand to be unevaluated in that case.
llvm-svn: 224465
Diffstat (limited to 'clang/test/SemaCXX/warn-unused-value-cxx11.cpp')
-rw-r--r--clang/test/SemaCXX/warn-unused-value-cxx11.cpp30
1 files changed, 29 insertions, 1 deletions
diff --git a/clang/test/SemaCXX/warn-unused-value-cxx11.cpp b/clang/test/SemaCXX/warn-unused-value-cxx11.cpp
index 115ddf3e02d..d929b4fd12f 100644
--- a/clang/test/SemaCXX/warn-unused-value-cxx11.cpp
+++ b/clang/test/SemaCXX/warn-unused-value-cxx11.cpp
@@ -1,5 +1,4 @@
// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify -Wunused-value %s
-// expected-no-diagnostics
void f() __attribute__((const));
@@ -13,4 +12,33 @@ auto foo(T) -> decltype(f(), bool()) { // Should not warn.
void g() {
foo(1);
}
+
+void h() {
+ int i = 0;
+ (void)noexcept(++i); // expected-warning {{expression with side effects has no effect in an unevaluated context}}
+ decltype(i++) j = 0; // expected-warning {{expression with side effects has no effect in an unevaluated context}}
}
+
+struct S {
+ S operator++(int);
+ S(int i);
+ S();
+
+ int& f();
+ S g();
+};
+
+void j() {
+ S s;
+ int i = 0;
+ (void)noexcept(s++); // Ok
+ (void)noexcept(i++); // expected-warning {{expression with side effects has no effect in an unevaluated context}}
+ (void)noexcept(i = 5); // expected-warning {{expression with side effects has no effect in an unevaluated context}}
+ (void)noexcept(s = 5); // Ok
+
+ (void)sizeof(s.f()); // Ok
+ (void)sizeof(s.f() = 5); // expected-warning {{expression with side effects has no effect in an unevaluated context}}
+ (void)noexcept(s.g() = 5); // Ok
+}
+
+} \ No newline at end of file
OpenPOWER on IntegriCloud