WebKit Bugzilla
New
Browse
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
RESOLVED FIXED
188146
Use static global variables instead of static NeverDestroyed inside function if possible
https://bugs.webkit.org/show_bug.cgi?id=188146
Summary
Use static global variables instead of static NeverDestroyed inside function ...
Yusuke Suzuki
Reported
2018-07-29 06:56:32 PDT
Use constexpr constructors more instead of NeverDestroyed
Attachments
Patch
(39.16 KB, patch)
2018-07-29 07:05 PDT
,
Yusuke Suzuki
darin
: review+
Details
Formatted Diff
Diff
View All
Add attachment
proposed patch, testcase, etc.
Yusuke Suzuki
Comment 1
2018-07-29 07:05:18 PDT
Created
attachment 346028
[details]
Patch
Darin Adler
Comment 2
2018-07-29 10:43:09 PDT
Comment on
attachment 346028
[details]
Patch Change seems fine. Bug title is a bit inaccurate. Having a constexpr constructor does not affect whether NeverDestroyed is needed. It does affect whether we can have a global outside a function. If the constructor is not constexpr it needs to be inside a function so it gets run the first time the function is installed rather than at load time. What affects the need for NeverDestroyed is whether the class has a trivial destructor. If it does then NeverDestroyed is not needed. In all these cases in this patch we changed both things but they are independent. You can have a static without NeverDestroyed if the destructor is trivial. You can have a global outside a function that uses NeverDestroyed as long as the entire constructor is all constexpr. (Might need to fix NeverDestroyed implementation to be sure it’s constructors are constexpr.)
Darin Adler
Comment 3
2018-07-29 10:50:26 PDT
“Called” not “installed”
Yusuke Suzuki
Comment 4
2018-07-29 11:12:06 PDT
(In reply to Darin Adler from
comment #2
)
> Comment on
attachment 346028
[details]
> Patch > > Change seems fine. > > Bug title is a bit inaccurate. > > Having a constexpr constructor does not affect whether NeverDestroyed is > needed. It does affect whether we can have a global outside a function. If > the constructor is not constexpr it needs to be inside a function so it gets > run the first time the function is installed rather than at load time. > > What affects the need for NeverDestroyed is whether the class has a trivial > destructor. If it does then NeverDestroyed is not needed. > > In all these cases in this patch we changed both things but they are > independent.
Right, changed.
> > You can have a static without NeverDestroyed if the destructor is trivial. > You can have a global outside a function that uses NeverDestroyed as long as > the entire constructor is all constexpr. (Might need to fix NeverDestroyed > implementation to be sure it’s constructors are constexpr.)
Currently, we cannot have constexpr NeverDestroyed, since it allocates an instance on aligned storage with placement `new`. This type of code cannot be achieved inside constexpr constructor unfortunately :(
Yusuke Suzuki
Comment 5
2018-07-29 11:13:33 PDT
Committed
r234347
: <
https://trac.webkit.org/changeset/234347
>
Radar WebKit Bug Importer
Comment 6
2018-07-29 11:14:17 PDT
<
rdar://problem/42710939
>
Note
You need to
log in
before you can comment on or make changes to this bug.
Top of Page
Format For Printing
XML
Clone This Bug