Jump to content

nothrow attribute w/ gcc


daniel.santos
 Share

Recommended Posts

../../../source/lib/allocators/headerless.cpp:757: error: attributes are not allowed on a function-definition

My understanding of __attribute__ (nothrow) is that it is an optimization feature to prevent the compiler from generating unwind code. I would recommend consulting an expert on this, but I believe the c++ throw() clause will accomplish the same thing (as in MSVC) and you can (and actually, must) stick it on both the declaration and the definition, whereas gcc only accepts the attribute on the definition.

See http://gcc.gnu.org/o...Attributes.html for the vague details. :)

--- lib/code_annotation.h   	(revision 10384)
+++ lib/code_annotation.h (working copy)
@@ -63,7 +63,8 @@
* smaller and more efficient code.
**/
#if GCC_VERSION >= 303
-# define NOTHROW __attribute__((nothrow))
+//# define NOTHROW __attribute__((nothrow))
+# define NOTHROW throw() // special meaning, equivalent to __declspec(nothrow)
#elif MSC_VERSION
# define NOTHROW throw() // special meaning, equivalent to __declspec(nothrow)
#else

Alternately, you can make a separate macros for the declaration & definition.

Edited by daniel.santos
Link to comment
Share on other sites

Thanks for the report! I was not aware about the restriction on definitions and still haven't found any mention of it.

The closest is http://www.mail-archive.com/commits@stdcxx.apache.org/msg00960.html, which also use the separate DEFINE/DECLARE approach. It's ugly, but preferable to possible pessimization via throw(), so I'll go with that approach.

Am about to commit a fix; sorry about the breakage.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...