+2002-05-27 Roger Sayle <roger@eyesopen.com>
+
+ * c-common.c: Add support for __attribute__((nothrow)) to specify
+ that a function cannot throw an exception (using TREE_NOTHROW).
+ (handle_nothrow_attribute): New function to process this attribute.
+
+ * doc/extend.texi: Document the new nothrow function attribute.
+
2002-05-27 H.J. Lu (hjl@gnu.org)
* cppexp.c (num_trim): Use 1UL instead of 1 for long int.
bool *));
static tree handle_nonnull_attribute PARAMS ((tree *, tree, tree, int,
bool *));
+static tree handle_nothrow_attribute PARAMS ((tree *, tree, tree, int,
+ bool *));
static tree vector_size_helper PARAMS ((tree, tree));
static void check_function_nonnull PARAMS ((tree, tree));
handle_visibility_attribute },
{ "nonnull", 0, -1, false, true, true,
handle_nonnull_attribute },
+ { "nothrow", 0, 0, true, false, false,
+ handle_nothrow_attribute },
{ NULL, 0, 0, false, false, false, NULL }
};
*valp = TREE_INT_CST_LOW (arg_num_expr);
return true;
}
+
+/* Handle a "nothrow" attribute; arguments as in
+ struct attribute_spec.handler. */
+
+static tree
+handle_nothrow_attribute (node, name, args, flags, no_add_attrs)
+ tree *node;
+ tree name;
+ tree args ATTRIBUTE_UNUSED;
+ int flags ATTRIBUTE_UNUSED;
+ bool *no_add_attrs;
+{
+ if (TREE_CODE (*node) == FUNCTION_DECL)
+ TREE_NOTHROW (*node) = 1;
+ /* ??? TODO: Support types. */
+ else
+ {
+ warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
+ *no_add_attrs = true;
+ }
+
+ return NULL_TREE;
+}
\f
/* Check for valid arguments being passed to a function. */
void
attribute specification inside double parentheses. The following
attributes are currently defined for functions on all targets:
@code{noreturn}, @code{noinline}, @code{always_inline},
-@code{pure}, @code{const},
+@code{pure}, @code{const}, @code{nothrow},
@code{format}, @code{format_arg}, @code{no_instrument_function},
@code{section}, @code{constructor}, @code{destructor}, @code{used},
@code{unused}, @code{deprecated}, @code{weak}, @code{malloc},
This approach does not work in GNU C++ from 2.6.0 on, since the language
specifies that the @samp{const} must be attached to the return value.
+@cindex @code{nothrow} function attribute
+@item nothrow
+The @code{nothrow} attribute is used to inform the compiler that a
+function cannot throw an exception. For example, most functions in
+the standard C library can be guaranteed not to throw an exception
+with the notable exceptions of @code{qsort} and @code{bsearch} that
+take function pointer arguments. The @code{nothrow} attribute is not
+implemented in GCC versions earlier than 3.2.
@item format (@var{archetype}, @var{string-index}, @var{first-to-check})
@cindex @code{format} function attribute
+2002-05-27 Richard Henderson <rth@redhat.com>
+
+ * g++.dg/ext/attrib6.C: New test case.
+
2002-05-27 Kaveh R. Ghazi <ghazi@caip.rutgers.edu>
* gcc.c-torture/execute/pure-1.c: New test.
--- /dev/null
+// Copyright (C) 2002 Free Software Foundation.
+//
+// Test that the nothrow attribute is working correctly.
+//
+// Written by Richard Henderson, 26 May 2002.
+
+// { dg-do link }
+extern void foo() __attribute__((nothrow));
+extern void link_error();
+
+int main()
+{
+ try {
+ foo();
+ } catch (...) {
+ link_error();
+ }
+}
+
+void foo() { }
+