From 94bf9c06cfcc16fb9494ad31bc425d351b7505b7 Mon Sep 17 00:00:00 2001 From: neingeist Date: Sun, 13 Apr 2014 09:48:04 +0200 Subject: [PATCH] add some broken array/vector tests --- .gitignore | 1 + CMakeLists.txt | 1 + array-bounds.cpp | 57 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+) create mode 100644 array-bounds.cpp diff --git a/.gitignore b/.gitignore index 0b85be5..9cc68db 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ auto_ptr typetest unique_ptr list-initializers +array-bounds diff --git a/CMakeLists.txt b/CMakeLists.txt index 6cd51dd..817877e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,3 +7,4 @@ add_executable(typetest typetest.cpp) add_executable(auto_ptr auto_ptr.cpp) add_executable(unique_ptr unique_ptr.cpp) add_executable(list-initializers list-initializers.cpp) +add_executable(array-bounds array-bounds.cpp) diff --git a/array-bounds.cpp b/array-bounds.cpp new file mode 100644 index 0000000..111a090 --- /dev/null +++ b/array-bounds.cpp @@ -0,0 +1,57 @@ +#include +#include +#include + +void classic() { + int array[2]; + array[0] = 1; + array[1] = 2; + // array[3] = 3; <- clang++ -Warray-bounds warns about this + // array[4] = 4; <- clang++ -Warray-bounds warns about this + + int n = 10; + std::cout << array[3] << std::endl; // no warning! + std::cout << array[4] << std::endl; // no warning! + std::cout << array[n-1] << std::endl; // no warning! +} + +// FIXME +void std_array() { + std::array array; + array[0] = 1; + array[1] = 2; + array[3] = 3; // XXX <- clang++ -Warray-bounds warns about this + // array[4] = 4; <- clang++ -Warray-bounds warns about this + + int n = 10; + std::cout << array[3] << std::endl; // no warning! + std::cout << array[4] << std::endl; // no warning! + std::cout << array[n-1] << std::endl; // no warning! +} + +// FIXME +void std_vector() { + std::vector vector; + vector[0] = 1; + vector[1] = 2; + // vector[3] = 3; // SEGFAULT + // vector[4] = 4; <- clang++ -Warray-bounds warns about this + + int n = 10; + // std::cout << vector[3] << std::endl; // no warning! + // std::cout << vector[4] << std::endl; // no warning! + // std::cout << vector[n-1] << std::endl; // no warning! +} + +int main() { + std::cout << "classic()" << std::endl; + classic(); + + std::cout << "std_array()" << std::endl; + std_array(); + + std::cout << "std_vector()" << std::endl; + std_vector(); + + return 0; +}