Skip to content

Commit

Permalink
added passedByValue samples
Browse files Browse the repository at this point in the history
  • Loading branch information
firewave committed Sep 19, 2024
1 parent c9bdd30 commit 5b81f94
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 0 deletions.
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)
^

0 comments on commit 5b81f94

Please sign in to comment.