File: digraphs.c

package info (click to toggle)
llvm-toolchain-19 1%3A19.1.7-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,998,520 kB
  • sloc: cpp: 6,951,680; ansic: 1,486,157; asm: 913,598; python: 232,024; f90: 80,126; objc: 75,281; lisp: 37,276; pascal: 16,990; sh: 10,009; ml: 5,058; perl: 4,724; awk: 3,523; makefile: 3,167; javascript: 2,504; xml: 892; fortran: 664; cs: 573
file content (90 lines) | stat: -rw-r--r-- 2,250 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// RUN: %clang_cc1 -verify -ffreestanding %s

/* WG14 ???: yes
 * restricted character set support via digraphs and <iso646.h>
 *
 * NB: I cannot find a definitive document number associated with the feature,
 * which was pulled from the editor's report in the C99 front matter. However,
 * based on discussion in the C99 rationale document, I believe this is
 * referring to features added by AMD1 to support ISO 646 and digraphs.
 */

// Validate that we provide iso646.h in freestanding mode.
#include <iso646.h>

// Validate that we define all the expected macros and their expected
// expansions (when suitable for a constant expression) as well.
#ifndef and
#error "missing and"
#else
_Static_assert((1 and 1) == (1 && 1), "");
#endif

#ifndef and_eq
#error "missing and_eq"
#endif

#ifndef bitand
#error "missing bitand"
#else
_Static_assert((1 bitand 3) == (1 & 3), "");
#endif

#ifndef bitor
#error "missing bitor"
#else
_Static_assert((1 bitor 2) == (1 | 2), "");
#endif

#ifndef compl
#error "missing compl"
#else
_Static_assert((compl 0) == (~0), "");
#endif

#ifndef not
#error "missing not"
#else
_Static_assert((not 12) == (!12), "");
#endif

#ifndef not_eq
#error "missing not_eq"
#else
_Static_assert((0 not_eq 12) == (0 != 12), "");
#endif

#ifndef or
#error "missing or"
#else
// This intentionally diagnoses use of '||' only, because the user likely did
// not confuse the operator when using 'or' instead.
_Static_assert((0 or 12) == (0 || 12), ""); // expected-warning {{use of logical '||' with constant operand}} \
                                               expected-note {{use '|' for a bitwise operation}}
#endif

#ifndef or_eq
#error "missing or_eq"
#endif

#ifndef xor
#error "missing xor"
#else
_Static_assert((1 xor 3) == (1 ^ 3), "");
#endif

#ifndef xor_eq
#error "missing xor_eq"
#endif

// Validate that digraphs behave the same as their expected counterparts. The
// definition should match the declaration in every way except spelling.
#define DI_NAME(f, b) f %:%: b
#define STD_NAME(f, b) f ## b
void DI_NAME(foo, bar)(int (*array)<: 0 :>);
void STD_NAME(foo, bar)(int (*array)[0]) {}

#define DI_STR(f) %:f
#define STD_STR(f) #f
_Static_assert(__builtin_strcmp(DI_STR(testing), STD_STR(testing)) == 0, "");