hamzasood updated this revision to Diff 156857.
hamzasood added a comment.

- Made the suggested test changes.

The compiler is meant to create these; Clang doesn't do this yet but I'm 
working on the implementation.

I was under the impression that the compiler support would require the library 
stuff to land first, but I just checked Clang's coroutine tests and it looks 
like they include their own coroutine header so it doesn't depend on the 
library. I suppose the same thing can happen here, in which case I agree it's 
probably best to put this on hold in the meantime.


https://reviews.llvm.org/D49647

Files:
  include/contract
  include/module.modulemap
  test/libcxx/double_include.sh.cpp
  test/libcxx/language.support/support.contract/version.pass.cpp
  test/std/language.support/support.contract/contract_violation.pass.cpp

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
+
+// <contract>
+// class contract_violation
+
+#include <contract>
+#include <cstdint>
+#include <string_view>
+#include <type_traits>
+#include <utility>
+
+using CV = std::contract_violation;
+
+// Check for noexcept.
+static_assert(noexcept(std::declval<const CV &>().line_number()));
+static_assert(noexcept(std::declval<const CV &>().file_name()));
+static_assert(noexcept(std::declval<const CV &>().function_name()));
+static_assert(noexcept(std::declval<const CV &>().comment()));
+static_assert(noexcept(std::declval<const CV &>().assertion_level()));
+
+// Check return types.
+static_assert(std::is_same_v<decltype(std::declval<const CV &>().line_number()),
+                             std::uint_least32_t>);
+static_assert(std::is_same_v<decltype(std::declval<const CV &>().file_name()),
+                             std::string_view>);
+static_assert(std::is_same_v<decltype(std::declval<const CV &>().function_name()),
+                             std::string_view>);
+static_assert(std::is_same_v<decltype(std::declval<const CV &>().comment()),
+                             std::string_view>);
+static_assert(std::is_same_v<decltype(std::declval<const CV &>().assertion_level()),
+                             std::string_view>);
+
+int main()
+{
+}
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
+
+// <contract>
+
+#include <contract>
+
+#ifndef _LIBCPP_VERSION
+#error _LIBCPP_VERSION not defined
+#endif
+
+int main()
+{
+}
Index: test/libcxx/double_include.sh.cpp
===================================================================
--- test/libcxx/double_include.sh.cpp
+++ test/libcxx/double_include.sh.cpp
@@ -45,6 +45,7 @@
 #include <complex>
 #include <complex.h>
 #include <condition_variable>
+#include <contract>
 #include <csetjmp>
 #include <csignal>
 #include <cstdarg>
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: 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 <cstdint>
+#include <string_view>
+
+#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
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to