Boost logo

Boost :

Subject: Re: [boost] [config] [chrono] consexpr workaround
From: Vicente J. Botet Escriba (vicente.botet_at_[hidden])
Date: 2013-03-19 14:23:06


Le 19/03/13 17:00, Krzysztof Czainski a écrit :
> 2013/3/19 John Maddock <boost.regex_at_[hidden]>
>
>> Hi,
>>> Could/should BOOST_CONSTEXPR expand to inline in C++03?
>>>
>>> If not, could a macro BOOST_CONSTEXPR_OR_INLINE be added?
>>>
>>> For one thing, constexpr functions are usually (but maybe not always?)
>>> good
>>> candidates for inlines. But also please consider the following example.
>>> Suppose we put the following code in a header file:
>>>
>>> struct X { BOOST_CONSTEXPR int fun() const; };
>>>
>>> BOOST_CONSTEXPR int X::fun() const { return 0; }
>>>
>>> Now if this file is included in multiple .cpp files, this will fail at
>>> link
>>> time in C++03 with message "multiple definition of `X::fun()", and it will
>>> link fine in C++11. But when BOOST_CONSTEXPR is inline in C++03, the above
>>> works.
>>>
>>> Would making BOOST_CONSTEXPR expand to inline in C++03 do any harm?
>>>
>> Yes, it would break lots of Boost.Multiprecision code that's declared [1]:
>>
>> inline BOOST_CONSTEXPR T foo();
>>
> Oh yeah, I didn't think about code, that already uses both BOOST_CONSTEXPR
> together with inline ;-)
>
> which begs the question why can't you do the same?
>> Particularly for templates where the constexpr-ness depends on the
>> template argument, this is exactly what you want anyway.
>>
> Right. So you pretty much answered my initial question, John ;-) Thanks.
>
> My initial reasoning was based on this: I analysed performance of some
> C++03 code, that uses Boost.Chrono. And I discovered, that a lot of trivial
> functions didn't get inlined. So now, narrowing the question to use of
> BOOST_CONSTEXPR in Boost.Chrono:
> 1. Could the functions marked BOOST_CONSTEXPR be also marked inline (and
> this question probably applies to other Boost libraries)?
> 2. This is probably related only to the TI compiler I use: marking
> constructors inline doesn't work for me, they need to be marked
> BOOST_FORCEINLINE (I've configured it), so could the constexpr constructors
> in Boost.Chrono be marked with BOOST_FORCEINLINE as well?
>
Hi,

could you point me to the cases that need to be inlined that the
compiler doesn't inline by itself?

Please create a ticket so that I don't forget it.

Best,
Vicente


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk