Skip to content

Commit

Permalink
Make stdexcept usable internally
Browse files Browse the repository at this point in the history
  • Loading branch information
miscco committed Jul 10, 2023
1 parent f72e8b0 commit 6dade2e
Showing 1 changed file with 63 additions and 65 deletions.
128 changes: 63 additions & 65 deletions libcudacxx/include/cuda/std/detail/libcxx/include/stdexcept
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
// -*- C++ -*-
//===--------------------------- stdexcept --------------------------------===//
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// Part of libcu++, the C++ Standard Library for your entire system,
// under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES.
//
//===----------------------------------------------------------------------===//

Expand Down Expand Up @@ -46,8 +48,8 @@ public:
#endif //__cuda_std__

#include "__assert" // all public C++ headers provide the assertion handler
#include "cstdlib"
#include "exception"
#include "__exception/exception.h"
#include "__verbose_abort"
#include "iosfwd"

#ifndef __cuda_std__
Expand All @@ -68,23 +70,17 @@ class _LIBCUDACXX_HIDDEN __libcpp_refstring
_LIBCUDACXX_HOST_DEVICE bool __uses_refcount() const;
public:
_LIBCUDACXX_HOST_DEVICE explicit __libcpp_refstring(const char* __msg);
_LIBCUDACXX_HOST_DEVICE __libcpp_refstring(const __libcpp_refstring& __s) _NOEXCEPT;
_LIBCUDACXX_HOST_DEVICE __libcpp_refstring& operator=(const __libcpp_refstring& __s) _NOEXCEPT;
_LIBCUDACXX_HOST_DEVICE __libcpp_refstring(const __libcpp_refstring& __s) noexcept;
_LIBCUDACXX_HOST_DEVICE __libcpp_refstring& operator=(const __libcpp_refstring& __s) noexcept;
_LIBCUDACXX_HOST_DEVICE ~__libcpp_refstring();

_LIBCUDACXX_HOST_DEVICE const char* c_str() const _NOEXCEPT {return __imp_;}
_LIBCUDACXX_HOST_DEVICE _LIBCUDACXX_HIDE_FROM_ABI const char* c_str() const noexcept {return __imp_;}
};
#endif // !_LIBCUDACXX_ABI_VCRUNTIME

_LIBCUDACXX_END_NAMESPACE_STD

#ifndef __cuda_std__
#ifdef _LIBCUDACXX_BEGIN_NAMESPACE_STD_NOVERSION
_LIBCUDACXX_BEGIN_NAMESPACE_STD_NOVERSION
#else
namespace std // purposefully not versioned
{
#endif //_LIBCUDACXX_BEGIN_NAMESPACE_STD_NOVERSION

class _LIBCUDACXX_EXCEPTION_ABI logic_error
: public exception
Expand All @@ -93,20 +89,20 @@ class _LIBCUDACXX_EXCEPTION_ABI logic_error
private:
_CUDA_VSTD::__libcpp_refstring __imp_;
public:
explicit logic_error(const string&);
explicit logic_error(const char*);
_LIBCUDACXX_HOST_DEVICE explicit logic_error(const string&);
_LIBCUDACXX_HOST_DEVICE explicit logic_error(const char*);

logic_error(const logic_error&) _NOEXCEPT;
logic_error& operator=(const logic_error&) _NOEXCEPT;
_LIBCUDACXX_HOST_DEVICE logic_error(const logic_error&) noexcept;
_LIBCUDACXX_HOST_DEVICE logic_error& operator=(const logic_error&) noexcept;

virtual ~logic_error() _NOEXCEPT;
_LIBCUDACXX_HOST_DEVICE virtual ~logic_error() noexcept;

virtual const char* what() const _NOEXCEPT;
#else
_LIBCUDACXX_HOST_DEVICE virtual const char* what() const noexcept;
#else // ^^^ !_LIBCUDACXX_ABI_VCRUNTIME ^^^ / vvv _LIBCUDACXX_ABI_VCRUNTIME vvv
public:
explicit logic_error(const _CUDA_VSTD::string&); // Symbol uses versioned std::string
_LIBCUDACXX_HOST_DEVICE explicit logic_error(const _CUDA_VSTD::string&); // Symbol uses versioned std::string
_LIBCUDACXX_INLINE_VISIBILITY explicit logic_error(const char* __s) : exception(__s) {}
#endif
#endif // _LIBCUDACXX_ABI_VCRUNTIME
};

