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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...