summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2020-08-09 14:51:56 +0200
committerBruno Haible <bruno@clisp.org>2020-08-09 14:51:56 +0200
commit94e462dba2d39c73858d855d528f2d86253de498 (patch)
tree9c50b3d0f820a99e0d0acbc2b5e05fe42b469764 /lib
parent90cc47f28487c90cecfb312c808a0710dcfbf114 (diff)
downloadgnulib-94e462dba2d39c73858d855d528f2d86253de498.tar.gz
Add ability to emit user-defined warnings and errors with clang.
* m4/gnulib-common.m4 (gl_COMMON_BODY): Define _GL_ATTRIBUTE_ERROR, _GL_ATTRIBUTE_WARNING using an attribute for clang. * lib/warn-on-use.h (_GL_WARN_ON_USE, _GL_WARN_ON_USE_ATTRIBUTE, _GL_WARN_ON_USE_CXX): Define using an attribute for clang. * lib/cdefs.h (__warndecl, __warnattr, __errordecl): Define using an attribute for clang.
Diffstat (limited to 'lib')
-rw-r--r--lib/cdefs.h6
-rw-r--r--lib/warn-on-use.h15
2 files changed, 20 insertions, 1 deletions
diff --git a/lib/cdefs.h b/lib/cdefs.h
index b034c0bdfd..801753c7f3 100644
--- a/lib/cdefs.h
+++ b/lib/cdefs.h
@@ -129,6 +129,12 @@
# define __warnattr(msg) __attribute__((__warning__ (msg)))
# define __errordecl(name, msg) \
extern void name (void) __attribute__((__error__ (msg)))
+#elif __clang_major__ >= 4
+# define __warndecl(name, msg) \
+ extern void name (void) __attribute__((__diagnose_if__ (1, msg, "warning")))
+# define __warnattr(msg) __attribute__((__diagnose_if__ (1, msg, "warning")))
+# define __errordecl(name, msg) \
+ extern void name (void) __attribute__((__diagnose_if__ (1, msg, "error")))
#else
# define __warndecl(name, msg) extern void name (void)
# define __warnattr(msg)
diff --git a/lib/warn-on-use.h b/lib/warn-on-use.h
index 291e7091b8..a39e3a394c 100644
--- a/lib/warn-on-use.h
+++ b/lib/warn-on-use.h
@@ -87,6 +87,13 @@
extern __typeof__ (function) function __attribute__ ((__warning__ (message)))
# define _GL_WARN_ON_USE_ATTRIBUTE(message) \
__attribute__ ((__warning__ (message)))
+# elif __clang_major__ >= 4
+/* Another compiler attribute is available in clang. */
+# define _GL_WARN_ON_USE(function, message) \
+extern __typeof__ (function) function \
+ __attribute__ ((__diagnose_if__ (1, message, "warning")))
+# define _GL_WARN_ON_USE_ATTRIBUTE(message) \
+ __attribute__ ((__diagnose_if__ (1, message, "warning")))
# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
/* Verify the existence of the function. */
# define _GL_WARN_ON_USE(function, message) \
@@ -111,9 +118,15 @@ _GL_WARN_EXTERN_C int _gl_warn_on_use
_GL_WARN_ON_USE (function, msg)
# else
# if 4 < __GNUC__ || (__GNUC__ == 4 && 3 <= __GNUC_MINOR__)
+/* A compiler attribute is available in gcc versions 4.3.0 and later. */
+# define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
+extern rettype function parameters_and_attributes \
+ __attribute__ ((__warning__ (msg)))
+# elif __clang_major__ >= 4
+/* Another compiler attribute is available in clang. */
# define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
extern rettype function parameters_and_attributes \
- __attribute__ ((__warning__ (msg)))
+ __attribute__ ((__diagnose_if__ (1, msg, "warning")))
# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
/* Verify the existence of the function. */
# define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \