Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
Howard Hinnant | 5b08a8a | 2010-05-11 21:36:01 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4 | // |
Howard Hinnant | 412dbeb | 2010-11-16 22:09:02 +0000 | [diff] [blame^] | 5 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 6 | // Source Licenses. See LICENSE.TXT for details. |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | // test invalid_argument |
| 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::logic_error, std::invalid_argument>::value), |
| 21 | "std::is_base_of<std::logic_error, std::invalid_argument>::value"); |
| 22 | static_assert(std::is_polymorphic<std::invalid_argument>::value, |
| 23 | "std::is_polymorphic<std::invalid_argument>::value"); |
| 24 | { |
| 25 | const char* msg = "invalid_argument message"; |
| 26 | std::invalid_argument e(msg); |
| 27 | assert(std::strcmp(e.what(), msg) == 0); |
| 28 | std::invalid_argument 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 invalid_argument message"); |
| 35 | std::invalid_argument e(msg); |
| 36 | assert(e.what() == msg); |
| 37 | std::invalid_argument e2(e); |
| 38 | assert(e2.what() == msg); |
| 39 | e2 = e; |
| 40 | assert(e2.what() == msg); |
| 41 | } |
| 42 | } |