summaryrefslogtreecommitdiff
path: root/absl/types/bad_variant_access.cc
diff options
context:
space:
mode:
authorGravatar Abseil Team <absl-team@google.com>2018-04-20 09:16:52 -0700
committerGravatar Jon Cohen <cohenjon@google.com>2018-04-20 12:30:23 -0400
commitfaf0a1b90374eab44e8956973b0e13febdcf3377 (patch)
tree63a7fd12a50b15c4a321e8373c1bbd975df0b7ba /absl/types/bad_variant_access.cc
parent5b535401665cc6aa96d54a5c9b0901153d97210f (diff)
- 551e205ef49682a1cb7e6e0cda46957fbcf88edd Release absl::variant. by Xiaoyi Zhang <zhangxy@google.com>
- 01c52f640594d073c6e54c47e7853b25522cf085 Update comments in absl::variant (and minor changes to ab... by Tom Manshreck <shreck@google.com> - 064465e1e6b158abd8c38fd1942b4fc464b57d6a Documentation change. by Abseil Team <absl-team@google.com> - 58df2c8a27e80c9ea21d87c1acee8019246377c9 Relocates SetCountdown and UnsetCountdown to the exceptio... by Abseil Team <absl-team@google.com> - fd9d248d0948d472f2543f7fd9c0ae4a1cd60d01 Clarify thread_annotation.h documentation around local va... by Abseil Team <absl-team@google.com> - 0d0abaf7f0945ac5f2c5f49e78afe1b326d5aca0 Typo fix in comments. by Abseil Team <absl-team@google.com> - 67286d587cbd07508a81e5b8147c245a5b5538b4 Internal change. by Xiaoyi Zhang <zhangxy@google.com> GitOrigin-RevId: 551e205ef49682a1cb7e6e0cda46957fbcf88edd Change-Id: I1a343b080187293cb5f892a309618b5712e7aa14
Diffstat (limited to 'absl/types/bad_variant_access.cc')
-rw-r--r--absl/types/bad_variant_access.cc58
1 files changed, 58 insertions, 0 deletions
diff --git a/absl/types/bad_variant_access.cc b/absl/types/bad_variant_access.cc
new file mode 100644
index 00000000..817fd789
--- /dev/null
+++ b/absl/types/bad_variant_access.cc
@@ -0,0 +1,58 @@
+// 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
+//
+// http://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/types/bad_variant_access.h"
+
+#include <cstdlib>
+#include <stdexcept>
+
+#include "absl/base/config.h"
+#include "absl/base/internal/raw_logging.h"
+
+namespace absl {
+
+//////////////////////////
+// [variant.bad.access] //
+//////////////////////////
+
+bad_variant_access::~bad_variant_access() = default;
+
+const char* bad_variant_access::what() const noexcept {
+ return "Bad variant access";
+}
+
+namespace variant_internal {
+
+void ThrowBadVariantAccess() {
+#ifdef ABSL_HAVE_EXCEPTIONS
+ throw bad_variant_access();
+#else
+ ABSL_RAW_LOG(FATAL, "Bad variant access");
+ abort(); // TODO(calabrese) Remove once RAW_LOG FATAL is noreturn.
+#endif
+}
+
+void Rethrow() {
+#ifdef ABSL_HAVE_EXCEPTIONS
+ throw;
+#else
+ ABSL_RAW_LOG(FATAL,
+ "Internal error in absl::variant implementation. Attempted to "
+ "rethrow an exception when building with exceptions disabled.");
+ abort(); // TODO(calabrese) Remove once RAW_LOG FATAL is noreturn.
+#endif
+}
+
+} // namespace variant_internal
+} // namespace absl