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