-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[clang] Restrict -Wnrvo to C++ code only. #157059
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
base: main
Are you sure you want to change the base?
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,41 @@ | ||||||
| // RUN: %clang -std=c23 -Wnrvo -Xclang -verify %s | ||||||
|
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
|
||||||
| // expected-no-diagnostics | ||||||
|
|
||||||
| #include <stdlib.h> | ||||||
|
|
||||||
| #define SIZE 20 | ||||||
|
|
||||||
| typedef struct String_s { | ||||||
| char* buf; | ||||||
| size_t len; | ||||||
| } String; | ||||||
|
|
||||||
|
|
||||||
| void clean(String* s) { | ||||||
| free(s->buf); | ||||||
| } | ||||||
|
|
||||||
| String randomString() { | ||||||
| String s = {}; | ||||||
|
|
||||||
| s.buf = malloc(SIZE); | ||||||
| s.len = SIZE; | ||||||
|
|
||||||
| if (!s.buf) { | ||||||
| goto fail; | ||||||
| } | ||||||
|
|
||||||
| return s; | ||||||
|
|
||||||
| fail: | ||||||
| clean(&s); | ||||||
| return (String){}; | ||||||
|
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. Can we also try returning from the body of an |
||||||
| } | ||||||
|
|
||||||
| int main(int argc, char** argv) | ||||||
| { | ||||||
| String s= randomString(); | ||||||
| clean(&s); | ||||||
|
|
||||||
| return 0; | ||||||
| } | ||||||
|
Comment on lines
+35
to
+41
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. nit: lets call that functions something else 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'll fix this, thanks! |
||||||
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.
Instead of using a nested
if, just merge the two conditions using&&.Uh oh!
There was an error while loading. Please reload this page.
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.
Thanks!
One question, after the Diag, and as part of if(!NRVOCandidate) there is a
Returns[I]->setNRVOCandidate(nullptr);
If I merge the two ifs(), then diag will be skip, but returns[i]->setNRVOCandidate(nullptr) will be also skipped. Is that ok?
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.
Ah, no, disregard that. I misread that because of how the diff was formatted; we do in fact need to keep them separate yes.