[PATCH] D136828: [clang][Interp] Diagnose uninitialized array record fields
Aaron Ballman via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Nov 4 11:49:23 PDT 2022
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.
Aside from the request for a comment about `SourceLocation SL`, this LGTM (though we may want to improve the diagnostic behavior in the future).
================
Comment at: clang/test/AST/Interp/cxx20.cpp:119
+ A a;
+ constexpr C2() {} // expected-note {{subobject of type 'int' is not initialized}}
+ };
----------------
tbaeder wrote:
> aaron.ballman wrote:
> > This note is kind of confusing to me. At this location, it's not a subobject of type `int` that matters, it's `A` that's not fully initialized, and within `A` the note points out which field is not initialized.
> >
> > I think this could get especially confusing in a case like:
> > ```
> > class C {
> > public:
> > A a;
> > int b = 0;
> >
> > constexpr C() {}
> > }
> > ```
> > because we'll talk about `int` not being initialized and it will look very much like it is.
> I thought this might even be an improvement over the current situation. It's followed by the "subobject declared here" note as well. With the current interpreter, the output is:
>
> ```
> array.cpp:95:16: error: constexpr variable 'c2' must be initialized by a constant expression
> constexpr C2 c2; // expected-error {{must be initialized by a constant expression}} \
> ^~
> array.cpp:95:16: note: subobject of type 'int' is not initialized
> array.cpp:88:18: note: subobject declared here
> struct A { int a; };
> ^
> ```
>
> And with the new one:
> ```
> array.cpp:95:16: error: constexpr variable 'c2' must be initialized by a constant expression
> constexpr C2 c2; // expected-error {{must be initialized by a constant expression}} \
> ^~
> array.cpp:93:15: note: subobject of type 'int' is not initialized
> constexpr C2() {} // expected-note {{subobject of type 'int' is not initialized}}
> ^
> array.cpp:95:16: note: in call to 'C2()'
> constexpr C2 c2; // expected-error {{must be initialized by a constant expression}} \
> ^
> array.cpp:88:18: note: subobject declared here
> struct A { int a; };
> ^
> ```
>
> But I dislike both very much, no idea why there's no "subobject declared here is not initialized" diagnostic and we need two notes instead :(
I think we can live with the behavior for now and improve the diagnostics once we've got more basic functionality in place.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D136828/new/
https://reviews.llvm.org/D136828
More information about the cfe-commits
mailing list