[lld][WebAssembly] Reinstate mistakenly disabled test. NFC
[llvm-project.git] / clang / test / SemaCXX / warn-self-assign-builtin.cpp
blob212fc241e3e7e84cc9d404a1007f3444c8fcdb64
1 // RUN: %clang_cc1 -fsyntax-only -Wself-assign -verify %s
3 void f() {
4 int a = 42, b = 42;
5 a = a; // expected-warning{{explicitly assigning}}
6 b = b; // expected-warning{{explicitly assigning}}
7 a = b;
8 b = a = b;
9 a = a = a; // expected-warning{{explicitly assigning}}
10 a = b = b = a;
12 a *= a;
13 a /= a;
14 a %= a;
15 a += a;
16 a -= a;
17 a <<= a;
18 a >>= a;
19 a &= a; // expected-warning {{explicitly assigning}}
20 a |= a; // expected-warning {{explicitly assigning}}
21 a ^= a;
24 // Dummy type.
25 struct S {};
27 void false_positives() {
28 #define OP =
29 #define LHS a
30 #define RHS a
31 int a = 42;
32 // These shouldn't warn due to the use of the preprocessor.
33 a OP a;
34 LHS = a;
35 a = RHS;
36 LHS OP RHS;
37 #undef OP
38 #undef LHS
39 #undef RHS
41 // A way to silence the warning.
42 a = (int &)a;
44 // Volatile stores aren't side-effect free.
45 volatile int vol_a;
46 vol_a = vol_a;
47 volatile int &vol_a_ref = vol_a;
48 vol_a_ref = vol_a_ref;
51 // Do not diagnose self-assigment in an unevaluated context
52 void false_positives_unevaluated_ctx(int a) noexcept(noexcept(a = a)) // expected-warning {{expression with side effects has no effect in an unevaluated context}}
54 decltype(a = a) b = a; // expected-warning {{expression with side effects has no effect in an unevaluated context}}
55 static_assert(noexcept(a = a), ""); // expected-warning {{expression with side effects has no effect in an unevaluated context}}
56 static_assert(sizeof(a = a), ""); // expected-warning {{expression with side effects has no effect in an unevaluated context}}
59 template <typename T>
60 void g() {
61 T a;
62 a = a; // expected-warning{{explicitly assigning}}
64 void instantiate() {
65 g<int>();
66 g<S>();