-
Notifications
You must be signed in to change notification settings - Fork 1.8k
C++: Add cpp/uninitialized-local test
#20407
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
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 | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,42 @@ | ||||||
| struct S { | ||||||
| int a; | ||||||
| int b; | ||||||
| int c; | ||||||
| unsigned long *d; | ||||||
|
|
||||||
| union { | ||||||
| struct { | ||||||
| const char *e; | ||||||
| int f; | ||||||
| S *g; | ||||||
| const char *h; | ||||||
| int i; | ||||||
| bool j; | ||||||
| bool k; | ||||||
| const char *l; | ||||||
| char **m; | ||||||
| } n; | ||||||
|
|
||||||
| struct { | ||||||
| bool o; | ||||||
| bool p; | ||||||
| } q; | ||||||
| } r; | ||||||
| }; | ||||||
|
|
||||||
| int too_many_constants_init(S *s); | ||||||
|
|
||||||
| char *too_many_constants(const char *h, bool k, int i) { | ||||||
| const char *e = ""; | ||||||
| char l[64] = ""; | ||||||
| char *m; | ||||||
|
|
||||||
| S s[] = { | ||||||
| {.a = 0, .c = 0, .d = nullptr, .r = {.n = {.e = e, .f = 1, .g = nullptr, .h = h, .i = i, .j = false, .k = k, .l = l, .m = &m}}}, | ||||||
| {.a = 0, .c = 0, .d = nullptr, .r = {.q = {.o = true, .p = true}}} | ||||||
| }; | ||||||
|
|
||||||
| too_many_constants_init(s); | ||||||
|
Contributor
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.
Suggested change
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. Now you need to define what a constant is, because the aggregate here clearly isn't. Can we not go down this rabbit hole, please.
Contributor
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 see the problem, but ok. |
||||||
|
|
||||||
| return m; // GOOD - initialized by too_many_constants_init | ||||||
| } | ||||||
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 think it would be nice with a small comment explaining what the interesting thing being tested here is. Something with too many constants? :)
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.
Nothing anymore, after the extractor fix I merged yesterday. This test is just here to make sure we do not regress.
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.
Then is is testing something interesting right? That we don't regress for some specific case. I'm suggesting it would be nice to write out what the special thing about this case here is. Is it the number of fields, the nesting, etc? It's not clear to me :)
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'm going to politely refuse, because this is related to internal extractor details. If you want the full story, please follow the link to the internal PR that references this PR.
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.
To be clear, I'm not suggesting writing anything about the extractor, but that we highlight the interesting/key aspect of the test. I've suggested a comment below.