1 // RUN: %clang_cc1 -fsyntax-only -Wself-assign -DDUMMY -verify %s
2 // RUN: %clang_cc1 -fsyntax-only -Wself-assign -DV0 -verify %s
3 // RUN: %clang_cc1 -fsyntax-only -Wself-assign -DV1 -verify %s
4 // RUN: %clang_cc1 -fsyntax-only -Wself-assign -DV2 -verify %s
5 // RUN: %clang_cc1 -fsyntax-only -Wself-assign -DV3 -verify %s
6 // RUN: %clang_cc1 -fsyntax-only -Wself-assign -DV4 -verify %s
7 // RUN: %clang_cc1 -fsyntax-only -Wno-self-assign -Wself-assign-overloaded -DDUMMY -verify %s
8 // RUN: %clang_cc1 -fsyntax-only -Wno-self-assign -Wself-assign-overloaded -DV0 -verify %s
9 // RUN: %clang_cc1 -fsyntax-only -Wno-self-assign -Wself-assign-overloaded -DV1 -verify %s
10 // RUN: %clang_cc1 -fsyntax-only -Wno-self-assign -Wself-assign-overloaded -DV2 -verify %s
11 // RUN: %clang_cc1 -fsyntax-only -Wno-self-assign -Wself-assign-overloaded -DV3 -verify %s
12 // RUN: %clang_cc1 -fsyntax-only -Wno-self-assign -Wself-assign-overloaded -DV4 -verify %s
21 S
&operator=(const S
&) = default;
23 S
&operator=(S
&) = default;
25 S
&operator=(const S
&);
29 #error Define something!
31 S
&operator*=(const S
&);
32 S
&operator/=(const S
&);
33 S
&operator%=(const S
&);
34 S
&operator+=(const S
&);
35 S
&operator-=(const S
&);
36 S
&operator<<=(const S
&);
37 S
&operator>>=(const S
&);
38 S
&operator&=(const S
&);
39 S
&operator|=(const S
&);
40 S
&operator^=(const S
&);
41 S
&operator=(const volatile S
&) volatile;
47 a
= a
; // expected-warning{{explicitly assigning}}
48 b
= b
; // expected-warning{{explicitly assigning}}
51 a
= a
= a
; // expected-warning{{explicitly assigning}}
56 a
/= a
; // expected-warning {{explicitly assigning}}
57 a
%= a
; // expected-warning {{explicitly assigning}}
59 a
-= a
; // expected-warning {{explicitly assigning}}
62 a
&= a
; // expected-warning {{explicitly assigning}}
63 a
|= a
; // expected-warning {{explicitly assigning}}
64 a
^= a
; // expected-warning {{explicitly assigning}}
68 void false_positives() {
73 // These shouldn't warn due to the use of the preprocessor.
82 // Ways to silence the warning.
85 a
= static_cast<decltype(a
) &>(a
);
88 // Volatile stores aren't side-effect free.
91 volatile S
&vol_a_ref
= vol_a
;
92 vol_a_ref
= vol_a_ref
;
96 // Do not diagnose self-assigment in an unevaluated context
98 SNoExcept() = default;
99 SNoExcept
&operator=(const SNoExcept
&) noexcept
;
101 void false_positives_unevaluated_ctx(SNoExcept a
) noexcept(noexcept(a
= a
)) {
102 decltype(a
= a
) b
= a
;
103 static_assert(noexcept(a
= a
), "");
104 static_assert(sizeof(a
= a
), "");
107 template <typename T
>
110 a
= a
; // expected-warning{{explicitly assigning}}