diff mbox series

PR libstdc++/88740 Print assertion messages to stderr

Message ID 20190122160816.GA13862@redhat.com
State New
Headers show
Series PR libstdc++/88740 Print assertion messages to stderr | expand

Commit Message

Jonathan Wakely Jan. 22, 2019, 4:08 p.m. UTC
Messages printed to stdout might be lost when the process terminates
via abort(), because output streams aren't flushed. Write to stderr
instead (if stderr is defined by <stdio.h>).

	PR libstdc++/88740
	* testsuite/util/testsuite_hooks.h [stderr] (VERIFY): Use fprintf to
	write to stderr instead of using printf.

Tested x86_64-linux, committed to trunk.
commit d249af5ee2c32453b5df5bcb1a9c645993da0673
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Tue Jan 22 15:54:44 2019 +0000

    PR libstdc++/88740 Print assertion messages to stderr
    
            PR libstdc++/88740
            * testsuite/util/testsuite_hooks.h [stderr] (VERIFY): Use fprintf to
            write to stderr instead of using printf.
diff mbox series

Patch

diff --git a/libstdc++-v3/testsuite/util/testsuite_hooks.h b/libstdc++-v3/testsuite/util/testsuite_hooks.h
index 3999a5d6ee1..51c431bf9c0 100644
--- a/libstdc++-v3/testsuite/util/testsuite_hooks.h
+++ b/libstdc++-v3/testsuite/util/testsuite_hooks.h
@@ -46,18 +46,25 @@ 
 #include <bits/c++config.h>
 #include <bits/functexcept.h>
 #include <ctime>
+#include <stdio.h>
 
 #ifdef _GLIBCXX_HAVE_SYS_STAT_H
 #include <sys/stat.h>
 #endif
 
+#ifdef stderr
+# define _VERIFY_PRINT(S, F, L, P, C) __builtin_fprintf(stderr, S, F, L, P, C)
+#else
+# define _VERIFY_PRINT(S, F, L, P, C) __builtin_printf(S, F, L, P, C)
+#endif
+
 #define VERIFY(fn)                                                      \
   do                                                                    \
   {                                                                     \
     if (! (fn))								\
       {									\
-	__builtin_printf("%s:%d: %s: Assertion '%s' failed.\n",		\
-			 __FILE__, __LINE__, __PRETTY_FUNCTION__, #fn); \
+	_VERIFY_PRINT("%s:%d: %s: Assertion '%s' failed.\n",		\
+		      __FILE__, __LINE__, __PRETTY_FUNCTION__, #fn);	\
 	__builtin_abort();						\
       }									\
   } while (false)