bug-gnulib@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
* [PATCH] verify: improve diagnostic quality in recent GCC
@ 2019-08-12 21:58 Paul Eggert
  0 siblings, 0 replies; only message in thread
From: Paul Eggert @ 2019-08-12 21:58 UTC (permalink / raw)
  To: bug-gnulib; +Cc: Paul Eggert

If ‘verify’ fails in a deeply-nested macro, GCC does not output a
useful line number containing the top-level caller of the macro.
So, bring back the older way of issuing a diagnostic containing
the top-level call’s arg, so that it is easier to diagnose
‘verify’ failures with recent GCC.
* lib/verify.h (_GL_VERIFY_TRUE, _GL_VERIFY_TYPE):
Bring back DIAGNOSTIC arg.  All callers changed.
(verify): Just use _GL_VERIFY.
---
 ChangeLog    | 12 ++++++++++++
 lib/verify.h | 33 +++++++++++++++++++--------------
 2 files changed, 31 insertions(+), 14 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 8928bb230..7e4276548 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2019-08-12  Paul Eggert  <eggert@cs.ucla.edu>
+
+	verify: improve diagnostic quality in recent GCC
+	If ‘verify’ fails in a deeply-nested macro, GCC does not output a
+	useful line number containing the top-level caller of the macro.
+	So, bring back the older way of issuing a diagnostic containing
+	the top-level call’s arg, so that it is easier to diagnose
+	‘verify’ failures with recent GCC.
+	* lib/verify.h (_GL_VERIFY_TRUE, _GL_VERIFY_TYPE):
+	Bring back DIAGNOSTIC arg.  All callers changed.
+	(verify): Just use _GL_VERIFY.
+
 2019-08-11  Bruno Haible  <bruno@clisp.org>
 
 	localcharset: Add more aliases for OS/2.
diff --git a/lib/verify.h b/lib/verify.h
index 9b8e1ed20..afdc1ad81 100644
--- a/lib/verify.h
+++ b/lib/verify.h
@@ -175,9 +175,11 @@
 #define _GL_GENSYM(prefix) _GL_CONCAT (prefix, _GL_COUNTER)
 
 /* Verify requirement R at compile-time, as an integer constant expression
-   that returns 1.  If R is false, fail at compile-time.  */
+   that returns 1.  If R is false, fail at compile-time, preferably
+   with a diagnostic that includes the string-literal DIAGNOSTIC.  */
 
-#define _GL_VERIFY_TRUE(R) (!!sizeof (_GL_VERIFY_TYPE (R)))
+#define _GL_VERIFY_TRUE(R, DIAGNOSTIC) \
+   (!!sizeof (_GL_VERIFY_TYPE (R, DIAGNOSTIC)))
 
 #ifdef __cplusplus
 # if !GNULIB_defined_struct__gl_verify_type
@@ -187,15 +189,16 @@ template <int w>
   };
 #  define GNULIB_defined_struct__gl_verify_type 1
 # endif
-# define _GL_VERIFY_TYPE(R) _gl_verify_type<(R) ? 1 : -1>
-#elif defined _GL_HAVE__STATIC_ASSERT1
-# define _GL_VERIFY_TYPE(R) \
+# define _GL_VERIFY_TYPE(R, DIAGNOSTIC) \
+    _gl_verify_type<(R) ? 1 : -1>
+#elif defined _GL_HAVE__STATIC_ASSERT
+# define _GL_VERIFY_TYPE(R, DIAGNOSTIC) \
     struct {                                   \
-      _Static_assert (R); \
+      _Static_assert (R, DIAGNOSTIC);          \
       int _gl_dummy;                          \
     }
 #else
-# define _GL_VERIFY_TYPE(R)                                             \
+# define _GL_VERIFY_TYPE(R, DIAGNOSTIC) \
     struct { unsigned int _gl_verify_error_if_negative: (R) ? 1 : -1; }
 #endif
 
@@ -214,7 +217,7 @@ template <int w>
 #else
 # define _GL_VERIFY(R, DIAGNOSTIC, ...)                                \
     extern int (*_GL_GENSYM (_gl_verify_function) (void))	       \
-      [_GL_VERIFY_TRUE (R)]
+      [_GL_VERIFY_TRUE (R, DIAGNOSTIC)]
 #endif
 
 /* _GL_STATIC_ASSERT_H is defined if this code is copied into assert.h.  */
@@ -242,17 +245,19 @@ template <int w>
 /* Verify requirement R at compile-time.  Return the value of the
    expression E.  */
 
-#define verify_expr(R, E) (_GL_VERIFY_TRUE (R) ? (E) : (E))
+#define verify_expr(R, E) \
+   (_GL_VERIFY_TRUE (R, "verify_expr (" #R ", " #E ")") ? (E) : (E))
 
 /* Verify requirement R at compile-time, as a declaration without a
    trailing ';'.  verify (R) acts like static_assert (R) except that
-   it is portable to C11/C++14 and earlier, and its name is shorter
-   and may be more convenient.  */
+   it is portable to C11/C++14 and earlier, it can issue better
+   diagnostics, and its name is shorter and may be more convenient.  */
 
-#ifdef _GL_HAVE__STATIC_ASSERT1
-# define verify(R) _Static_assert (R)
-#else
+#ifdef __PGI
+/* PGI barfs if R is long.  */
 # define verify(R) _GL_VERIFY (R, "verify (...)", -)
+#else
+# define verify(R) _GL_VERIFY (R, "verify (" #R ")", -)
 #endif
 
 #ifndef __has_builtin
-- 
2.21.0



^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2019-08-12 21:58 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-12 21:58 [PATCH] verify: improve diagnostic quality in recent GCC Paul Eggert

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).