On Wed, Jan 17, 2018 at 02:17:22PM -0800, Nicol Bolas wrote:
> On Wednesday, January 17, 2018 at 4:36:00 PM UTC-5, Magnus Fromreide wrote:
> >
> > On Wed, Jan 17, 2018 at 10:47:09AM -0800, Flávio Lisbôa wrote:
> > > I searched in the forums but could not find a similar proposal. Instead,
> > I found
> > > a discussion
> > > <
> >
https://groups.google.com/a/isocpp.org/forum/#!topic/std-proposals/r1pWsCgV550>
> >
> > > that may be related, but I'm not sure if my proposal completely fulfills
> > > the author's needs.
> > >
> > > [[always_inline]] is a hint that would substitute
> > > __attribute__((always_inline)), __forceinline and similar
> > compiler-specific
> > > hints. The intention is for it to be semantically different from C++'s
> > > inline (e.g. as a mechanism for ODR realization) and be more on par with
> > > the compiler-dependent attributes it substitutes and C99's inline (e.g.
> > try
> > > to inline the function call to avoid stack growth).
> >
> > One of the points of always_inline is that the compiler ain't allowed to
> > ignore
> > it. As such it can't be an attribute.
> >
>
> If the compiler doesn't implement the concept of `always_inline`, then I
> don't see the problem. That is, if the compiler has no compiler-specific
> inlining attribute, then it shouldn't be a surprise that [[always_inline]]
> won't inline it either.
But an always_inline attribute that fails to always inline is obviously
misnamed.
> What we want is a cross-platform way to say what we can already say.
I agree that this would be a good thing, but there seem to be some disagreement
regarding what it is we want to say here.
> People
> who genuinely need forced inlining use compilers that support forced
> inlining. If some compiler can't do it, they simply won't use that compiler.
So, you are telling me that I should use some magic at other places to detect
if [[always_inline]] actually do inline at all times as opposed to the
current state where I have to do some compiler-specific trickery.
I would then claim that
#ifdef __GNUC__
#define ALWAYS_INLINE __attribute__((always_inline))
#else
#error "No ALWAYS_INLINE on this compiler"
#endif
is better than the proposed
[[always_inline]]
since the former gives a hard error when the compiler ain't supporting it
while the latter is mandated to be silently ignored.
If I want to send the compiler a hint that some function should be inlined then
the language already provides that via the "inline" keyword so this proposed
[[always_inline]] will just provide a strength of the inlining hint,
Now, that is also a resonable idea but then it should be an attribute on the
inline keyword since that is what it affects:
inline [[inline_harder]] void fun() { /* */ }
but the name "always_inline" should not be used unlees you have the GCC
semantics of it beeing an error to fail to inline the function and in that
case it can't be an attribute.
I think one could express this in standardeese like this:
* The "always_inline" keyword ensures that the function declared so have no
linkage.
This is similar to how "static" ensures no external linkage or how "inline"
allows vague linkage.
> This is a QOI issue. Let compilers handle it as they see fit.
I'd rather se no standardization here than a standardization of a broken
concept.
/MF