Bug 190819 - Cleanup: inline constexpr is redundant as constexpr implies inline
Summary: Cleanup: inline constexpr is redundant as constexpr implies inline
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebCore Misc. (show other bugs)
Version: WebKit Local Build
Hardware: All All
: P2 Normal
Assignee: Ross Kirsling
URL:
Keywords: EasyFix, InRadar
Depends on:
Blocks:
 
Reported: 2018-10-22 21:37 PDT by Daniel Bates
Modified: 2018-10-25 15:24 PDT (History)
11 users (show)

See Also:


Attachments
Patch (24.61 KB, patch)
2018-10-25 14:13 PDT, Ross Kirsling
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Daniel Bates 2018-10-22 21:37:58 PDT
As per [dcl.constexpr] (2), "constexpr functions and constexpr constructors are implicitly inline" (http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3797.pdf). So, it is sufficient to annotate a function with "constexpr" instead of annotating with "inline constexpr".
Comment 1 Daniel Bates 2018-10-22 21:46:38 PDT
Bonus points: teach the style checker to recognize "inline constexpr" and provide an informative diagnostic message that suggests using dropping the "inline" keyword.
Comment 2 Ross Kirsling 2018-10-25 13:47:20 PDT
(In reply to Daniel Bates from comment #1)
> Bonus points: teach the style checker to recognize "inline constexpr" and
> provide an informative diagnostic message that suggests using dropping the
> "inline" keyword.

Looks like clang-tidy should support this in the future:
https://reviews.llvm.org/D18914
Comment 3 Ross Kirsling 2018-10-25 13:48:26 PDT
(In reply to Ross Kirsling from comment #2)
> (In reply to Daniel Bates from comment #1)
> > Bonus points: teach the style checker to recognize "inline constexpr" and
> > provide an informative diagnostic message that suggests using dropping the
> > "inline" keyword.
> 
> Looks like clang-tidy should support this in the future:
> https://reviews.llvm.org/D18914

Er hmm, I posted that before double-checking the date. Guess it's kind of stale. 😓
Comment 4 Ross Kirsling 2018-10-25 14:13:21 PDT
Created attachment 353108 [details]
Patch
Comment 5 Mark Lam 2018-10-25 14:32:16 PDT
Comment on attachment 353108 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=353108&action=review

> Source/JavaScriptCore/ChangeLog:3
> +        Cleanup: inline constexpr is redundant as constexpr implies inline

Are you sure that this is true?  constexpr functions may be called on none const arguments, and therefore produce a non-constexpr value.  Marking a function constexpr only means that it *can* produce a constexpr value, not necessarily that it *will* produce a constexpr value.  Hence, I'm not sure that constexpr necessarily means the function will be inlined.  At least that's my understanding.  Am I wrong?
Comment 6 Ross Kirsling 2018-10-25 14:41:22 PDT
(In reply to Mark Lam from comment #5)
> Comment on attachment 353108 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=353108&action=review
> 
> > Source/JavaScriptCore/ChangeLog:3
> > +        Cleanup: inline constexpr is redundant as constexpr implies inline
> 
> Are you sure that this is true?  constexpr functions may be called on none
> const arguments, and therefore produce a non-constexpr value.  Marking a
> function constexpr only means that it *can* produce a constexpr value, not
> necessarily that it *will* produce a constexpr value.  Hence, I'm not sure
> that constexpr necessarily means the function will be inlined.  At least
> that's my understanding.  Am I wrong?

According to https://en.cppreference.com/w/cpp/language/constexpr:
> A constexpr specifier used in a function ... declaration implies inline.

So that's seems pretty unambiguous... But of course, we wouldn't want to touch any ALWAYS_INLINE cases.
Comment 7 Mark Lam 2018-10-25 14:44:21 PDT
Comment on attachment 353108 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=353108&action=review

r=me

>>> Source/JavaScriptCore/ChangeLog:3
>>> +        Cleanup: inline constexpr is redundant as constexpr implies inline
>> 
>> Are you sure that this is true?  constexpr functions may be called on none const arguments, and therefore produce a non-constexpr value.  Marking a function constexpr only means that it *can* produce a constexpr value, not necessarily that it *will* produce a constexpr value.  Hence, I'm not sure that constexpr necessarily means the function will be inlined.  At least that's my understanding.  Am I wrong?
> 
> According to https://en.cppreference.com/w/cpp/language/constexpr:

Excellent.
Comment 8 WebKit Commit Bot 2018-10-25 15:23:33 PDT
Comment on attachment 353108 [details]
Patch

Clearing flags on attachment: 353108

Committed r237429: <https://trac.webkit.org/changeset/237429>
Comment 9 WebKit Commit Bot 2018-10-25 15:23:35 PDT
All reviewed patches have been landed.  Closing bug.
Comment 10 Radar WebKit Bug Importer 2018-10-25 15:24:30 PDT
<rdar://problem/45569008>