Skip to content

Commit c609cd2

Browse files
authored
Give this diagnostic a diagnostic group (#136182)
I put this under -Wunitialized because that's the same group it's under in GCC. Fixes #41104
1 parent c5d5972 commit c609cd2

File tree

4 files changed

+20
-3
lines changed

4 files changed

+20
-3
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,10 @@ Improvements to Clang's diagnostics
391391

392392
Fixes #GH131127
393393

394+
- ``-Wuninitialized`` now diagnoses when a class does not declare any
395+
constructors to initialize their non-modifiable members. The diagnostic is
396+
not new; being controlled via a warning group is what's new. Fixes #GH41104
397+
394398
Improvements to Clang's time-trace
395399
----------------------------------
396400

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2266,7 +2266,8 @@ def err_constructor_byvalue_arg : Error<
22662266
"copy constructor must pass its first argument by reference">;
22672267
def warn_no_constructor_for_refconst : Warning<
22682268
"%select{struct|interface|union|class|enum}0 %1 does not declare any "
2269-
"constructor to initialize its non-modifiable members">;
2269+
"constructor to initialize its non-modifiable members">,
2270+
InGroup<Uninitialized>;
22702271
def note_refconst_member_not_initialized : Note<
22712272
"%select{const|reference}0 member %1 will never be initialized">;
22722273
def ext_ms_explicit_constructor_call : ExtWarn<

clang/test/Misc/warning-flags.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ This test serves two purposes:
1818

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

21-
CHECK: Warnings without flags (57):
21+
CHECK: Warnings without flags (56):
2222

2323
CHECK-NEXT: ext_expected_semi_decl_list
2424
CHECK-NEXT: ext_missing_whitespace_after_macro_name
@@ -57,7 +57,6 @@ CHECK-NEXT: warn_method_param_redefinition
5757
CHECK-NEXT: warn_missing_case_for_condition
5858
CHECK-NEXT: warn_missing_dependent_template_keyword
5959
CHECK-NEXT: warn_missing_whitespace_after_macro_name
60-
CHECK-NEXT: warn_no_constructor_for_refconst
6160
CHECK-NEXT: warn_not_compound_assign
6261
CHECK-NEXT: warn_objc_property_copy_missing_on_block
6362
CHECK-NEXT: warn_objc_protocol_qualifier_missing_id
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// RUN: %clang_cc1 -fsyntax-only -Wuninitialized -verify %s
2+
// RUN: %clang_cc1 -fsyntax-only -Wno-uninitialized -verify=good %s
3+
//good-no-diagnostics
4+
5+
template <class T>
6+
class RefMem { // expected-warning {{class 'RefMem<int &>' does not declare any constructor to initialize its non-modifiable members}}
7+
T &M; // expected-note {{reference member 'M' will never be initialized}}
8+
};
9+
10+
struct RefRef {
11+
RefMem<int &> R; // expected-note {{in instantiation of template class 'RefMem<int &>' requested here}}
12+
};
13+

0 commit comments

Comments
 (0)