blob: 5e06e521e40497a80e14fd6501bf73d7ded37c10 [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001//===------------------------ stdexcept.cpp -------------------------------===//
2//
Howard Hinnantf5256e12010-05-11 21:36:01 +00003// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004//
Howard Hinnantb64f8b02010-11-16 22:09:02 +00005// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00007//
8//===----------------------------------------------------------------------===//
9
10#include "stdexcept"
11#include "new"
12#include "string"
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000013#include "system_error"
Eric Fiselier12f2b262017-07-12 01:38:35 +000014#include "include/refstring.h"
Richard Smithc756f5b2012-04-19 01:36:12 +000015
Joerg Sonnenberger55622072014-04-30 19:54:11 +000016/* For _LIBCPPABI_VERSION */
Eric Fiseliercfc55152017-01-03 01:18:48 +000017#if !defined(_LIBCPP_BUILDING_HAS_NO_ABI_LIBRARY) && \
18 (defined(LIBCXX_BUILDING_LIBCXXABI) || defined(__APPLE__) || defined(LIBCXXRT))
Howard Hinnante1642e12012-02-17 19:24:42 +000019#include <cxxabi.h>
Richard Smithc756f5b2012-04-19 01:36:12 +000020#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000021
Joerg Sonnenberger55622072014-04-30 19:54:11 +000022static_assert(sizeof(std::__libcpp_refstring) == sizeof(const char *), "");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000023
Eric Fiselier6979a422016-10-25 19:33:14 +000024
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000025namespace std // purposefully not using versioning namespace
26{
27
Joerg Sonnenberger55622072014-04-30 19:54:11 +000028logic_error::logic_error(const string& msg) : __imp_(msg.c_str())
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000029{
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000030}
31
Joerg Sonnenberger55622072014-04-30 19:54:11 +000032logic_error::logic_error(const char* msg) : __imp_(msg)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000033{
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000034}
35
Joerg Sonnenberger55622072014-04-30 19:54:11 +000036logic_error::logic_error(const logic_error& le) _NOEXCEPT : __imp_(le.__imp_)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000037{
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000038}
39
40logic_error&
Howard Hinnant1e15fd12011-05-26 19:48:01 +000041logic_error::operator=(const logic_error& le) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000042{
Joerg Sonnenberger55622072014-04-30 19:54:11 +000043 __imp_ = le.__imp_;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000044 return *this;
45}
46
Peter Collingbourned0d308f2013-10-06 22:13:19 +000047#if !defined(_LIBCPPABI_VERSION) && !defined(LIBSTDCXX)
Howard Hinnante1642e12012-02-17 19:24:42 +000048
Howard Hinnant1e15fd12011-05-26 19:48:01 +000049logic_error::~logic_error() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000050{
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000051}
52
53const char*
Howard Hinnant1e15fd12011-05-26 19:48:01 +000054logic_error::what() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000055{
Joerg Sonnenberger55622072014-04-30 19:54:11 +000056 return __imp_.c_str();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000057}
58
Howard Hinnante1642e12012-02-17 19:24:42 +000059#endif
60
Joerg Sonnenberger55622072014-04-30 19:54:11 +000061runtime_error::runtime_error(const string& msg) : __imp_(msg.c_str())
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000062{
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000063}
64
Joerg Sonnenberger55622072014-04-30 19:54:11 +000065runtime_error::runtime_error(const char* msg) : __imp_(msg)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000066{
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000067}
68
Howard Hinnant1e15fd12011-05-26 19:48:01 +000069runtime_error::runtime_error(const runtime_error& le) _NOEXCEPT
Joerg Sonnenberger55622072014-04-30 19:54:11 +000070 : __imp_(le.__imp_)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000071{
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000072}
73
74runtime_error&
Howard Hinnant1e15fd12011-05-26 19:48:01 +000075runtime_error::operator=(const runtime_error& le) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000076{
Joerg Sonnenberger55622072014-04-30 19:54:11 +000077 __imp_ = le.__imp_;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000078 return *this;
79}
80
Peter Collingbourned0d308f2013-10-06 22:13:19 +000081#if !defined(_LIBCPPABI_VERSION) && !defined(LIBSTDCXX)
Howard Hinnante1642e12012-02-17 19:24:42 +000082
Howard Hinnant1e15fd12011-05-26 19:48:01 +000083runtime_error::~runtime_error() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000084{
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000085}
86
87const char*
Howard Hinnant1e15fd12011-05-26 19:48:01 +000088runtime_error::what() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000089{
Joerg Sonnenberger55622072014-04-30 19:54:11 +000090 return __imp_.c_str();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000091}
92
Howard Hinnant1e15fd12011-05-26 19:48:01 +000093domain_error::~domain_error() _NOEXCEPT {}
94invalid_argument::~invalid_argument() _NOEXCEPT {}
95length_error::~length_error() _NOEXCEPT {}
96out_of_range::~out_of_range() _NOEXCEPT {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000097
Howard Hinnant1e15fd12011-05-26 19:48:01 +000098range_error::~range_error() _NOEXCEPT {}
99overflow_error::~overflow_error() _NOEXCEPT {}
100underflow_error::~underflow_error() _NOEXCEPT {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000101
Howard Hinnante1642e12012-02-17 19:24:42 +0000102#endif
103
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000104} // std