From 7ccad498c42b414dca0050497950fd010a0a2698 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sat, 8 Oct 2016 15:29:27 -0400 Subject: [PATCH] Move exception raising into a .cc file so that -fno-exceptions can be used with the header. --- Makefile | 10 ++++++---- zcpointer.cc | 25 +++++++++++++++++++++++++ zcpointer.h | 7 +++---- 3 files changed, 34 insertions(+), 8 deletions(-) create mode 100644 zcpointer.cc diff --git a/Makefile b/Makefile index 12299a2..87d7be6 100644 --- 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 index 0000000..1dc22ba --- /dev/null +++ b/zcpointer.cc @@ -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 + +namespace zc { +namespace internal { + +void RaiseUseAfterFree(const char* error) { + throw std::logic_error(error); +} + +} // namespace internal +} // namespace zc diff --git a/zcpointer.h b/zcpointer.h index 27bffa9..ce4a821 100644 --- a/zcpointer.h +++ b/zcpointer.h @@ -14,7 +14,6 @@ #include #include -#include namespace zc { @@ -55,9 +54,9 @@ class OwnedPtrDeleter { std::forward_list*> refs_; }; -} // namespace internal +void RaiseUseAfterFree(const char* error) __attribute__((noreturn)); -using UseAfterFreeException = std::logic_error; +} // namespace internal template class owned : public std::unique_ptr> { @@ -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"); } } -- 2.43.5