xref: /netbsd-src/tests/usr.bin/xlint/lint1/lex_char.c (revision d16b7486a53dcb8072b60ec6fcb4373a2d0c27b7)
1 /*	$NetBSD: lex_char.c,v 1.7 2023/03/28 14:44:34 rillig Exp $	*/
2 # 3 "lex_char.c"
3 
4 /*
5  * Tests for lexical analysis of character constants.
6  *
7  * C99 6.4.4.4 "Character constants"
8  */
9 
10 /* lint1-extra-flags: -X 351 */
11 
12 void sink(char);
13 
14 void
15 test(void)
16 {
17 	/* expect+1: error: empty character constant [73] */
18 	sink('');
19 
20 	sink('a');
21 
22 	sink('\0');
23 
24 	/* UTF-8 */
25 	/* expect+2: warning: multi-character character constant [294] */
26 	/* expect+1: warning: conversion of 'int' to 'char' is out of range, arg #1 [295] */
27 	sink('ä');
28 
29 	/* GCC extension */
30 	/* expect+1: warning: dubious escape \e [79] */
31 	sink('\e');
32 
33 	/* since C99 */
34 	sink('\x12');
35 
36 	/* octal */
37 	sink('\177');
38 
39 	/* expect+1: error: empty character constant [73] */
40 	sink('');
41 
42 	/* U+0007 alarm/bell */
43 	sink('\a');
44 
45 	/* U+0008 backspace */
46 	sink('\b');
47 
48 	/* U+0009 horizontal tabulation */
49 	sink('\t');
50 
51 	/* U+000A line feed */
52 	sink('\n');
53 
54 	/* U+000B vertical tabulation */
55 	sink('\v');
56 
57 	/* U+000C form feed */
58 	sink('\f');
59 
60 	/* U+000D carriage return */
61 	sink('\r');
62 }
63 
64 /*
65  * The sequence backslash-newline is handled in an early stage of
66  * translation (C90 5.1.1.2 item 2, C99 5.1.1.2 item 2, C11 5.1.1.2 item 2),
67  * which allows it in character literals as well.  This doesn't typically
68  * occur in practice though.
69  */
70 char ch = '\
71 \
72 \
73 \
74 \
75 x';
76