Index: include/contract =================================================================== --- include/contract +++ include/contract @@ -0,0 +1,67 @@ +// -*- C++ -*- +//===------------------------------ contract ------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_CONTRACT +#define _LIBCPP_CONTRACT + +/* + contract synopsis + +namespace std { + class contract_violation { + public: + uint_least32_t line_number() const noexcept; + string_view file_name() const noexcept; + string_view function_name() const noexcept; + string_view comment() const noexcept; + string_view assertion_level() const noexcept; + }; +} +*/ + +#include <__config> +#include +#include + +#ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +#if _LIBCPP_STD_VER > 17 + +class _LIBCPP_TYPE_VIS contract_violation { +public: + _LIBCPP_INLINE_VISIBILITY uint_least32_t line_number() const noexcept { return __line_number; } + _LIBCPP_INLINE_VISIBILITY string_view file_name() const noexcept { return __file_name; } + _LIBCPP_INLINE_VISIBILITY string_view function_name() const noexcept { return __function_name; } + _LIBCPP_INLINE_VISIBILITY string_view comment() const noexcept { return __comment; } + _LIBCPP_INLINE_VISIBILITY string_view assertion_level() const noexcept { return __assertion_level; } + +private: + _LIBCPP_INLINE_VISIBILITY + constexpr contract_violation(uint_least32_t __line, string_view __file, string_view __fn, + string_view __comment, string_view __lvl) noexcept + : __line_number(__line), __file_name(__file), __function_name(__fn), + __comment(__comment), __assertion_level(__lvl) {} + + uint_least32_t __line_number; + string_view __file_name; + string_view __function_name; + string_view __comment; + string_view __assertion_level; +}; + +#endif // _LIBCPP_STD_VER > 17 + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_CONTRACT Index: include/module.modulemap =================================================================== --- include/module.modulemap +++ include/module.modulemap @@ -255,6 +255,10 @@ header "condition_variable" export * } + module contract { + header "contract" + export * + } module deque { header "deque" export initializer_list Index: test/libcxx/double_include.sh.cpp =================================================================== --- test/libcxx/double_include.sh.cpp +++ test/libcxx/double_include.sh.cpp @@ -45,6 +45,7 @@ #include #include #include +#include #include #include #include Index: test/libcxx/language.support/support.contract/version.pass.cpp =================================================================== --- test/libcxx/language.support/support.contract/version.pass.cpp +++ test/libcxx/language.support/support.contract/version.pass.cpp @@ -0,0 +1,22 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// + +#include + +#ifndef _LIBCPP_VERSION +#error _LIBCPP_VERSION not defined +#endif + +int main() +{ +} Index: test/std/language.support/support.contract/contract_violation.pass.cpp =================================================================== --- test/std/language.support/support.contract/contract_violation.pass.cpp +++ test/std/language.support/support.contract/contract_violation.pass.cpp @@ -0,0 +1,44 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03, c++11, c++14, c++17 + +// +// class contract_violation + +#include +#include +#include +#include +#include + +using CV = std::contract_violation; + +// Check for noexcept. +static_assert(noexcept(std::declval().line_number())); +static_assert(noexcept(std::declval().file_name())); +static_assert(noexcept(std::declval().function_name())); +static_assert(noexcept(std::declval().comment())); +static_assert(noexcept(std::declval().assertion_level())); + +// Check return types. +static_assert(std::is_same_v().line_number()), + std::uint_least32_t>); +static_assert(std::is_same_v().file_name()), + std::string_view>); +static_assert(std::is_same_v().function_name()), + std::string_view>); +static_assert(std::is_same_v().comment()), + std::string_view>); +static_assert(std::is_same_v().assertion_level()), + std::string_view>); + +int main() +{ +}