about summary refs log tree commit diff
path: root/absl/base
diff options
context:
space:
mode:
Diffstat (limited to 'absl/base')
-rw-r--r--absl/base/BUILD.bazel14
-rw-r--r--absl/base/CMakeLists.txt13
-rw-r--r--absl/base/casts.h22
-rw-r--r--absl/base/dynamic_annotations.h2
-rw-r--r--absl/base/log_severity.cc25
-rw-r--r--absl/base/log_severity.h5
-rw-r--r--absl/base/log_severity_test.cc43
7 files changed, 108 insertions, 16 deletions
diff --git a/absl/base/BUILD.bazel b/absl/base/BUILD.bazel
index 8133a4627e1a..9fb1d8cdddb3 100644
--- a/absl/base/BUILD.bazel
+++ b/absl/base/BUILD.bazel
@@ -135,6 +135,7 @@ cc_library(
         "internal/sysinfo.cc",
         "internal/thread_identity.cc",
         "internal/unscaledcycleclock.cc",
+        "log_severity.cc",
     ],
     hdrs = [
         "call_once.h",
@@ -162,6 +163,7 @@ cc_library(
         ":core_headers",
         ":dynamic_annotations",
         ":spinlock_wait",
+        "//absl/meta:type_traits",
     ],
 )
 
@@ -523,3 +525,15 @@ cc_test(
         "@com_google_googletest//:gtest_main",
     ],
 )
