Home | History | Annotate | Line # | Download | only in lint1
c23.c revision 1.6
      1 /*	$NetBSD: c23.c,v 1.6 2023/07/25 16:56: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 //	msg_353.c		for empty initializer braces
      9 
     10 /* lint1-flags: -Ac23 -w -X 351 */
     11 
     12 int
     13 empty_initializer_braces(void)
     14 {
     15 	struct s {
     16 		int member;
     17 	} s;
     18 
     19 	// Empty initializer braces were introduced in C23.
     20 	s = (struct s){};
     21 	s = (struct s){s.member};
     22 	return s.member;
     23 }
     24 
     25 // The keyword 'thread_local' was introduced in C23.
     26 thread_local int globally_visible;
     27 
     28 // Thread-local functions don't make sense; lint allows them, though.
     29 thread_local void
     30 thread_local_function(void)
     31 {
     32 }
     33 
     34 void
     35 function(void)
     36 {
     37 	// Not sure whether it makes sense to have a function-scoped
     38 	// thread-local variable.  Don't warn for now, let the compilers handle
     39 	// this case.
     40 	thread_local int function_scoped_thread_local;
     41 }
     42 
     43 // 'thread_local' can be combined with 'extern' and 'static', but with no other
     44 // storage classes.  The other storage classes cannot be combined.
     45 extern thread_local int extern_thread_local_1;
     46 thread_local extern int extern_thread_local_2;
     47 static thread_local int static_thread_local_1;
     48 thread_local static int static_thread_local_2;
     49 /* expect-2: warning: static variable 'static_thread_local_1' unused [226] */
     50 /* expect-2: warning: static variable 'static_thread_local_2' unused [226] */
     51