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