xref: /minix3/external/bsd/llvm/dist/clang/test/SemaCXX/warn-unused-value-cxx11.cpp (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc // RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify -Wunused-value %s
2*0a6a1f1dSLionel Sambuc 
3*0a6a1f1dSLionel Sambuc void f() __attribute__((const));
4*0a6a1f1dSLionel Sambuc 
5*0a6a1f1dSLionel Sambuc namespace PR18571 {
6*0a6a1f1dSLionel Sambuc // Unevaluated contexts should not trigger unused result warnings.
7*0a6a1f1dSLionel Sambuc template <typename T>
foo(T)8*0a6a1f1dSLionel Sambuc auto foo(T) -> decltype(f(), bool()) { // Should not warn.
9*0a6a1f1dSLionel Sambuc   return true;
10*0a6a1f1dSLionel Sambuc }
11*0a6a1f1dSLionel Sambuc 
g()12*0a6a1f1dSLionel Sambuc void g() {
13*0a6a1f1dSLionel Sambuc   foo(1);
14*0a6a1f1dSLionel Sambuc }
15*0a6a1f1dSLionel Sambuc 
h()16*0a6a1f1dSLionel Sambuc void h() {
17*0a6a1f1dSLionel Sambuc   int i = 0;
18*0a6a1f1dSLionel Sambuc   (void)noexcept(++i); // expected-warning {{expression with side effects has no effect in an unevaluated context}}
19*0a6a1f1dSLionel Sambuc   decltype(i++) j = 0; // expected-warning {{expression with side effects has no effect in an unevaluated context}}
20*0a6a1f1dSLionel Sambuc }
21*0a6a1f1dSLionel Sambuc 
22*0a6a1f1dSLionel Sambuc struct S {
23*0a6a1f1dSLionel Sambuc   S operator++(int);
24*0a6a1f1dSLionel Sambuc   S(int i);
25*0a6a1f1dSLionel Sambuc   S();
26*0a6a1f1dSLionel Sambuc 
27*0a6a1f1dSLionel Sambuc   int& f();
28*0a6a1f1dSLionel Sambuc   S g();
29*0a6a1f1dSLionel Sambuc };
30*0a6a1f1dSLionel Sambuc 
j()31*0a6a1f1dSLionel Sambuc void j() {
32*0a6a1f1dSLionel Sambuc   S s;
33*0a6a1f1dSLionel Sambuc   int i = 0;
34*0a6a1f1dSLionel Sambuc   (void)noexcept(s++); // Ok
35*0a6a1f1dSLionel Sambuc   (void)noexcept(i++); // expected-warning {{expression with side effects has no effect in an unevaluated context}}
36*0a6a1f1dSLionel Sambuc   (void)noexcept(i = 5); // expected-warning {{expression with side effects has no effect in an unevaluated context}}
37*0a6a1f1dSLionel Sambuc   (void)noexcept(s = 5); // Ok
38*0a6a1f1dSLionel Sambuc 
39*0a6a1f1dSLionel Sambuc   (void)sizeof(s.f()); // Ok
40*0a6a1f1dSLionel Sambuc   (void)sizeof(s.f() = 5); // expected-warning {{expression with side effects has no effect in an unevaluated context}}
41*0a6a1f1dSLionel Sambuc   (void)noexcept(s.g() = 5); // Ok
42*0a6a1f1dSLionel Sambuc }
43*0a6a1f1dSLionel Sambuc 
44*0a6a1f1dSLionel Sambuc }