class _LIBCUDACXX_EXCEPTION_ABI runtime_error
Expand All @@ -116,18 +112,18 @@ class _LIBCUDACXX_EXCEPTION_ABI runtime_error
private:
_CUDA_VSTD::__libcpp_refstring __imp_;
public:
explicit runtime_error(const string&);
explicit runtime_error(const char*);
_LIBCUDACXX_HOST_DEVICE explicit runtime_error(const string&);
_LIBCUDACXX_HOST_DEVICE explicit runtime_error(const char*);

runtime_error(const runtime_error&) _NOEXCEPT;
runtime_error& operator=(const runtime_error&) _NOEXCEPT;
_LIBCUDACXX_HOST_DEVICE runtime_error(const runtime_error&) noexcept;
_LIBCUDACXX_HOST_DEVICE runtime_error& operator=(const runtime_error&) noexcept;

virtual ~runtime_error() _NOEXCEPT;
_LIBCUDACXX_HOST_DEVICE virtual ~runtime_error() noexcept;

virtual const char* what() const _NOEXCEPT;
#else
_LIBCUDACXX_HOST_DEVICE virtual const char* what() const noexcept;
#else // ^^^ !_LIBCUDACXX_ABI_VCRUNTIME ^^^ / vvv _LIBCUDACXX_ABI_VCRUNTIME vvv
public:
explicit runtime_error(const _CUDA_VSTD::string&); // Symbol uses versioned std::string
_LIBCUDACXX_HOST_DEVICE explicit runtime_error(const _CUDA_VSTD::string&); // Symbol uses versioned std::string
_LIBCUDACXX_INLINE_VISIBILITY explicit runtime_error(const char* __s) : exception(__s) {}
#endif // _LIBCUDACXX_ABI_VCRUNTIME
};
Expand All @@ -140,8 +136,9 @@ public:
_LIBCUDACXX_INLINE_VISIBILITY explicit domain_error(const char* __s) : logic_error(__s) {}

#ifndef _LIBCUDACXX_ABI_VCRUNTIME
virtual ~domain_error() _NOEXCEPT;
#endif
_LIBCUDACXX_HIDE_FROM_ABI domain_error(const domain_error&) noexcept = default;
_LIBCUDACXX_HOST_DEVICE virtual ~domain_error() noexcept;
#endif // _LIBCUDACXX_ABI_VCRUNTIME
};

class _LIBCUDACXX_EXCEPTION_ABI invalid_argument
Expand All @@ -152,8 +149,9 @@ public:
_LIBCUDACXX_INLINE_VISIBILITY explicit invalid_argument(const char* __s) : logic_error(__s) {}

#ifndef _LIBCUDACXX_ABI_VCRUNTIME
virtual ~invalid_argument() _NOEXCEPT;
#endif
_LIBCUDACXX_HIDE_FROM_ABI invalid_argument(const invalid_argument&) noexcept = default;
_LIBCUDACXX_HOST_DEVICE virtual ~invalid_argument() noexcept;
#endif // _LIBCUDACXX_ABI_VCRUNTIME
};

class _LIBCUDACXX_EXCEPTION_ABI length_error
Expand All @@ -163,8 +161,9 @@ public:
_LIBCUDACXX_INLINE_VISIBILITY explicit length_error(const string& __s) : logic_error(__s) {}
_LIBCUDACXX_INLINE_VISIBILITY explicit length_error(const char* __s) : logic_error(__s) {}
#ifndef _LIBCUDACXX_ABI_VCRUNTIME
virtual ~length_error() _NOEXCEPT;
#endif
_LIBCUDACXX_HIDE_FROM_ABI length_error(const length_error&) noexcept = default;
_LIBCUDACXX_HOST_DEVICE virtual ~length_error() noexcept;
#endif // _LIBCUDACXX_ABI_VCRUNTIME
};

