Opened 15 years ago

Closed 5 years ago

#454 closed enhancement (fixed)

Move to noexcept

Reported by: Olly Betts Owned by: Olly Betts
Priority: normal Milestone: 1.5.0
Component: Build system Version: git master
Severity: normal Keywords:
Cc: Blocked By:
Blocking: Operating System: All

Description (last modified by Olly Betts)

Some compilers support extensions to allow functions and methods to be marked as not throwing exceptions. The compiler can potentially use this knowledge to optimise better.

This applies to both external and internal APIs. Marking up external APIs in this way is probably ABI compatible (provided of course that the function/method has never thrown exceptions in any previous ABI-compatible version of Xapian). So marking for 1.2.x.

Also we can probably use the same machinery to tell SWIG that exception handling isn't required for these methods, though I've not yet looked into that.

GCC 3.3 and later support:

int func() __attribute__((nothrow));

http://gcc.gnu.org/onlinedocs/gcc-4.3.2//gcc/Function-Attributes.html

MSVC apparently has:

int __declspec(nothrow) func();

These are a better approach than the standard C++ throw() specifier, because that requires the compiler to add a runtime check that the function really doesn't throw an exception (unless the compiler can prove that it can't, in which case the nothrow status can be inferred automatically anyway!)

Change History (8)

comment:1 by Olly Betts, 14 years ago

Description: modified (diff)

Clarify ambiguity in description.

comment:2 by Olly Betts, 13 years ago

Milestone: 1.2.x1.3.x

comment:3 by Olly Betts, 13 years ago

C++11 adds noexcept(true) as a standard way to support this:

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2010/n3050.html

comment:4 by Olly Betts, 12 years ago

Added XAPIAN_NOTHROW and used it to mark up some obvious cases in the public API in r16632, updated the bindings to ignore it in r16633, and used it to avoid generated exception handling for such functions/methods in r16634.

Still to do:

  • check for any more cases in the API
  • use internally

comment:5 by Olly Betts, 9 years ago

Milestone: 1.3.x1.4.x

I marked more cases in the public API in a few commits which are in 1.3.3, plus some methods in Query::Internal. I think everything in the public API which could be marked now is.

There are probably more internal functions and methods which could be marked, but there's no reason to block 1.4.0 for that.

comment:6 by Olly Betts, 5 years ago

Milestone: 1.4.x1.5.0
Status: newassigned
Summary: Mark up methods as "nothrow"Move to noexcept(true)
Version: SVN trunkgit master

We now require a C++11 compiler for the API headers too so we should probably drop XAPIAN_NOTHROW and XAPIAN_NOEXCEPT and just use noexcept(true) instead.

The awkward part is we currently rely on crudely parsing XAPIAN_NOTHROW to avoid exception wrapping methods which can't throw, but perhaps we can get SWIG to do that for us automatically.

comment:7 by Olly Betts, 5 years ago

Summary: Move to noexcept(true)Move to noexcept

Actually, just noexcept works and is shorter and clearer than noexcept(true).

comment:8 by Olly Betts, 5 years ago

Resolution: fixed
Status: assignedclosed

Moved to noexcept in 3cc4ef58834b0defc2d4ffb71fa4f10d375afc11 for git master. Not suitable for 1.4.x as we don't assume a C++11 compiler for code using Xapian there.

There might still be more places we could use noexcept internally, but I don't think we need to keep a ticket open for that.

Note: See TracTickets for help on using tickets.