bug-gnulib@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
* _Noreturn.h not respecting __STDC_VERSION__ (macOS, clang 10)
@ 2021-01-09  4:31 Joe Nelson
  2021-01-09 22:21 ` Paul Eggert
  0 siblings, 1 reply; 3+ messages in thread
From: Joe Nelson @ 2021-01-09  4:31 UTC (permalink / raw)
  To: bug-gnulib

Hi, my project uses lib/_Noreturn.h, but gets a warning when compiled
with "-std=c99 -pedantic":

	warning: _Noreturn functions are a C11-specific feature

By placing an #error directive in the code below during testing, I
confirmed the preprocessor is incorrectly hitting the condition marked
/* _Noreturn works as-is.  */

	#ifndef _Noreturn
	# if (defined __cplusplus \
		  && ((201103 <= __cplusplus && !(__GNUC__ == 4 && __GNUC_MINOR__ == 7)) \
			  || (defined _MSC_VER && 1900 <= _MSC_VER)) \
		  && 0)
		/* [[noreturn]] is not practically usable, because with it the syntax
			 extern _Noreturn void func (...);
		   would not be valid; such a declaration would only be valid with 'extern'
		   and '_Noreturn' swapped, or without the 'extern' keyword.  However, some
		   AIX system header files and several gnulib header files use precisely
		   this syntax with 'extern'.  */
	#  define _Noreturn [[noreturn]]
	# elif ((!defined __cplusplus || defined __clang__)                     \
			&& (201112 <= (defined __STDC_VERSION__ ? __STDC_VERSION__ : 0)  \
				|| 4 < __GNUC__ + (7 <= __GNUC_MINOR__) \
				|| (defined __apple_build_version__ \
					? 6000000 <= __apple_build_version__ \
					: 3 < __clang_major__ + (5 <= __clang_minor__))))
	   /* _Noreturn works as-is.  */
	# elif 2 < __GNUC__ + (8 <= __GNUC_MINOR__) || 0x5110 <= __SUNPRO_C
	#  define _Noreturn __attribute__ ((__noreturn__))
	# elif 1200 <= (defined _MSC_VER ? _MSC_VER : 0)
	#  define _Noreturn __declspec (noreturn)
	# else
	#  define _Noreturn
	# endif
	#endif

The correct behavior would be to respect the value of __STDC_VERSION__
which I set with the -std=c99 compiler flag.

Here are the values of the relevant macros in my environment:

#define __GNUC__ 4
#define __GNUC_MINOR__ 2
#define __STDC_VERSION__ 199901L
#define __apple_build_version__ 10001145
#define __clang_major__ 10
#define __clang_minor__ 0

Here is my compiler version:
	Apple LLVM version 10.0.0 (clang-1000.11.45.5)
	Target: x86_64-apple-darwin17.7.0

Also tested that on my system it would be OK to define _Noreturn to be
"__attribute__ ((__noreturn__))".  That option causes no warnings.

Thanks for your help. Hope there's a way to simplify/fix the logic in
the header.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-01-10  4:23 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-09  4:31 _Noreturn.h not respecting __STDC_VERSION__ (macOS, clang 10) Joe Nelson
2021-01-09 22:21 ` Paul Eggert
2021-01-10  4:23   ` Joe Nelson

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).