-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[C] Warn on uninitialized const objects #137166
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 8 commits
bb184fc
c3aef49
f8e1760
32daa84
6773ce9
ef89962
1e34563
c642095
b23359e
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 |
---|---|---|
|
@@ -8197,6 +8197,16 @@ def err_address_space_qualified_new : Error< | |
def err_address_space_qualified_delete : Error< | ||
"'delete' cannot delete objects of type %0 in address space '%1'">; | ||
|
||
def note_default_init_const_member : Note< | ||
"member %0 declared 'const' here">; | ||
def warn_default_init_const : Warning< | ||
"default initialization of an object of type %0%select{| with const member}1 " | ||
"is incompatible with C++">, | ||
InGroup<DefaultConstInit>, DefaultIgnore; | ||
def warn_default_init_const_unsafe : Warning< | ||
"default initialization of an object of type %0%select{| with const member}1 " | ||
"leaves the object uninitialized and is incompatible with C++">, | ||
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. @AaronBallman I just came across this diagnostic. Why did we chose to mention the incompatibility with C++? I found it odd because the diagnostic is showing up when building a C source file. If the code was in an inline function in a header (that could be consumed from C++) then I think it would make sense to mention incompatibility with C++ but if it's in a C source file it makes less sense to me. When I'm building C source files I don't typically think (or care) about what would happen if I were to build the source file with C++ instead of C. Really not a huge deal but I'd like to understand the reasoning and here. 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. Good question! I wish I didn't. :-D We don't have a way to know whether a particular warning group is enabled, so there's no way to tell the difference between the user passing no flags and getting the default-enabled However, maybe I can hack around this by adding a new off-by-default fake diagnostic that is never emitted by Clang but is in the 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 posted #138266 to try to improve this, thank you for bringing it up! |
||
InGroup<DefaultConstInitUnsafe>; | ||
def err_default_init_const : Error< | ||
"default initialization of an object of const type %0" | ||
"%select{| without a user-provided default constructor}1">; | ||
|
Uh oh!
There was an error while loading. Please reload this page.