Skip to content

No -Wc++-compat warning on uninitialized const field in struct #19297

Closed
@chengniansun

Description

@chengniansun
Bugzilla Link 18923
Version trunk
OS Windows NT
CC @chengniansun

Extended Description

At trunk 201801. I am not sure whether clang support the warning flag -Wc++-compat. Currently it does not warn on the uninitialized field in a struct.

$: cat s.c
struct S{const int i;};
void f() {struct S s;}
$: clang-trunk -Wc++-compat -c s.c
$: clang++ -c s.c
clang: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated
s.c:1:8: error: implicit default constructor for 'S' must explicitly initialize the const member 'i'
struct S{const int i;};
^
s.c:1:20: note: declared here
struct S{const int i;};
^
s.c:2:20: note: implicit default constructor for 'S' first required here
void f() {struct S s;}
^
1 error generated.
$:
$: gcc-trunk -Wc++-compat -c s.c
s.c: In function ‘f’:
s.c:2:20: warning: uninitialized const member in ‘struct S’ is invalid in C++ [-Wc++-compat]
void f() {struct S s;}
^
s.c:1:20: note: ‘i’ should be initialized
struct S{const int i;};
^

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugzillaIssues migrated from bugzillaclang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzer

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions