Home | History | Annotate | Line # | Download | only in lint1
c23.c revision 1.9
      1 /*	$NetBSD: c23.c,v 1.9 2024/05/07 19:32:35 rillig Exp $	*/
      2 # 3 "c23.c"
      3 
      4 // Tests for the option -Ac23, which allows features from C23 and all earlier
      5 // ISO standards, but none of the GNU extensions.
      6 //
      7 // See also:
      8 //	c11.c
      9 //	msg_353.c		for empty initializer braces
     10 
     11 /* lint1-flags: -Ac23 -w -X 351 */
     12 
     13 
     14 int
     15 bool_is_predefined_in_c23(void)
     16 {
     17 	/* expect+1: error: syntax error 't' [249] */
     18 	bool t = true;
     19 	bool f = false;
     20 	/* expect+4: error: 't' undefined [99] */
     21 	/* expect+3: error: 'true' undefined [99] */
     22 	/* expect+2: error: 'f' undefined [99] */
     23 	/* expect+1: error: 'false' undefined [99] */
     24 	return (t == true ? 20 : 0) + (f == false ? 3 : 0);
     25 }
     26 
     27 int
     28 c99_bool_is_still_valid_in_c23(void)
     29 {
     30 	_Bool t = 1;
     31 	_Bool f = 0;
     32 	return (t == 1 ? 20 : 0) + (f == 0 ? 3 : 0);
     33 }
     34 
     35 
     36 int
     37 empty_initializer_braces(void)
     38 {
     39 	struct s {
     40 		int member;
     41 	} s;
     42 
     43 	// Empty initializer braces were introduced in C23.
     44 	s = (struct s){};
     45 	s = (struct s){s.member};
     46 	return s.member;
     47 }
     48 
     49 
     50 _Static_assert(1 > 0, "string");
     51 _Static_assert(1 > 0);
     52 
     53 
     54 // The keyword 'thread_local' was introduced in C23.
     55 thread_local int globally_visible;
     56 
     57 // Thread-local functions don't make sense; lint allows them, though.
     58 thread_local void
     59 thread_local_function(void)
     60 {
     61 }
     62 
     63 void
     64 function(void)
     65 {
     66 	// Not sure whether it makes sense to have a function-scoped
     67 	// thread-local variable.  Don't warn for now, let the compilers handle
     68 	// this case.
     69 	thread_local int function_scoped_thread_local;
     70 }
     71 
     72 // 'thread_local' can be combined with 'extern' and 'static', but with no other
     73 // storage classes.  The other storage classes cannot be combined.
     74 extern thread_local int extern_thread_local_1;
     75 thread_local extern int extern_thread_local_2;
     76 /* expect+1: warning: static variable 'static_thread_local_1' unused [226] */
     77 static thread_local int static_thread_local_1;
     78 /* expect+1: warning: static variable 'static_thread_local_2' unused [226] */
     79 thread_local static int static_thread_local_2;
     80