class _LIBCUDACXX_EXCEPTION_ABI out_of_range
Expand All @@ -175,8 +174,9 @@ public:
_LIBCUDACXX_INLINE_VISIBILITY explicit out_of_range(const char* __s) : logic_error(__s) {}

#ifndef _LIBCUDACXX_ABI_VCRUNTIME
virtual ~out_of_range() _NOEXCEPT;
#endif
_LIBCUDACXX_HIDE_FROM_ABI out_of_range(const out_of_range&) noexcept = default;
_LIBCUDACXX_HOST_DEVICE virtual ~out_of_range() noexcept;
#endif // _LIBCUDACXX_ABI_VCRUNTIME
};

class _LIBCUDACXX_EXCEPTION_ABI range_error
Expand All @@ -187,8 +187,9 @@ public:
_LIBCUDACXX_INLINE_VISIBILITY explicit range_error(const char* __s) : runtime_error(__s) {}

#ifndef _LIBCUDACXX_ABI_VCRUNTIME
virtual ~range_error() _NOEXCEPT;
#endif
_LIBCUDACXX_HIDE_FROM_ABI range_error(const range_error&) noexcept = default;
_LIBCUDACXX_HOST_DEVICE virtual ~range_error() noexcept;
#endif // _LIBCUDACXX_ABI_VCRUNTIME
};

class _LIBCUDACXX_EXCEPTION_ABI overflow_error
Expand All @@ -199,8 +200,9 @@ public:
_LIBCUDACXX_INLINE_VISIBILITY explicit overflow_error(const char* __s) : runtime_error(__s) {}

#ifndef _LIBCUDACXX_ABI_VCRUNTIME
virtual ~overflow_error() _NOEXCEPT;
#endif
_LIBCUDACXX_HIDE_FROM_ABI overflow_error(const overflow_error&) noexcept = default;
_LIBCUDACXX_HOST_DEVICE virtual ~overflow_error() noexcept;
#endif // _LIBCUDACXX_ABI_VCRUNTIME
};

class _LIBCUDACXX_EXCEPTION_ABI underflow_error
Expand All @@ -211,16 +213,12 @@ public:
_LIBCUDACXX_INLINE_VISIBILITY explicit underflow_error(const char* __s) : runtime_error(__s) {}

#ifndef _LIBCUDACXX_ABI_VCRUNTIME
virtual ~underflow_error() _NOEXCEPT;
#endif
_LIBCUDACXX_HIDE_FROM_ABI underflow_error(const underflow_error&) noexcept = default;
_LIBCUDACXX_HOST_DEVICE virtual ~underflow_error() noexcept;
#endif // _LIBCUDACXX_ABI_VCRUNTIME
};

#ifdef _LIBCUDACXX_END_NAMESPACE_STD_NOVERSION
_LIBCUDACXX_END_NAMESPACE_STD_NOVERSION
#else
}
#endif //_LIBCUDACXX_END_NAMESPACE_STD_NOVERSION
#endif //__cuda_std__

_LIBCUDACXX_BEGIN_NAMESPACE_STD

Expand All @@ -232,87 +230,87 @@ void __throw_logic_error(const char*__msg)
{
#ifndef _LIBCUDACXX_NO_EXCEPTIONS
throw logic_error(__msg);
#else
#else // ^^^ !_LIBCUDACXX_NO_EXCEPTIONS ^^^ / vvv _LIBCUDACXX_NO_EXCEPTIONS vvv
((void)__msg);
_LIBCUDACXX_UNREACHABLE();
#endif
#endif // _LIBCUDACXX_NO_EXCEPTIONS
}

