]> Savannah Git Hosting - gnulib.git/commitdiff
Add ability to emit user-defined warnings and errors with clang.
authorBruno Haible <bruno@clisp.org>
Sun, 9 Aug 2020 12:51:56 +0000 (14:51 +0200)
committerBruno Haible <bruno@clisp.org>
Sun, 9 Aug 2020 12:51:56 +0000 (14:51 +0200)
* 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.

ChangeLog
lib/cdefs.h
lib/warn-on-use.h
m4/gnulib-common.m4

index 18de16e5921359cf0c676ca9cabcad7a85ef6ac4..e1c48b21538c5bfc9ff32569f15fb025c01b0d01 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2020-08-09  Bruno Haible  <bruno@clisp.org>
+
+       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.
+
 2020-08-09  Bruno Haible  <bruno@clisp.org>
 
        intprops: Fix typo in comment.
index b034c0bdfd0d70d338df75d53be25bba68b00be8..801753c7f36309f83c59157c6624667196788bfe 100644 (file)
 # 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)
index 291e7091b887469fc681084fb1ac6a352cd480f1..a39e3a394c73da27ef6c2aeb4fd1f5ef0833b4ac 100644 (file)
 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) \
index 50acc0a474b582c8031de1d9c449434bcf7b9d88..e42b80cf61e561505dd327febdc7a7f9a0da3a44 100644 (file)
@@ -1,4 +1,4 @@
-# gnulib-common.m4 serial 53
+# gnulib-common.m4 serial 54
 dnl Copyright (C) 2007-2020 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -76,6 +76,7 @@ AC_DEFUN([gl_COMMON_BODY], [
 # define _GL_ATTR_cold _GL_GNUC_PREREQ (4, 3)
 # define _GL_ATTR_const _GL_GNUC_PREREQ (2, 95)
 # define _GL_ATTR_deprecated _GL_GNUC_PREREQ (3, 1)
+# define _GL_ATTR_diagnose_if 0
 # define _GL_ATTR_error _GL_GNUC_PREREQ (4, 3)
 # define _GL_ATTR_externally_visible _GL_GNUC_PREREQ (4, 1)
 # define _GL_ATTR_fallthrough _GL_GNUC_PREREQ (7, 0)
@@ -149,6 +150,9 @@ AC_DEFUN([gl_COMMON_BODY], [
 #if _GL_HAS_ATTRIBUTE (error)
 # define _GL_ATTRIBUTE_ERROR(msg) __attribute__ ((__error__ (msg)))
 # define _GL_ATTRIBUTE_WARNING(msg) __attribute__ ((__warning__ (msg)))
+#elif _GL_HAS_ATTRIBUTE (diagnose_if)
+# define _GL_ATTRIBUTE_ERROR(msg) __attribute__ ((__diagnose_if__ (1, msg, "error")))
+# define _GL_ATTRIBUTE_WARNING(msg) __attribute__ ((__diagnose_if__ (1, msg, "warning")))
 #else
 # define _GL_ATTRIBUTE_ERROR(msg)
 # define _GL_ATTRIBUTE_WARNING(msg)