Clang Project

clang_source_code/test/Lexer/unicode.c
1// RUN: %clang_cc1 -fsyntax-only -verify -x c -std=c11 %s
2// RUN: %clang_cc1 -fsyntax-only -verify -x c++ -std=c++11 %s
3// RUN: %clang_cc1 -E -DPP_ONLY=1 %s -o %t
4// RUN: FileCheck --strict-whitespace --input-file=%t %s
5
6// This file contains Unicode characters; please do not "fix" them!
7
8extern int x; // expected-warning {{treating Unicode character as whitespace}}
9extern int x; // expected-warning {{treating Unicode character as whitespace}}
10
11// CHECK: extern int {{x}}
12// CHECK: extern int {{x}}
13
14#pragma mark ¡Unicode!
15
16#define COPYRIGHT Copyright © 2012
17#define XSTR(X) #X
18#define STR(X) XSTR(X)
19
20static const char *copyright = STR(COPYRIGHT); // no-warning
21// CHECK: static const char *copyright = "Copyright © {{2012}}";
22
23#if PP_ONLY
24COPYRIGHT
25// CHECK: Copyright © {{2012}}
26CHECK: The preprocessor should not complain about Unicode characters like ©.
27#endif
28
29// A 🌹 by any other name....
30extern int 🌹;
31int 🌵(int 🌻) { return 🌻+ 1; }
32int main () {
33  int 🌷 = 🌵(🌹);
34  return 🌷;
35}
36
37int n; = 3; // expected-warning {{treating Unicode character <U+037E> as identifier character rather than as ';' symbol}}
38int *n꞉꞉v = &n;; // expected-warning 2{{treating Unicode character <U+A789> as identifier character rather than as ':' symbol}}
39                 // expected-warning@-1 {{treating Unicode character <U+037E> as identifier character rather than as ';' symbol}}
40int v=[=](auto){return~x;}(); // expected-warning 12{{treating Unicode character}}
41
42int ⁠xx‍;
43// expected-warning@-1 {{identifier contains Unicode character <U+2060> that is invisible in some environments}}
44// expected-warning@-2 {{identifier contains Unicode character <U+FEFF> that is invisible in some environments}}
45// expected-warning@-3 {{identifier contains Unicode character <U+200D> that is invisible in some environments}}
46int foo​bar = 0; // expected-warning {{identifier contains Unicode character <U+200B> that is invisible in some environments}}
47int x = foobar; // expected-error {{undeclared identifier}}
48
49int ∣foo; // expected-error {{non-ASCII character}}
50#ifndef PP_ONLY
51#define ∶ x // expected-error {{macro name must be an identifier}}
52#endif
53