[Development] Proposal: adding Q_DECL_NOEXCEPT to many methods

marius.storm-olsen at nokia.com marius.storm-olsen at nokia.com
Thu Aug 2 21:25:31 CEST 2012


On 02/08/2012 12:55, ext Thiago Macieira wrote:
> On quinta-feira, 2 de agosto de 2012 17.32.36,
> marius.storm-olsen at nokia.com wrote:
>> "the compiler can eliminate the mechanics of tracking the lifetime
>> of certain unwindable objects in such a function, and significantly
>> reduce the code size".
>
> That's in the caller.
>
> The problem is in the callee. The function that got the throw()
> decoration gets more code to verify that it is not leaking any
> exceptions.

That doesn't make any sense, and certainly not in release builds, that 
you in a function marked as not going to throw an exception generate 
code to _really_ make sure you don't? And if that was the case, you 
certainly wouldn't proclaim that it "significantly reduces the code 
size", since you would increase the size of every callee marked as 
noexcept, only to save a little bit in the caller function.

Looking at the assembly produced with or without throw() didn't show any 
size difference in the function calls, and they certainly didn't grow in 
size compared to those without throw().

In fact, I couldn't seem to get any effect out of throw() with MSVC2012, 
no matter what type of build I did (debug/release, /EH[acs]+), so 
perhaps 2012 RC is bad on this still. Might try this with one of the 
older compilers later.

Anyways, I see that LLVM/libc++ 
(http://llvm.org/svn/llvm-project/libcxx/trunk/include/__config) defines 
it like this:
   #if (__has_feature(cxx_noexcept))
   #  define _NOEXCEPT noexcept
   #  define _NOEXCEPT_(x) noexcept(x)
   #else
   #  define _NOEXCEPT throw()
   #  define _NOEXCEPT_(x)
   #endif
so, they do what I suggested, except they use 'noexcept' instead of 
'noexcept(true)'. (Shouldn't really matter, just that the latter is more 
clear, IMO.)

-- 
.marius


More information about the Development mailing list