Skip to content

Give this diagnostic a diagnostic group #136182

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

Merged
merged 1 commit into from
Apr 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,10 @@ Improvements to Clang's diagnostics

Fixes #GH131127

- ``-Wuninitialized`` now diagnoses when a class does not declare any
constructors to initialize their non-modifiable members. The diagnostic is
not new; being controlled via a warning group is what's new. Fixes #GH41104

Improvements to Clang's time-trace
----------------------------------

Expand Down
3 changes: 2 additions & 1 deletion clang/include/clang/Basic/DiagnosticSemaKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -2266,7 +2266,8 @@ def err_constructor_byvalue_arg : Error<
"copy constructor must pass its first argument by reference">;
def warn_no_constructor_for_refconst : Warning<
"%select{struct|interface|union|class|enum}0 %1 does not declare any "
"constructor to initialize its non-modifiable members">;
"constructor to initialize its non-modifiable members">,
InGroup<Uninitialized>;
def note_refconst_member_not_initialized : Note<
"%select{const|reference}0 member %1 will never be initialized">;
def ext_ms_explicit_constructor_call : ExtWarn<
Expand Down
3 changes: 1 addition & 2 deletions clang/test/Misc/warning-flags.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ This test serves two purposes:

The list of warnings below should NEVER grow. It should gradually shrink to 0.

CHECK: Warnings without flags (57):
CHECK: Warnings without flags (56):

CHECK-NEXT: ext_expected_semi_decl_list
CHECK-NEXT: ext_missing_whitespace_after_macro_name
Expand Down Expand Up @@ -57,7 +57,6 @@ CHECK-NEXT: warn_method_param_redefinition
CHECK-NEXT: warn_missing_case_for_condition
CHECK-NEXT: warn_missing_dependent_template_keyword
CHECK-NEXT: warn_missing_whitespace_after_macro_name
CHECK-NEXT: warn_no_constructor_for_refconst
CHECK-NEXT: warn_not_compound_assign
CHECK-NEXT: warn_objc_property_copy_missing_on_block
CHECK-NEXT: warn_objc_protocol_qualifier_missing_id
Expand Down
13 changes: 13 additions & 0 deletions clang/test/SemaCXX/uninitialized-no-ctor.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// RUN: %clang_cc1 -fsyntax-only -Wuninitialized -verify %s
// RUN: %clang_cc1 -fsyntax-only -Wno-uninitialized -verify=good %s
//good-no-diagnostics

template <class T>
class RefMem { // expected-warning {{class 'RefMem<int &>' does not declare any constructor to initialize its non-modifiable members}}
T &M; // expected-note {{reference member 'M' will never be initialized}}
};

struct RefRef {
RefMem<int &> R; // expected-note {{in instantiation of template class 'RefMem<int &>' requested here}}
};

Loading