xref: /llvm-project/libcxx/test/std/diagnostics/std.exceptions/overflow.error/overflow_error.pass.cpp (revision 57b08b0944046a6a57ee9b7b479181f548a5b9b4)
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 // test overflow_error
10 
11 #include <stdexcept>
12 #include <type_traits>
13 #include <cstring>
14 #include <string>
15 #include <cassert>
16 
17 int main()
18 {
19     static_assert((std::is_base_of<std::runtime_error, std::overflow_error>::value),
20                  "std::is_base_of<std::runtime_error, std::overflow_error>::value");
21     static_assert(std::is_polymorphic<std::overflow_error>::value,
22                  "std::is_polymorphic<std::overflow_error>::value");
23     {
24     const char* msg = "overflow_error message";
25     std::overflow_error e(msg);
26     assert(std::strcmp(e.what(), msg) == 0);
27     std::overflow_error e2(e);
28     assert(std::strcmp(e2.what(), msg) == 0);
29     e2 = e;
30     assert(std::strcmp(e2.what(), msg) == 0);
31     }
32     {
33     std::string msg("another overflow_error message");
34     std::overflow_error e(msg);
35     assert(e.what() == msg);
36     std::overflow_error e2(e);
37     assert(e2.what() == msg);
38     e2 = e;
39     assert(e2.what() == msg);
40     }
41 }
42