File: | conftest.cpp |
Warning: | line 195, column 15 Value stored to 'utf8' during its initialization is never read |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | /* confdefs.h */ |
2 | #define PACKAGE_NAME"hfstospell" "hfstospell" |
3 | #define PACKAGE_TARNAME"hfstospell" "hfstospell" |
4 | #define PACKAGE_VERSION"0.5.4" "0.5.4" |
5 | #define PACKAGE_STRING"hfstospell 0.5.4" "hfstospell 0.5.4" |
6 | #define PACKAGE_BUGREPORT"hfst-bugs@helsinki.fi" "hfst-bugs@helsinki.fi" |
7 | #define PACKAGE_URL"http://hfst.github.io" "http://hfst.github.io" |
8 | #define PACKAGE"hfstospell" "hfstospell" |
9 | #define VERSION"0.5.4" "0.5.4" |
10 | #define ZHFST_EXTRACT_TO_MEM1 1 |
11 | /* end confdefs.h. */ |
12 | |
13 | // Does the compiler advertise C++98 conformance? |
14 | #if !defined __cplusplus201703L || __cplusplus201703L < 199711L |
15 | # error "Compiler does not advertise C++98 conformance" |
16 | #endif |
17 | |
18 | // These inclusions are to reject old compilers that |
19 | // lack the unsuffixed header files. |
20 | #include <cstdlib> |
21 | #include <exception> |
22 | |
23 | // <cassert> and <cstring> are *not* freestanding headers in C++98. |
24 | extern void assert (int); |
25 | namespace std { |
26 | extern int strcmp (const char *, const char *); |
27 | } |
28 | |
29 | // Namespaces, exceptions, and templates were all added after "C++ 2.0". |
30 | using std::exception; |
31 | using std::strcmp; |
32 | |
33 | namespace { |
34 | |
35 | void test_exception_syntax() |
36 | { |
37 | try { |
38 | throw "test"; |
39 | } catch (const char *s) { |
40 | // Extra parentheses suppress a warning when building autoconf itself, |
41 | // due to lint rules shared with more typical C programs. |
42 | assert (!(strcmp) (s, "test")); |
43 | } |
44 | } |
45 | |
46 | template <typename T> struct test_template |
47 | { |
48 | T const val; |
49 | explicit test_template(T t) : val(t) {} |
50 | template <typename U> T add(U u) { return static_cast<T>(u) + val; } |
51 | }; |
52 | |
53 | } // anonymous namespace |
54 | |
55 | |
56 | // Does the compiler advertise C++ 2011 conformance? |
57 | #if !defined __cplusplus201703L || __cplusplus201703L < 201103L |
58 | # error "Compiler does not advertise C++11 conformance" |
59 | #endif |
60 | |
61 | namespace cxx11test |
62 | { |
63 | constexpr int get_val() { return 20; } |
64 | |
65 | struct testinit |
66 | { |
67 | int i; |
68 | double d; |
69 | }; |
70 | |
71 | class delegate |
72 | { |
73 | public: |
74 | delegate(int n) : n(n) {} |
75 | delegate(): delegate(2354) {} |
76 | |
77 | virtual int getval() { return this->n; }; |
78 | protected: |
79 | int n; |
80 | }; |
81 | |
82 | class overridden : public delegate |
83 | { |
84 | public: |
85 | overridden(int n): delegate(n) {} |
86 | virtual int getval() override final { return this->n * 2; } |
87 | }; |
88 | |
89 | class nocopy |
90 | { |
91 | public: |
92 | nocopy(int i): i(i) {} |
93 | nocopy() = default; |
94 | nocopy(const nocopy&) = delete; |
95 | nocopy & operator=(const nocopy&) = delete; |
96 | private: |
97 | int i; |
98 | }; |
99 | |
100 | // for testing lambda expressions |
101 | template <typename Ret, typename Fn> Ret eval(Fn f, Ret v) |
102 | { |
103 | return f(v); |
104 | } |
105 | |
106 | // for testing variadic templates and trailing return types |
107 | template <typename V> auto sum(V first) -> V |
108 | { |
109 | return first; |
110 | } |
111 | template <typename V, typename... Args> auto sum(V first, Args... rest) -> V |
112 | { |
113 | return first + sum(rest...); |
114 | } |
115 | } |
116 | |
117 | |
118 | int |
119 | main (int argc, char **argv) |
120 | { |
121 | int ok = 0; |
122 | |
123 | assert (argc); |
124 | assert (! argv[0]); |
125 | { |
126 | test_exception_syntax (); |
127 | test_template<double> tt (2.0); |
128 | assert (tt.add (4) == 6.0); |
129 | assert (true && !false); |
130 | } |
131 | |
132 | |
133 | { |
134 | // Test auto and decltype |
135 | auto a1 = 6538; |
136 | auto a2 = 48573953.4; |
137 | auto a3 = "String literal"; |
138 | |
139 | int total = 0; |
140 | for (auto i = a3; *i; ++i) { total += *i; } |
141 | |
142 | decltype(a2) a4 = 34895.034; |
143 | } |
144 | { |
145 | // Test constexpr |
146 | short sa[cxx11test::get_val()] = { 0 }; |
147 | } |
148 | { |
149 | // Test initializer lists |
150 | cxx11test::testinit il = { 4323, 435234.23544 }; |
151 | } |
152 | { |
153 | // Test range-based for |
154 | int array[] = {9, 7, 13, 15, 4, 18, 12, 10, 5, 3, |
155 | 14, 19, 17, 8, 6, 20, 16, 2, 11, 1}; |
156 | for (auto &x : array) { x += 23; } |
157 | } |
158 | { |
159 | // Test lambda expressions |
160 | using cxx11test::eval; |
161 | assert (eval ([](int x) { return x*2; }, 21) == 42); |
162 | double d = 2.0; |
163 | assert (eval ([&](double x) { return d += x; }, 3.0) == 5.0); |
164 | assert (d == 5.0); |
165 | assert (eval ([=](double x) mutable { return d += x; }, 4.0) == 9.0); |
166 | assert (d == 5.0); |
167 | } |
168 | { |
169 | // Test use of variadic templates |
170 | using cxx11test::sum; |
171 | auto a = sum(1); |
172 | auto b = sum(1, 2); |
173 | auto c = sum(1.0, 2.0, 3.0); |
174 | } |
175 | { |
176 | // Test constructor delegation |
177 | cxx11test::delegate d1; |
178 | cxx11test::delegate d2(); |
179 | cxx11test::delegate d3(45); |
180 | } |
181 | { |
182 | // Test override and final |
183 | cxx11test::overridden o1(55464); |
184 | } |
185 | { |
186 | // Test nullptr |
187 | char *c = nullptr; |
188 | } |
189 | { |
190 | // Test template brackets |
191 | test_template<::test_template<int>> v(test_template<int>(12)); |
192 | } |
193 | { |
194 | // Unicode literals |
195 | char const *utf8 = u8"UTF-8 string \u2500"; |
Value stored to 'utf8' during its initialization is never read | |
196 | char16_t const *utf16 = u"UTF-8 string \u2500"; |
197 | char32_t const *utf32 = U"UTF-32 string \u2500"; |
198 | } |
199 | |
200 | return ok; |
201 | } |
202 |