PR c++/65051
[official-gcc.git] / gcc / testsuite / g++.dg / ext / pr57735.C
blob0eb95006dda418e961c820e737ee135ceb2084b7
1 /* { dg-do compile { target arm*-*-* } } */
2 /* { dg-options "-march=armv5te -marm  -mtune=xscale -mfloat-abi=soft -O1" } */
4 typedef unsigned int size_t;
5 __extension__
6 typedef long long int int64_t;
7 namespace WTF {
8     template<typename T> class RefPtr {
9     public:
10         inline T* operator->() const { return m_ptr; }
11         T* m_ptr;
12     };
14 using WTF::RefPtr;
15 namespace JSC {
16     class ExecState;
17     class JSString;
18     typedef int64_t EncodedJSValue;
19     class JSValue {
20     public:
21         static EncodedJSValue encode(JSValue);
22         JSString* toString(ExecState*) const;
23     };
25 typedef unsigned char LChar;
26     typedef short unsigned int UChar;
27 namespace WTF {
28     template<typename T, size_t inlineCapacity = 0>
29     class Vector {
30     public:
31         template<typename U> bool tryAppend(const U*, size_t);
32     };
34 using WTF::Vector;
35 namespace WTF {
36 template<typename CharType> inline bool isASCIIDigit(CharType c)
39 template<typename CharType> inline bool isASCIIHexDigit(CharType c)
41     return isASCIIDigit(c) || ((c | 0x20) >= 'a' && (c | 0x20) <= 'f');
43     class StringImpl;
45 using WTF::StringImpl;
46 namespace WTF {
47 class StringImpl {
48 public:
49     unsigned length() const { return m_length; }
50     unsigned m_length;
53 namespace JSC {
54     class Register {
55     };
56 class UString {
57 public:
58     unsigned length() const
59     {
60         return m_impl->length();
61     }
62     const LChar* characters8() const
63     {
64     }
65     RefPtr<StringImpl> m_impl;
67     class ExecState : private Register {
68     public:
69         JSValue argument(size_t argument)
70         {
71         }
72     };
73     class JSCell {
74     };
75     class JSString : public JSCell {
76     public:
77         const UString& value(ExecState*) const;
78     };
79 class JSStringBuilder {
80 public:
81     void append(const UChar u)
82     {
83         m_okay &= buffer16.tryAppend(&u, 1);
84     }
85     Vector<UChar, 64> buffer16;
86     bool m_okay;
88 template <typename T>
89 class Lexer {
90 public:
91     static unsigned char convertHex(int c1, int c2);
94 namespace WTF {
95 namespace Unicode {
96     int UTF8SequenceLength(char);
97     int decodeUTF8Sequence(const char*);
100 using namespace WTF;
101 using namespace Unicode;
102 namespace JSC {
103 template <typename CharType>
104 static JSValue decode(ExecState* exec, const CharType* characters, int length, const char* doNotUnescape, bool strict)
106     JSStringBuilder builder;
107     int k = 0;
108     UChar u = 0;
109     while (k < length) {
110         const CharType* p = characters + k;
111         CharType c = *p;
112         if (c == '%') {
113             int charLen = 0;
114             if (k <= length - 3 && isASCIIHexDigit(p[1]) && isASCIIHexDigit(p[2])) {
115                 const char b0 = Lexer<CharType>::convertHex(p[1], p[2]);
116                 const int sequenceLen = UTF8SequenceLength(b0);
117                 if (sequenceLen && k <= length - sequenceLen * 3) {
118                     charLen = sequenceLen * 3;
119                     char sequence[5];
120                     if (charLen != 0) {
121                         const int character = decodeUTF8Sequence(sequence);
122                         if (character < 0 || character >= 0x110000)
123                             charLen = 0;
124                         else if (character >= 0x10000) {
125                             builder.append(static_cast<UChar>(0xD800 | ((character - 0x10000) >> 10)));
126                         } else
127                             u = static_cast<UChar>(character);
128                     }
129                 }
130             }
131         }
132     }
134 static JSValue decode(ExecState* exec, const char* doNotUnescape, bool strict)
136     UString str = exec->argument(0).toString(exec)->value(exec);
137         return decode(exec, str.characters8(), str.length(), doNotUnescape, strict);
139 EncodedJSValue globalFuncDecodeURI(ExecState* exec)
141     static const char do_not_unescape_when_decoding_URI[] =
142         "#$&+,/:;=?@";
143     return JSValue::encode(decode(exec, do_not_unescape_when_decoding_URI, true));