Closed
Bug 1495892
Opened 6 years ago
Closed 6 years ago
clang trunk build warning: "GLContext.h:3504:33 [-Wc++2a-compat] aggregate initialization of type 'mozilla::gl::GLContextSymbols' with user-declared constructors is incompatible with C++2a"
Categories
(Core :: Graphics: CanvasWebGL, defect)
Core
Graphics: CanvasWebGL
Tracking
()
VERIFIED
FIXED
mozilla64
Tracking | Status | |
---|---|---|
firefox64 | --- | fixed |
People
(Reporter: dholbert, Assigned: jgilbert)
References
(Blocks 3 open bugs)
Details
Attachments
(1 file)
(deleted),
text/x-phabricator-request
|
Details |
I get these build warnings with current clang SVN trunk (SVN revision 343613, technically version 8.0 but probably introduced pretty recently):
====
warning: gfx/gl/GLContext.cpp:325:20 [-Wc++2a-compat] aggregate initialization of type 'mozilla::gl::GLContextSymbols' with user-declared constructors is incompatible with C++2a
warning: gfx/gl/GLContext.cpp:2054:16 [-Wc++2a-compat] aggregate initialization of type 'mozilla::gl::GLContextSymbols' with user-declared constructors is incompatible with C++2a
warning: gfx/gl/GLContext.h:3504:33 [-Wc++2a-compat] aggregate initialization of type 'mozilla::gl::GLContextSymbols' with user-declared constructors is incompatible with C++2a
====
This is about this declaration:
> GLContextSymbols mSymbols = {};
https://dxr.mozilla.org/mozilla-central/rev/56b988a937689d5599400afa59b72c390b40abf2/gfx/gl/GLContext.h#3504
...and this assignment:
> // If initialization fails, zero the symbols to avoid hard-to-understand bugs.
> mSymbols = {};
https://dxr.mozilla.org/mozilla-central/rev/56b988a937689d5599400afa59b72c390b40abf2/gfx/gl/GLContext.cpp#325
...which it complains about because we do have a user-declared constructor -- THOUGH, we only declare it insomuch as to delete it:
> struct GLContextSymbols final
> {
> GLContextSymbols() = delete; // Initialize with {}.
https://dxr.mozilla.org/mozilla-central/rev/56b988a937689d5599400afa59b72c390b40abf2/gfx/gl/GLContextSymbols.h#30
This deleted-constructor scenario almost seems like it should be an exception to the warning, but apparently it was considered in the proposal -- see section 1.1 here:
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p1008r1.pdf
Quoting section 1.1 of that paper, which gives an example like ours (deleted constructor, aggregate instantiation with {}):
"Clearly, the intent of the deleted constructor is to prevent the user from initializing the class. However, contrary to intuition, this does not work: the user can still initialize [instances of the class] via aggregate initialization because this completely bypasses the constructors."
In our case, the "clearly" thing here is not actually accurate. But maybe we're abusing this C++ feature?
(A bit more info at https://clang.llvm.org/cxx_status.html -- see row for "Prohibit aggregates with user-declared constructors" there, which links to the PDF noted above.)
This issue seems to have been introduced by bug 1411626 (which deleted the constructor) and, to a lesser extent, bug 1482974 (which added some of these "= {}" lines.) Setting both of those as dependencies.
Reporter | ||
Updated•6 years ago
|
Flags: needinfo?(jgilbert)
Reporter | ||
Updated•6 years ago
|
Blocks: buildwarning
Summary: /GLContext.h:3504:33 [-Wc++2a-compat] aggregate initialization of type 'mozilla::gl::GLContextSymbols' with user-declared constructors is incompatible with C++2a → clang trunk build warning: "GLContext.h:3504:33 [-Wc++2a-compat] aggregate initialization of type 'mozilla::gl::GLContextSymbols' with user-declared constructors is incompatible with C++2a"
Assignee | ||
Comment 1•6 years ago
|
||
Yeah, I deleted the constructors to force aggregate initialization, as they mention, to prevent uninitialized values.
It looks like they're taking this pseudo-annotation away.
For the curious, it seems like the compelling issue here is that there's no easy way to forbid aggregate construction on a class before this proposal. (You would have to include a dummy non-default-constructable member object though, I think? And even then they could agg-construct /that/)
Flags: needinfo?(jgilbert)
Assignee | ||
Updated•6 years ago
|
Assignee: nobody → jgilbert
Comment 3•6 years ago
|
||
I reported it in bug 1494603
--
It was caused by this upstream change:
https://github.com/llvm-mirror/clang/commit/de8e63fd00e24e58a5ca05007cf7954916a6e6b9
--
Blocks: build-clang-trunk
Assignee | ||
Comment 4•6 years ago
|
||
I played around some, and I no longer see a way to encourage zero-initializing, besides static analysis to lint for lack of initialization.
Assignee | ||
Comment 5•6 years ago
|
||
Updated•6 years ago
|
Attachment #9017366 -
Attachment description: Bug 1495892 - Aggregates in c++2a can't have deleted ctors. - → Bug 1495892 - Aggregates in c++2a can't have deleted ctors.
Pushed by jgilbert@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/af0263577e4d
Aggregates in c++2a can't have deleted ctors. r=dholbert
Comment 7•6 years ago
|
||
bugherder |
Status: NEW → RESOLVED
Closed: 6 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla64
Updated•6 years ago
|
Status: RESOLVED → VERIFIED
You need to log in
before you can comment on or make changes to this bug.
Description
•