+
+cc_test(
+    name = "log_severity_test",
+    size = "small",
+    srcs = ["log_severity_test.cc"],
+    copts = ABSL_TEST_COPTS,
+    linkopts = ABSL_DEFAULT_LINKOPTS,
+    deps = [
+        ":base",
+        "@com_google_googletest//:gtest_main",
+    ],
+)
diff --git a/absl/base/CMakeLists.txt b/absl/base/CMakeLists.txt
index cd1ec4128539..5042f1567043 100644
--- a/absl/base/CMakeLists.txt
+++ b/absl/base/CMakeLists.txt
@@ -127,6 +127,7 @@ absl_cc_library(
     "internal/sysinfo.cc"
     "internal/thread_identity.cc"
     "internal/unscaledcycleclock.cc"
+    "log_severity.cc"
   COPTS
     ${ABSL_DEFAULT_COPTS}
   DEPS
@@ -135,6 +136,7 @@ absl_cc_library(
     absl::core_headers
     absl::dynamic_annotations
     absl::spinlock_wait
+    absl::type_traits
     Threads::Threads
   PUBLIC
 )
@@ -449,3 +451,14 @@ absl_cc_test(
   DEPS
     absl::base
 )
+
+absl_cc_test(
+  NAME
+    log_severity_test
+  SRCS
+    "log_severity_test.cc"
+  DEPS
+    absl::base
+    gmock
+    gtest_main
+)
diff --git a/absl/base/casts.h b/absl/base/casts.h
index 00196d20ae77..a381c4276441 100644
--- a/absl/base/casts.h
+++ b/absl/base/casts.h
@@ -30,28 +30,20 @@
 
 #include "absl/base/internal/identity.h"
 #include "absl/base/macros.h"
+#include "absl/meta/type_traits.h"
 
 namespace absl {
 
 namespace internal_casts {
 
-// NOTE: Not a fully compliant implementation of `std::is_trivially_copyable`.
-// TODO(calabrese) Branch on implementations that directly provide
-// `std::is_trivially_copyable`, create a more rigorous workaround, and publicly
-// expose in meta/type_traits.
-template <class T>
-struct is_trivially_copyable
-    : std::integral_constant<
-          bool, std::is_destructible<T>::value&& __has_trivial_destructor(T) &&
-                    __has_trivial_copy(T) && __has_trivial_assign(T)> {};
-
 template <class Dest, class Source>
 struct is_bitcastable
-    : std::integral_constant<bool,
-                             sizeof(Dest) == sizeof(Source) &&
-                                 is_trivially_copyable<Source>::value &&
-                                 is_trivially_copyable<Dest>::value &&
-                                 std::is_default_constructible<Dest>::value> {};
+    : std::integral_constant<
+          bool,
+          sizeof(Dest) == sizeof(Source) &&
+              type_traits_internal::is_trivially_copyable<Source>::value &&
+              type_traits_internal::is_trivially_copyable<Dest>::value &&
+              std::is_default_constructible<Dest>::value> {};
 
 }  // namespace internal_casts
 
diff --git a/absl/base/dynamic_annotations.h b/absl/base/dynamic_annotations.h
index ac33df9e575a..65a54b447f80 100644
--- a/absl/base/dynamic_annotations.h
+++ b/absl/base/dynamic_annotations.h
@@ -377,7 +377,7 @@ inline T ANNOTATE_UNPROTECTED_READ(const volatile T &x) { /* NOLINT */
   struct { char x[8] __attribute__ ((aligned (8))); } name
 #else
 #define ANNOTATE_CONTIGUOUS_CONTAINER(beg, end, old_mid, new_mid)
-#define ADDRESS_SANITIZER_REDZONE(name)
+#define ADDRESS_SANITIZER_REDZONE(name) static_assert(true, "")
 #endif  // ADDRESS_SANITIZER
 
 /* Undefine the macros intended only in this file. */
diff --git a/absl/base/log_severity.cc b/absl/base/log_severity.cc
new file mode 100644
index 000000000000..02a2a4852a57
--- /dev/null
+++ b/absl/base/log_severity.cc
@@ -0,0 +1,25 @@
+// Copyright 2017 The Abseil Authors.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      https://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include "absl/base/log_severity.h"
+
+#include <ostream>
+
+namespace absl {
+
+std::ostream& operator<<(std::ostream& os, absl::LogSeverity s) {
+  if (s == absl::NormalizeLogSeverity(s)) return os << absl::LogSeverityName(s);
+  return os << "absl::LogSeverity(" << static_cast<int>(s) << ")";
+}
+}  // namespace absl
diff --git a/absl/base/log_severity.h b/absl/base/log_severity.h
index b19a7ffab820..5a1d5576ce7b 100644
--- a/absl/base/log_severity.h
+++ b/absl/base/log_severity.h
@@ -16,6 +16,7 @@
 #define ABSL_BASE_INTERNAL_LOG_SEVERITY_H_
 
 #include <array>
+#include <ostream>
 
 #include "absl/base/attributes.h"
 
@@ -61,6 +62,10 @@ constexpr absl::LogSeverity NormalizeLogSeverity(int s) {
   return NormalizeLogSeverity(static_cast<absl::LogSeverity>(s));
 }
 
+// The exact representation of a streamed `absl::LogSeverity` is deliberately
+// unspecified; do not rely on it.
+std::ostream& operator<<(std::ostream& os, absl::LogSeverity s);
+
 }  // namespace absl
 
 #endif  // ABSL_BASE_INTERNAL_LOG_SEVERITY_H_
diff --git a/absl/base/log_severity_test.cc b/absl/base/log_severity_test.cc
new file mode 100644
index 000000000000..1de2d101bfa8
--- /dev/null
+++ b/absl/base/log_severity_test.cc
@@ -0,0 +1,43 @@
+// Copyright 2018 The Abseil Authors.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      https://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include "absl/base/log_severity.h"
+
+#include <sstream>
+#include <string>
+
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+namespace {
+using testing::Eq;
+
+std::string StreamHelper(absl::LogSeverity value) {
+  std::ostringstream stream;
+  stream << value;
+  return stream.str();
+}
+
+TEST(StreamTest, Works) {
+  EXPECT_THAT(StreamHelper(static_cast<absl::LogSeverity>(-100)),
+              Eq("absl::LogSeverity(-100)"));
+  EXPECT_THAT(StreamHelper(absl::LogSeverity::kInfo), Eq("INFO"));
+  EXPECT_THAT(StreamHelper(absl::LogSeverity::kWarning), Eq("WARNING"));
+  EXPECT_THAT(StreamHelper(absl::LogSeverity::kError), Eq("ERROR"));
+  EXPECT_THAT(StreamHelper(absl::LogSeverity::kFatal), Eq("FATAL"));
+  EXPECT_THAT(StreamHelper(static_cast<absl::LogSeverity>(4)),
+              Eq("absl::LogSeverity(4)"));
+}
+
+}  // namespace