xref: /netbsd-src/tests/usr.bin/xlint/lint1/lex_char.c (revision 183f84fe872ccaa5d671b1ae9610c95e0e166fae)
1 /*	$NetBSD: lex_char.c,v 1.9 2024/02/02 19:07:58 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
test(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 	sink('\e');
31 
32 	/* expect+1: warning: dubious escape \y [79] */
33 	sink('\y');
34 
35 	/* since C99 */
36 	sink('\x12');
37 
38 	/* octal */
39 	sink('\177');
40 
41 	/* expect+1: error: empty character constant [73] */
42 	sink('');
43 
44 	/* U+0007 alarm/bell */
45 	sink('\a');
46 
47 	/* U+0008 backspace */
48 	sink('\b');
49 
50 	/* U+0009 horizontal tabulation */
51 	sink('\t');
52 
53 	/* U+000A line feed */
54 	sink('\n');
55 
56 	/* U+000B vertical tabulation */
57 	sink('\v');
58 
59 	/* U+000C form feed */
60 	sink('\f');
61 
62 	/* U+000D carriage return */
63 	sink('\r');
64 
65 	/* A double quote may be escaped or not, since C90. */
66 	sink('"');
67 	sink('\"');
68 
69 	/* A question mark may be escaped or not, since C90. */
70 	sink('?');
71 	sink('\?');
72 
73 	sink('\\');
74 
75 	sink('\'');
76 }
77 
78 /*
79  * The sequence backslash-newline is handled in an early stage of
80  * translation (C90 5.1.1.2 item 2, C99 5.1.1.2 item 2, C11 5.1.1.2 item 2),
81  * which allows it in character literals as well.  This doesn't typically
82  * occur in practice though.
83  */
84 char ch = '\
85 \
86 \
87 \
88 \
89 x';
90