]> git.ozlabs.org Git - ccan/commitdiff
compiler: NORETURN
authorRusty Russell <rusty@rustcorp.com.au>
Tue, 4 Jan 2011 10:42:41 +0000 (21:12 +1030)
committerRusty Russell <rusty@rustcorp.com.au>
Tue, 4 Jan 2011 10:42:41 +0000 (21:12 +1030)
ccan/compiler/compiler.h
config.h
tools/configurator/configurator.c

index d57d814b3711213c978602cd46c7c6e2e67ccf7d..1e0d8efbaacc1be66aa291f861560a513b69887a 100644 (file)
 #define COLD
 #endif
 
+#if HAVE_ATTRIBUTE_NORETURN
+/**
+ * NORETURN - a function does not return
+ *
+ * Used to mark a function which exits; useful for suppressing warnings.
+ *
+ * Example:
+ * static void NORETURN fail(const char *reason)
+ * {
+ *     fprintf(stderr, "Error: %s (%s)\n", reason, strerror(errno));
+ *     exit(1);
+ * }
+ */
+#define NORETURN __attribute__((noreturn))
+#else
+#define NORETURN
+#endif
+
 #if HAVE_ATTRIBUTE_PRINTF
 /**
  * PRINTF_FMT - a function takes printf-style arguments
index 7ef5d3baf622ec104a27f8814f2613ed5d8cb0b0..0473fb1f5220ac72a9d7a471ef46ff8ade7d481c 100644 (file)
--- a/config.h
+++ b/config.h
@@ -6,6 +6,7 @@
 #define HAVE_ATTRIBUTE_COLD 1
 #define HAVE_ATTRIBUTE_CONST 1
 #define HAVE_ATTRIBUTE_MAY_ALIAS 1
+#define HAVE_ATTRIBUTE_NORETURN 1
 #define HAVE_ATTRIBUTE_PRINTF 1
 #define HAVE_ATTRIBUTE_UNUSED 1
 #define HAVE_ATTRIBUTE_USED 1
index 4445139c90fcfabd01989956e1e60cd8cc958e36..7d9db8a1b407928810f3195b8f1a63d4bd82a366 100644 (file)
@@ -44,6 +44,9 @@ static struct test tests[] = {
          "static int __attribute__((const)) func(int x) { return x; }" },
        { "HAVE_ATTRIBUTE_MAY_ALIAS", OUTSIDE_MAIN, NULL,
          "typedef short __attribute__((__may_alias__)) short_a;" },
+       { "HAVE_ATTRIBUTE_NORETURN", DEFINES_FUNC, NULL,
+         "#include <stdlib.h>\n"
+         "static void __attribute__((noreturn)) func(int x) { exit(x); }" },
        { "HAVE_ATTRIBUTE_PRINTF", DEFINES_FUNC, NULL,
          "static void __attribute__((format(__printf__, 1, 2))) func(const char *fmt, ...) { }" },
        { "HAVE_ATTRIBUTE_UNUSED", OUTSIDE_MAIN, NULL,