1 // RUN: %clang_cc1 -fsyntax-only -Wself-assign-field -verify %s
7 C(int a
, int b
) : a(a
), b(b
) {}
10 a
= a
; // expected-warning {{assigning field to itself}}
11 b
= b
; // expected-warning {{assigning field to itself}}
14 this->a
= a
; // expected-warning {{assigning field to itself}}
15 this->b
= b
; // expected-warning {{assigning field to itself}}
16 a
= this->a
; // expected-warning {{assigning field to itself}}
17 b
= this->b
; // expected-warning {{assigning field to itself}}
18 this->a
= this->a
; // expected-warning {{assigning field to itself}}
19 this->b
= this->b
; // expected-warning {{assigning field to itself}}
38 void false_positives() {
42 // These shouldn't warn due to the use of the preprocessor.
51 // A way to silence the warning.
55 // Do not diagnose self-assigment in an unevaluated context
56 void false_positives_unevaluated_ctx() noexcept(noexcept(a
= a
)) // expected-warning {{expression with side effects has no effect in an unevaluated context}}
58 decltype(a
= a
) b
= a
; // expected-warning {{expression with side effects has no effect in an unevaluated context}}
59 static_assert(noexcept(a
= a
), ""); // expected-warning {{expression with side effects has no effect in an unevaluated context}}
60 static_assert(sizeof(a
= a
), ""); // expected-warning {{expression with side effects has no effect in an unevaluated context}}
65 // Volatile stores aren't side-effect free.
67 volatile int &vol_a_ref
= vol_a
;
68 vol_a_ref
= vol_a_ref
;
76 struct TemplateClass
{
79 var
= var
; // expected-warning {{assigning field to itself}}
88 TemplateClass
<Dummy
> c
;
93 // It may make sense not to warn on the rest of the tests.
94 // It may be a valid use-case to self-assign to tell the compiler that
95 // it is ok to vectorize the store.
102 void f1(C
&s
, C
&t
) {
111 void f2(T
*t
, T
*t2
) {
116 void f3(T
&t
, T
&t2
) {