Debian Codegraph @

gcc/testsuite/g++.dg/torture/pr64669.C

raw
1 // { dg-additional-options "-Wno-return-type" }
2
3 typedef unsigned int source_location;
4 typedef source_location location_t;
5 extern void error_at (location_t, const char *, ...)
6 __attribute__ ((__format__ (__gcc_tdiag__, 2, 3)))
7 __attribute__ ((__nonnull__ (2)));
8
9 class Lex
10 {
11 static int fetch_char (const char *str, unsigned int *value);
12 location_t location () const;
13 const char *advance_one_utf8_char (const char *, unsigned int *, bool *);
14 const char *advance_one_char (const char *, bool, unsigned int *, bool *);
15 int lineoff_;
16 int lineno_;
17 };
18
19 int
20 Lex::fetch_char (const char *p, unsigned int *value)
21 {
22 unsigned char c = *p;
23 if (c <= 0x7f)
24 {
25 return 1;
26 }
27 else if ((c & 0xe0) == 0xc0 && (p[1] & 0xc0) == 0x80)
28 {
29 *value = (((c & 0x1f) << 6) + (p[1] & 0x3f));
30 }
31 {
32 *value = (((c & 0xf) << 12) + (p[2] & 0x3f));
33 }
34 }
35
36 const char *
37 Lex::advance_one_utf8_char (const char *p, unsigned int *value,
38 bool * issued_error)
39 {
40 *issued_error = false;
41 if (*p == '\0')
42 {
43 *issued_error = true;
44 return p + 1;
45 }
46 int adv = Lex::fetch_char (p, value);
47 if (*value == 0xfeff && (this->lineno_ != 1 || this->lineoff_ != 0))
48 {
49 *issued_error = true;
50 }
51 return p + adv;
52 }
53
54 const char *
55 Lex::advance_one_char (const char *p, bool is_single_quote,
56 unsigned int *value, bool * is_character)
57 {
58 {
59 bool issued_error;
60 const char *ret = this->advance_one_utf8_char (p, value, &issued_error);
61 if (is_single_quote
62 && (*value == '\'' || *value == '\n') && !issued_error)
63 error_at (this->location (), "invalid character literal");
64 }
65
66 return 0;
67 }