brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.3 KiB · 687278a Raw
54 lines · cpp
1// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify -Wunused-value %s2 3int f() __attribute__((const));4 5namespace PR18571 {6// Unevaluated contexts should not trigger unused result warnings.7template <typename T>8auto foo(T) -> decltype(f(), bool()) { // Should not warn.9  return true;10}11 12void g() {13  foo(1);14}15 16void h() {17  int i = 0;18  (void)noexcept(++i); // expected-warning {{expression with side effects has no effect in an unevaluated context}}19  decltype(i++) j = 0; // expected-warning {{expression with side effects has no effect in an unevaluated context}}20}21 22struct S {23  S operator++(int);24  S(int i);25  S();26 27  int& f();28  S g();29};30 31void j() {32  S s;33  int i = 0;34  (void)noexcept(s++); // Ok35  (void)noexcept(i++); // expected-warning {{expression with side effects has no effect in an unevaluated context}}36  (void)noexcept(i = 5); // expected-warning {{expression with side effects has no effect in an unevaluated context}}37  (void)noexcept(s = 5); // Ok38 39  (void)sizeof(s.f()); // Ok40  (void)sizeof(s.f() = 5); // expected-warning {{expression with side effects has no effect in an unevaluated context}}41  (void)noexcept(s.g() = 5); // Ok42}43 44}45 46namespace volatile_array {47void test() {48  char a[10];49  volatile char b[10];50  a; // expected-warning-re {{expression result unused{{$}}}}51  b; // expected-warning-re {{expression result unused{{$}}}}52}53}54