Home | History | Annotate | Download | only in overflow.error
      1 //===----------------------------------------------------------------------===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is dual licensed under the MIT and the University of Illinois Open
      6 // Source Licenses. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 
     10 // test overflow_error
     11 
     12 #include <stdexcept>
     13 #include <type_traits>
     14 #include <cstring>
     15 #include <string>
     16 #include <cassert>
     17 
     18 int main()
     19 {
     20     static_assert((std::is_base_of<std::runtime_error, std::overflow_error>::value),
     21                  "std::is_base_of<std::runtime_error, std::overflow_error>::value");
     22     static_assert(std::is_polymorphic<std::overflow_error>::value,
     23                  "std::is_polymorphic<std::overflow_error>::value");
     24     {
     25     const char* msg = "overflow_error message";
     26     std::overflow_error e(msg);
     27     assert(std::strcmp(e.what(), msg) == 0);
     28     std::overflow_error e2(e);
     29     assert(std::strcmp(e2.what(), msg) == 0);
     30     e2 = e;
     31     assert(std::strcmp(e2.what(), msg) == 0);
     32     }
     33     {
     34     std::string msg("another overflow_error message");
     35     std::overflow_error e(msg);
     36     assert(e.what() == msg);
     37     std::overflow_error e2(e);
     38     assert(e2.what() == msg);
     39     e2 = e;
     40     assert(e2.what() == msg);
     41     }
     42 }
     43