Debian Codegraph @

clang-tools-extra/test/clang-tidy/checkers/bugprone/unused-return-value-avoid-assignment.cpp

raw
1 // RUN: %check_clang_tidy %s bugprone-unused-return-value %t \
2 // RUN: -config='{CheckOptions: \
3 // RUN: {bugprone-unused-return-value.CheckedFunctions: "::*"}}' \
4 // RUN: --
5
6 struct S1 {
7 S1(){};
8 S1(S1 const &);
9 S1(S1 &&);
10 S1 &operator=(S1 const &);
11 S1 &operator=(S1 &&);
12 S1 &operator+=(S1);
13 S1 &operator++();
14 S1 &operator++(int);
15 S1 &operator--();
16 S1 &operator--(int);
17 };
18
19 struct S2 {
20 S2(){};
21 S2(S2 const &);
22 S2(S2 &&);
23 };
24
25 S2 &operator-=(S2&, int);
26 S2 &operator++(S2 &);
27 S2 &operator++(S2 &, int);
28
29 S1 returnValue();
30 S1 const &returnRef();
31
32 void bar() {
33 returnValue();
34 // CHECK-MESSAGES: [[@LINE-1]]:3: warning: the value returned by this function should not be disregarded; neglecting it may lead to errors
35
36 S1 a{};
37 a = returnValue();
38 a.operator=(returnValue());
39
40 a = returnRef();
41 a.operator=(returnRef());
42
43 a += returnRef();
44
45 a++;
46 ++a;
47 a--;
48 --a;
49
50 S2 b{};
51
52 b -= 1;
53 b++;
54 ++b;
55 }