-
Notifications
You must be signed in to change notification settings - Fork 0
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
Clang tidy pr #3
Changes from 9 commits
cb992b1
a63c304
2e882d6
ef6845d
4669934
0b9f040
7f0362a
d42d127
f2ad533
f5a4842
28ff62c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -8,7 +8,7 @@ | |||||||||||||||||||||||||||||||||
#include <unordered_map> | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
static int s_counter = 0; | ||||||||||||||||||||||||||||||||||
class obj | ||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||
public: | ||||||||||||||||||||||||||||||||||
obj() : m_a{ s_counter++ } | ||||||||||||||||||||||||||||||||||
|
@@ -20,17 +20,20 @@ | |||||||||||||||||||||||||||||||||
m_a = o.m_a; | ||||||||||||||||||||||||||||||||||
std::cout << "obj " << m_a << " copied. \n"; | ||||||||||||||||||||||||||||||||||
Comment on lines
20
to
21
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. clang-tidy diagnostics
Suggested change
|
||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
~obj() | ||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. clang-tidy diagnostics
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. clang-tidy diagnostics
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. clang-tidy diagnostics
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. clang-tidy diagnostics
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. clang-tidy diagnostics
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. clang-tidy diagnostics
Suggested change
|
||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||
std::cout << " obj " << m_a << " destruct. \n"; | ||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. clang-tidy diagnostics
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. clang-tidy diagnostics
Suggested change
|
||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
int& a() { return m_a; } | ||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. clang-tidy diagnostics
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. clang-tidy diagnostics
Suggested change
|
||||||||||||||||||||||||||||||||||
private: | ||||||||||||||||||||||||||||||||||
int m_a; | ||||||||||||||||||||||||||||||||||
static int m_b; | ||||||||||||||||||||||||||||||||||
Comment on lines
31
to
+32
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. clang-tidy diagnostics
Suggested change
Comment on lines
31
to
+32
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. clang-tidy diagnostics
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. clang-tidy diagnostics
Suggested change
|
||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
class bank | ||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||
public: | ||||||||||||||||||||||||||||||||||
bank() | ||||||||||||||||||||||||||||||||||
|
@@ -41,35 +44,35 @@ | |||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||
std::cout << "bank destruct. \n"; | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
void set(const std::any& a) | ||||||||||||||||||||||||||||||||||
void set(const std::any& aB) | ||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. clang-tidy diagnostics
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. clang-tidy diagnostics
Suggested change
|
||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||
std::cout << "set bank data. \n"; | ||||||||||||||||||||||||||||||||||
m_data = a; | ||||||||||||||||||||||||||||||||||
m_data = aB; | ||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. clang-tidy diagnostics
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. clang-tidy diagnostics
Suggested change
|
||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
//template <class T> void set_org(T a) /// 如果參數type 直接寫 T, 會複製傳進來 | ||||||||||||||||||||||||||||||||||
template <class T> void set_org(const T& a) /// 這樣是物件參考,參數不會複製 | ||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||
std::cout << "set bank org data. \n"; | ||||||||||||||||||||||||||||||||||
m_data = a; /// 這裡會複製 | ||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. clang-tidy diagnostics
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. clang-tidy diagnostics
Suggested change
|
||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
const std::any& get() | ||||||||||||||||||||||||||||||||||
const std::any& get() | ||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. clang-tidy diagnostics
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. clang-tidy diagnostics
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. clang-tidy diagnostics
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. clang-tidy diagnostics
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. clang-tidy diagnostics
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. clang-tidy diagnostics
Suggested change
|
||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||
std::cout << "get bank data. \n"; | ||||||||||||||||||||||||||||||||||
return m_data; | ||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. clang-tidy diagnostics
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. clang-tidy diagnostics
Suggested change
|
||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
template <class T> T get_org() | ||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||
std::cout << "get bank org data. \n"; | ||||||||||||||||||||||||||||||||||
return std::any_cast<T>(m_data); | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
template <class T> std::optional<T> get_opt() | ||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||
std::cout << "get bank opt data. \n"; | ||||||||||||||||||||||||||||||||||
return std::any_cast<T>(m_data); | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
template <class T> std::optional<std::reference_wrapper<T>> get_opt_ref() | ||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||
std::cout << "get bank opt data. \n"; | ||||||||||||||||||||||||||||||||||
//return std::any_cast<T>(m_data); /// 這樣編譯不過, C2440 | ||||||||||||||||||||||||||||||||||
|
@@ -77,6 +80,7 @@ | |||||||||||||||||||||||||||||||||
return std::ref(m_data); | ||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. clang-tidy diagnostics
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. clang-tidy diagnostics
Suggested change
|
||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
std::any m_data; | ||||||||||||||||||||||||||||||||||
std::vector<obj> m_org_data; | ||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. clang-tidy diagnostics
Suggested change
clang-tidy diagnosticStdAny/StdAny/StdAny.cpp:79:14: warning: [misc-non-private-member-variables-in-classes]
std::any m_data;
^ clang-tidy diagnosticStdAny/StdAny/StdAny.cpp:80:22: warning: [misc-non-private-member-variables-in-classes]
std::vector<obj> m_org_data;
^ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. clang-tidy diagnostics
Suggested change
clang-tidy diagnosticStdAny/StdAny/StdAny.cpp:81:14: warning: [misc-non-private-member-variables-in-classes]
std::any m_data;
^ clang-tidy diagnosticStdAny/StdAny/StdAny.cpp:82:22: warning: [misc-non-private-member-variables-in-classes]
std::vector<obj> m_org_data;
^ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. clang-tidy diagnostics
Suggested change
clang-tidy diagnosticStdAny/StdAny/StdAny.cpp:81:14: warning: [misc-non-private-member-variables-in-classes]
std::any m_data;
^ clang-tidy diagnosticStdAny/StdAny/StdAny.cpp:82:22: warning: [misc-non-private-member-variables-in-classes]
std::vector<obj> m_org_data;
^
Comment on lines
82
to
+83
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. clang-tidy diagnostics
Suggested change
clang-tidy diagnosticStdAny/StdAny/StdAny.cpp:82:14: warning: [misc-non-private-member-variables-in-classes]
std::any m_data;
^ clang-tidy diagnosticStdAny/StdAny/StdAny.cpp:83:22: warning: [misc-non-private-member-variables-in-classes]
std::vector<obj> m_org_data;
^
Comment on lines
82
to
+83
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. clang-tidy diagnostics
Suggested change
clang-tidy diagnosticStdAny/StdAny/StdAny.cpp:82:14: warning: [misc-non-private-member-variables-in-classes]
std::any m_data;
^ clang-tidy diagnosticStdAny/StdAny/StdAny.cpp:83:22: warning: [misc-non-private-member-variables-in-classes]
std::vector<obj> m_org_data;
^ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. clang-tidy diagnostics
Suggested change
clang-tidy diagnosticStdAny/StdAny/StdAny.cpp:82:14: warning: [misc-non-private-member-variables-in-classes]
std::any m_data;
^ clang-tidy diagnosticStdAny/StdAny/StdAny.cpp:83:22: warning: [misc-non-private-member-variables-in-classes]
std::vector<obj> m_org_data;
^ |
||||||||||||||||||||||||||||||||||
//const std::any& m_data; /// 不能用 | ||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||
using func_any = std::function<std::any(const std::string&)>; | ||||||||||||||||||||||||||||||||||
|
@@ -103,7 +107,7 @@ | |||||||||||||||||||||||||||||||||
//auto ob = std::any_cast<std::vector<obj>>(std::cref(a)); /// 這樣不能轉 | ||||||||||||||||||||||||||||||||||
auto ob = std::any_cast<std::reference_wrapper<std::vector<obj>>>(a1); /// by reference 要這樣轉 | ||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. clang-tidy diagnostics
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. clang-tidy diagnostics
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. clang-tidy diagnostics
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. clang-tidy diagnostics
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. clang-tidy diagnostics
Suggested change
|
||||||||||||||||||||||||||||||||||
//ob[3].m_a = -1; // by value | ||||||||||||||||||||||||||||||||||
ob.get()[3].m_a = -1; // by reference, 要從 wrapper 裡 get 出來 | ||||||||||||||||||||||||||||||||||
ob.get()[3].a() = -1; // by reference, 要從 wrapper 裡 get 出來 | ||||||||||||||||||||||||||||||||||
std::cout << "func return\n"; /// 參數跟著內部變數一起解構 | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
|
@@ -153,7 +157,7 @@ | |||||||||||||||||||||||||||||||||
//auto ov2 = b->get_org<const std::vector<obj>&>(); /// 有複製, auto 不是引用 | ||||||||||||||||||||||||||||||||||
//auto& ov2 = b->get_org<const std::vector<obj>&>(); /// 沒有複製 | ||||||||||||||||||||||||||||||||||
auto& ov2 = b->get_org<std::vector<obj>&>(); /// 沒有複製, 可以取出來改 | ||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. clang-tidy diagnostics
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. clang-tidy diagnostics
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. clang-tidy diagnostics
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. clang-tidy diagnostics
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. clang-tidy diagnostics
Suggested change
|
||||||||||||||||||||||||||||||||||
ov2[8].m_a = -23; | ||||||||||||||||||||||||||||||||||
ov2[8].a() = -23; | ||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. clang-tidy diagnosticStdAny/StdAny/StdAny.cpp:159:13: warning: [readability-magic-numbers]
ov2[8].a() = -23;
^ clang-tidy diagnosticStdAny/StdAny/StdAny.cpp:159:23: warning: [readability-magic-numbers]
ov2[8].a() = -23;
^ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. clang-tidy diagnosticStdAny/StdAny/StdAny.cpp:159:13: warning: [readability-magic-numbers]
ov2[8].a() = -23;
^ clang-tidy diagnosticStdAny/StdAny/StdAny.cpp:159:23: warning: [readability-magic-numbers]
ov2[8].a() = -23;
^ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. clang-tidy diagnosticStdAny/StdAny/StdAny.cpp:160:13: warning: [readability-magic-numbers]
ov2[8].a() = -23;
^ clang-tidy diagnosticStdAny/StdAny/StdAny.cpp:160:23: warning: [readability-magic-numbers]
ov2[8].a() = -23;
^ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. clang-tidy diagnosticStdAny/StdAny/StdAny.cpp:160:13: warning: [readability-magic-numbers]
ov2[8].a() = -23;
^ clang-tidy diagnosticStdAny/StdAny/StdAny.cpp:160:23: warning: [readability-magic-numbers]
ov2[8].a() = -23;
^ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. clang-tidy diagnosticStdAny/StdAny/StdAny.cpp:160:13: warning: [readability-magic-numbers]
ov2[8].a() = -23;
^ clang-tidy diagnosticStdAny/StdAny/StdAny.cpp:160:23: warning: [readability-magic-numbers]
ov2[8].a() = -23;
^ |
||||||||||||||||||||||||||||||||||
std::cout << "end block\n"; | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
/// 結論是, any 是 value, 建構或指定時會複製一份; 取值時並不會特別複製一份 | ||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clang-tidy diagnostics