Move exception raising into a .cc file so that -fno-exceptions can be used with the...
authorRobert Sesek <rsesek@bluestatic.org>
Sat, 8 Oct 2016 19:29:27 +0000 (15:29 -0400)
committerRobert Sesek <rsesek@bluestatic.org>
Sat, 8 Oct 2016 19:34:13 +0000 (15:34 -0400)
Makefile
zcpointer.cc [new file with mode: 0644]
zcpointer.h

index 12299a28c6e0e4790766e8e207af83e18168ae27..87d7be63da6891289651dce3b5b3e4500e11f0d5 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,13 +1,15 @@
 CXX := clang++
 CXXFLAGS := -g -std=c++11
 
+FILES := test.cc zcpointer.cc
+
 all: test-zc test-tr
 
-test-zc: test.cc
-       $(CXX) $(CXXFLAGS) $< -o $@
+test-zc: $(FILES) zcpointer.h
+       $(CXX) $(CXXFLAGS) $(FILES) -o $@
 
-test-tr: test.cc
-       $(CXX) -DZCPOINTER_TRACK_REFS=1 $(CXXFLAGS) $< -o $@
+test-tr: $(FILES) zcpointer.h
+       $(CXX) -DZCPOINTER_TRACK_REFS=1 $(CXXFLAGS) $(FILES) -o $@
 
 clean:
        rm -rf test-zc test-tr *.dSYM
diff --git a/zcpointer.cc b/zcpointer.cc
new file mode 100644 (file)
index 0000000..1dc22ba
--- /dev/null
@@ -0,0 +1,25 @@
+// Copyright 2016 Google Inc. All rights reserved.
+//
+// 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 <stdexcept>
+
+namespace zc {
+namespace internal {
+
+void RaiseUseAfterFree(const char* error) {
+  throw std::logic_error(error);
+}
+
+}  // namespace internal
+}  // namespace zc
index 27bffa997b76702865a174f9fe83633755f7ed45..ce4a821e2a71ccb36e36f3f16713aee8677d5ed9 100644 (file)
@@ -14,7 +14,6 @@
 
 #include <memory>
 #include <forward_list>
-#include <stdexcept>
 
 namespace zc {
 
@@ -55,9 +54,9 @@ class OwnedPtrDeleter {
   std::forward_list<ref<T>*> refs_;
 };
 
-}  // namespace internal
+void RaiseUseAfterFree(const char* error) __attribute__((noreturn));
 
-using UseAfterFreeException = std::logic_error;
+}  // namespace internal
 
 template <typename T>
 class owned : public std::unique_ptr<T, internal::OwnedPtrDeleter<T>> {
@@ -121,7 +120,7 @@ class ref {
  private:
   void CheckDeleted() const {
     if (deleted_) {
-      throw UseAfterFreeException("attempt to access deleted pointer");
+      internal::RaiseUseAfterFree("attempt to access deleted pointer");
     }
   }