1 // RUN: %clang_cc1 -fsyntax-only -Wself-assign -verify %s
5 a
= a
; // expected-warning{{explicitly assigning}}
6 b
= b
; // expected-warning{{explicitly assigning}}
9 a
= a
= a
; // expected-warning{{explicitly assigning}}
19 a
&= a
; // expected-warning {{explicitly assigning}}
20 a
|= a
; // expected-warning {{explicitly assigning}}
27 void false_positives() {
32 // These shouldn't warn due to the use of the preprocessor.
41 // A way to silence the warning.
44 // Volatile stores aren't side-effect free.
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}}
62 a
= a
; // expected-warning{{explicitly assigning}}
75 A
= A
; // expected-warning{{explicitly assigning value of variable of type 'int' to itself; did you mean to assign to member 'A'?}}
78 void setThroughLambda() {
80 // To fix here we would need to insert an explicit capture 'this'
81 A
= A
; // expected-warning{{explicitly assigning}}
86 // This fix would be possible by just adding this-> as above, but currently unsupported.
87 A
= A
; // expected-warning{{explicitly assigning}}