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

- Added a missing visibility attribute.
- Added a simple test that type-checks the expected public interface.

Testing whether it's actually hooked up correctly is quite problematic; it 
isn't meant to be instantiable. What's the best way to proceed with this?


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,42 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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 "test_macros.h"
+
+// Check that the expected public members exist and have the required type.
+// The contract_violation is taken as a const reference, which ensures that the
+// member functions we access are marked as const.
+void check_public_member_types(const std::contract_violation &violation) {
+  (void)violation;
+
+  ASSERT_NOEXCEPT(violation.line_number());
+  ASSERT_NOEXCEPT(violation.file_name());
+  ASSERT_NOEXCEPT(violation.function_name());
+  ASSERT_NOEXCEPT(violation.comment());
+  ASSERT_NOEXCEPT(violation.assertion_level());
+
+  ASSERT_SAME_TYPE(decltype(violation.line_number()), std::uint_least32_t);
+  ASSERT_SAME_TYPE(decltype(violation.file_name()), std::string_view);
+  ASSERT_SAME_TYPE(decltype(violation.function_name()), std::string_view);
+  ASSERT_SAME_TYPE(decltype(violation.comment()), std::string_view);
+  ASSERT_SAME_TYPE(decltype(violation.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,20 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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.
+//
+//===----------------------------------------------------------------------===//
+
+// <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