From 3365d5986b8de951fbecc593c441568fa76a1837 Mon Sep 17 00:00:00 2001 From: karl Date: Mon, 15 Mar 2021 13:50:07 +0100 Subject: [PATCH] Enable all warnings and fix a few --- SConstruct | 2 ++ Vector.h | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/SConstruct b/SConstruct index 2f851b0..cb82381 100644 --- a/SConstruct +++ b/SConstruct @@ -4,5 +4,7 @@ env = DefaultEnvironment(tools=['default', 'compilation_db']) env.CompilationDatabase() +env.Append(CCFLAGS=["-Wall", "-Wextra", "-Werror", "-pedantic"]) + # Build the output program Program('vector.out', Glob('*.cpp')) diff --git a/Vector.h b/Vector.h index 3de0eab..998127f 100644 --- a/Vector.h +++ b/Vector.h @@ -25,7 +25,7 @@ class Vector { } // Move Constructor using the copy-and-swap-idiom - Vector(Vector &&other) : data((T *)::operator new(capacity * sizeof(T))) { + Vector(Vector &&other) : data(nullptr) { swap(*this, other); } @@ -160,9 +160,9 @@ class Vector { } private: - T *data; - unsigned int element_count; unsigned int capacity; + unsigned int element_count; + T *data; bool is_using_excessive_memory() { return 10 + element_count * 2 < capacity;