-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Better handle const/noexcept methods #2211
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
Changes from all commits
b33e0e3
5613abc
b6222ec
8dd8a91
e7f0e9b
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 |
|---|---|---|
|
|
@@ -164,6 +164,7 @@ class TestSimplifyTypedef : public TestFixture { | |
| TEST_CASE(simplifyTypedef126); // ticket #5953 | ||
| TEST_CASE(simplifyTypedef127); // ticket #8878 | ||
| TEST_CASE(simplifyTypedef128); // ticket #9053 | ||
| TEST_CASE(simplifyTypedef129); | ||
|
|
||
| TEST_CASE(simplifyTypedefFunction1); | ||
| TEST_CASE(simplifyTypedefFunction2); // ticket #1685 | ||
|
|
@@ -2544,6 +2545,63 @@ class TestSimplifyTypedef : public TestFixture { | |
| ASSERT_EQUALS(exp, tok(code, false)); | ||
| } | ||
|
|
||
| void simplifyTypedef129() { | ||
| { | ||
| const char code[] = "class c {\n" | ||
| " typedef char foo[4];\n" | ||
| " foo &f ;\n" | ||
| "};"; | ||
|
|
||
| const char exp [] = "class c { char ( & f ) [ 4 ] ; } ;"; | ||
| ASSERT_EQUALS(exp, tok(code, false)); | ||
| } | ||
|
|
||
| { | ||
| const char code[] = "class c {\n" | ||
| " typedef char foo[4];\n" | ||
|
Collaborator
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. I don't think this is C++ code. At least g++ 8.3.0 does not like it when I test. Which compiler do you use?
Contributor
Author
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. Indeed. My brain switched off when I tried to add some more test cases. /o |
||
| " const foo &f;\n" | ||
| "};"; | ||
|
|
||
| const char exp [] = "class c { const char ( & f ) [ 4 ] ; } ;"; | ||
| ASSERT_EQUALS(exp, tok(code, false)); | ||
| } | ||
|
|
||
| { | ||
| const char code[] = "class c {\n" | ||
| " typedef char foo[4];\n" | ||
| " foo _a;\n" | ||
| " constexpr const foo &c_str() const noexcept { return _a; }\n" | ||
| "};"; | ||
|
|
||
| const char exp [] = "class c { char _a [ 4 ] ; const const char ( & c_str ( ) const noexcept ) [ 4 ] { return _a ; } } ;"; | ||
|
Collaborator
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. I guess this is the correct expansion.. however I admit I don't understand this simplification. I'll trust you on this. However I guess that for instance |
||
| ASSERT_EQUALS(exp, tok(code, false)); | ||
| } | ||
|
|
||
| { | ||
| const char code[] = "class c {\n" | ||
| " typedef char foo[4];\n" | ||
| " foo _a;\n" | ||
| " constexpr operator foo &() const noexcept { return _a; }\n" | ||
| "};"; | ||
|
|
||
| const char actual [] = "class c { char _a [ 4 ] ; const operatorchar ( & ( ) const noexcept ) [ 4 ] { return _a ; } } ;"; | ||
| const char exp [] = "class c { char _a [ 4 ] ; const operator char ( & ( ) const noexcept ) [ 4 ] { return _a ; } } ;"; | ||
| TODO_ASSERT_EQUALS(exp, actual, tok(code, false)); | ||
| } | ||
|
|
||
| { | ||
| const char code[] = "class c {\n" | ||
| " typedef char foo[4];\n" | ||
| " foo _a;\n" | ||
| " constexpr operator const foo &() const noexcept { return _a; }\n" | ||
| "};"; | ||
|
|
||
| const char actual [] = "class c { char _a [ 4 ] ; const operatorconstchar ( & ( ) const noexcept ) [ 4 ] { return _a ; } } ;"; | ||
| const char exp [] = "class c { char _a [ 4 ] ; const operator const char ( & ( ) const noexcept ) [ 4 ] { return _a ; } } ;"; | ||
| TODO_ASSERT_EQUALS(exp, actual, tok(code, false)); | ||
| } | ||
| } | ||
|
|
||
| void simplifyTypedefFunction1() { | ||
| { | ||
| const char code[] = "typedef void (*my_func)();\n" | ||
|
|
||
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.
I would probably have written a Token::Match here. That is shorter code and should be faster. But I don't have a strong opinion about it so will merge anyway..