Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added more samples #6812

Merged
merged 4 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions samples/accessMoved/bad.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
void foo(std::string);

int main()
{
std::string s = "test";
foo(std::move(s));

std::cout << s << std::endl;
}
9 changes: 9 additions & 0 deletions samples/accessMoved/good.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
void foo(std::string);

int main()
{
std::string s = "test";
foo(s);

std::cout << s << std::endl;
}
9 changes: 9 additions & 0 deletions samples/accessMoved/out.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
samples\accessMoved\bad.cpp:8:18: warning: Access of moved variable 's'. [accessMoved]
std::cout << s << std::endl;
^
samples\accessMoved\bad.cpp:6:9: note: Calling std::move(s)
foo(std::move(s));
^
samples\accessMoved\bad.cpp:8:18: note: Access of moved variable 's'.
std::cout << s << std::endl;
^
11 changes: 11 additions & 0 deletions samples/multiCondition/bad.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
static void f(bool b)
{
if (b) {}
else if (!b) {}
}

int main()
{
f(true);
return 0;
}
11 changes: 11 additions & 0 deletions samples/multiCondition/good.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
static void f(bool b)
{
if (b) {}
else {}
}

int main()
{
f(true);
return 0;
}
9 changes: 9 additions & 0 deletions samples/multiCondition/out.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
samples\multiCondition\bad.c:4:14: style: Expression is always true because 'else if' condition is opposite to previous condition at line 3. [multiCondition]
else if (!b) {}
^
samples\multiCondition\bad.c:3:9: note: first condition
if (b) {}
^
samples\multiCondition\bad.c:4:14: note: else if condition is opposite to first condition
else if (!b) {}
^
11 changes: 11 additions & 0 deletions samples/passedByValue_1/bad.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class C
{
public:
explicit C(std::string s)
: _s(s)
{
}
void foo();
private:
std::string _s;
};
11 changes: 11 additions & 0 deletions samples/passedByValue_1/good.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class C
{
public:
explicit C(std::string s)
: _s(std::move(s))
{
}
void foo();
private:
std::string _s;
};
3 changes: 3 additions & 0 deletions samples/passedByValue_1/out.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
samples\passedByValue_1\bad.cpp:4:28: performance: Function parameter 's' should be passed by const reference. [passedByValue]
explicit C(std::string s)
^
10 changes: 10 additions & 0 deletions samples/passedByValue_2/bad.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
bool foo(std::string s)
{
return s.empty();
}

int main()
{
std::string s;
foo(s);
}
10 changes: 10 additions & 0 deletions samples/passedByValue_2/good.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
bool foo(const std::string& s)
{
return s.empty();
}

int main()
{
std::string s;
foo(s);
}
3 changes: 3 additions & 0 deletions samples/passedByValue_2/out.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
samples\passedByValue_2\bad.cpp:1:22: performance: Function parameter 's' should be passed by const reference. [passedByValue]
bool foo(std::string s)
^
7 changes: 7 additions & 0 deletions samples/unreadVariable/bad.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
void foo(const std::string&, const std::string&);

int main()
{
std::string s1 = "test1", s2 = "test2";
foo(s1, s1);
}
7 changes: 7 additions & 0 deletions samples/unreadVariable/good.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
void foo(const std::string&, const std::string&);

int main()
{
std::string s1 = "test1", s2 = "test2";
foo(s1, s2);
}
3 changes: 3 additions & 0 deletions samples/unreadVariable/out.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
samples\unreadVariable\bad.cpp:5:34: style: Variable 's2' is assigned a value that is never used. [unreadVariable]
std::string s1 = "test1", s2 = "test2";
^
Loading