_LIBCUDACXX_NORETURN inline _LIBCUDACXX_INLINE_VISIBILITY
void __throw_domain_error(const char*__msg)
{
#ifndef _LIBCUDACXX_NO_EXCEPTIONS
throw domain_error(__msg);
#else
#else // ^^^ !_LIBCUDACXX_NO_EXCEPTIONS ^^^ / vvv _LIBCUDACXX_NO_EXCEPTIONS vvv
((void)__msg);
_LIBCUDACXX_UNREACHABLE();
#endif
#endif // _LIBCUDACXX_NO_EXCEPTIONS
}

_LIBCUDACXX_NORETURN inline _LIBCUDACXX_INLINE_VISIBILITY
void __throw_invalid_argument(const char*__msg)
{
#ifndef _LIBCUDACXX_NO_EXCEPTIONS
throw invalid_argument(__msg);
#else
#else // ^^^ !_LIBCUDACXX_NO_EXCEPTIONS ^^^ / vvv _LIBCUDACXX_NO_EXCEPTIONS vvv
((void)__msg);
_LIBCUDACXX_UNREACHABLE();
#endif
#endif // _LIBCUDACXX_NO_EXCEPTIONS
}

_LIBCUDACXX_NORETURN inline _LIBCUDACXX_INLINE_VISIBILITY
void __throw_length_error(const char*__msg)
{
#ifndef _LIBCUDACXX_NO_EXCEPTIONS
throw length_error(__msg);
#else
#else // ^^^ !_LIBCUDACXX_NO_EXCEPTIONS ^^^ / vvv _LIBCUDACXX_NO_EXCEPTIONS vvv
((void)__msg);
_LIBCUDACXX_UNREACHABLE();
#endif
#endif // _LIBCUDACXX_NO_EXCEPTIONS
}

_LIBCUDACXX_NORETURN inline _LIBCUDACXX_INLINE_VISIBILITY
void __throw_out_of_range(const char*__msg)
{
#ifndef _LIBCUDACXX_NO_EXCEPTIONS
throw out_of_range(__msg);
#else
#else // ^^^ !_LIBCUDACXX_NO_EXCEPTIONS ^^^ / vvv _LIBCUDACXX_NO_EXCEPTIONS vvv
((void)__msg);
_LIBCUDACXX_UNREACHABLE();
#endif
#endif // _LIBCUDACXX_NO_EXCEPTIONS
}

_LIBCUDACXX_NORETURN inline _LIBCUDACXX_INLINE_VISIBILITY
void __throw_range_error(const char*__msg)
{
#ifndef _LIBCUDACXX_NO_EXCEPTIONS
throw range_error(__msg);
#else
#else // ^^^ !_LIBCUDACXX_NO_EXCEPTIONS ^^^ / vvv _LIBCUDACXX_NO_EXCEPTIONS vvv
((void)__msg);
_LIBCUDACXX_UNREACHABLE();
#endif
#endif // _LIBCUDACXX_NO_EXCEPTIONS
}

_LIBCUDACXX_NORETURN inline _LIBCUDACXX_INLINE_VISIBILITY
void __throw_overflow_error(const char*__msg)
{
#ifndef _LIBCUDACXX_NO_EXCEPTIONS
throw overflow_error(__msg);
#else
#else // ^^^ !_LIBCUDACXX_NO_EXCEPTIONS ^^^ / vvv _LIBCUDACXX_NO_EXCEPTIONS vvv
((void)__msg);
_LIBCUDACXX_UNREACHABLE();
#endif
#endif // _LIBCUDACXX_NO_EXCEPTIONS
}

_LIBCUDACXX_NORETURN inline _LIBCUDACXX_INLINE_VISIBILITY
void __throw_underflow_error(const char*__msg)
{
#ifndef _LIBCUDACXX_NO_EXCEPTIONS
throw underflow_error(__msg);
#else
#else // ^^^ !_LIBCUDACXX_NO_EXCEPTIONS ^^^ / vvv _LIBCUDACXX_NO_EXCEPTIONS vvv
((void)__msg);
_LIBCUDACXX_UNREACHABLE();
#endif
#endif // _LIBCUDACXX_NO_EXCEPTIONS
}

_LIBCUDACXX_END_NAMESPACE_STD
Expand Down

0 comments on commit 6dade2e

Please sign in to comment.