Skip to content

Commit 7fa2eb5

Browse files
authored
added more samples (#6812)
1 parent 38e8d39 commit 7fa2eb5

File tree

15 files changed

+123
-0
lines changed

15 files changed

+123
-0
lines changed

samples/accessMoved/bad.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
void foo(std::string);
2+
3+
int main()
4+
{
5+
std::string s = "test";
6+
foo(std::move(s));
7+
8+
std::cout << s << std::endl;
9+
}

samples/accessMoved/good.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
void foo(std::string);
2+
3+
int main()
4+
{
5+
std::string s = "test";
6+
foo(s);
7+
8+
std::cout << s << std::endl;
9+
}

samples/accessMoved/out.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
samples\accessMoved\bad.cpp:8:18: warning: Access of moved variable 's'. [accessMoved]
2+
std::cout << s << std::endl;
3+
^
4+
samples\accessMoved\bad.cpp:6:9: note: Calling std::move(s)
5+
foo(std::move(s));
6+
^
7+
samples\accessMoved\bad.cpp:8:18: note: Access of moved variable 's'.
8+
std::cout << s << std::endl;
9+
^

samples/multiCondition/bad.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
static void f(bool b)
2+
{
3+
if (b) {}
4+
else if (!b) {}
5+
}
6+
7+
int main()
8+
{
9+
f(true);
10+
return 0;
11+
}

samples/multiCondition/good.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
static void f(bool b)
2+
{
3+
if (b) {}
4+
else {}
5+
}
6+
7+
int main()
8+
{
9+
f(true);
10+
return 0;
11+
}

samples/multiCondition/out.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
samples\multiCondition\bad.c:4:14: style: Expression is always true because 'else if' condition is opposite to previous condition at line 3. [multiCondition]
2+
else if (!b) {}
3+
^
4+
samples\multiCondition\bad.c:3:9: note: first condition
5+
if (b) {}
6+
^
7+
samples\multiCondition\bad.c:4:14: note: else if condition is opposite to first condition
8+
else if (!b) {}
9+
^

samples/passedByValue_1/bad.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class C
2+
{
3+
public:
4+
explicit C(std::string s)
5+
: _s(s)
6+
{
7+
}
8+
void foo();
9+
private:
10+
std::string _s;
11+
};

samples/passedByValue_1/good.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class C
2+
{
3+
public:
4+
explicit C(std::string s)
5+
: _s(std::move(s))
6+
{
7+
}
8+
void foo();
9+
private:
10+
std::string _s;
11+
};

samples/passedByValue_1/out.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
samples\passedByValue_1\bad.cpp:4:28: performance: Function parameter 's' should be passed by const reference. [passedByValue]
2+
explicit C(std::string s)
3+
^

samples/passedByValue_2/bad.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
bool foo(std::string s)
2+
{
3+
return s.empty();
4+
}
5+
6+
int main()
7+
{
8+
std::string s;
9+
foo(s);
10+
}

0 commit comments

Comments
 (0)