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
--- /dev/null
+// 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
#include <memory>
#include <forward_list>
-#include <stdexcept>
namespace zc {
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>> {
private:
void CheckDeleted() const {
if (deleted_) {
- throw UseAfterFreeException("attempt to access deleted pointer");
+ internal::RaiseUseAfterFree("attempt to access deleted pointer");
}
}