aboutsummaryrefslogtreecommitdiff
path: root/gcc/vec.c
diff options
context:
space:
mode:
authorThomas Koenig <tkoenig@gcc.gnu.org>2021-09-13 19:49:49 +0200
committerThomas Koenig <tkoenig@gcc.gnu.org>2021-09-13 19:49:49 +0200
commitb18a97e5dd0935e1c4a626c230f21457d0aad3d5 (patch)
treec1818f41af6fe780deafb6cd6a183f32085fe654 /gcc/vec.c
parente76a53644c9d70e998c0d050e9a456af388c6b61 (diff)
downloadgcc-b18a97e5dd0935e1c4a626c230f21457d0aad3d5.zip
gcc-b18a97e5dd0935e1c4a626c230f21457d0aad3d5.tar.gz
gcc-b18a97e5dd0935e1c4a626c230f21457d0aad3d5.tar.bz2
Merged current trunk to branch.
Diffstat (limited to 'gcc/vec.c')
-rw-r--r--gcc/vec.c49
1 files changed, 38 insertions, 11 deletions
diff --git a/gcc/vec.c b/gcc/vec.c
index a288991..6d767cc 100644
--- a/gcc/vec.c
+++ b/gcc/vec.c
@@ -1,5 +1,5 @@
/* Vector API for GNU compiler.
- Copyright (C) 2004-2020 Free Software Foundation, Inc.
+ Copyright (C) 2004-2021 Free Software Foundation, Inc.
Contributed by Nathan Sidwell <nathan@codesourcery.com>
Re-implemented in C++ by Diego Novillo <dnovillo@google.com>
@@ -38,16 +38,6 @@ along with GCC; see the file COPYING3. If not see
#include "diagnostic-core.h"
#endif
-/* vNULL is an empty type with a template cast operation that returns
- a zero-initialized vec<T, A, L> instance. Use this when you want
- to assign nil values to new vec instances or pass a nil vector as
- a function call argument.
-
- We use this technique because vec<T, A, L> must be PODs (they are
- stored in unions and passed in vararg functions), this means that
- they cannot have ctors/dtors. */
-vnull vNULL;
-
/* Vector memory usage. */
class vec_usage: public mem_usage
{
@@ -282,6 +272,42 @@ safe_push_range (vec <int>&v, int start, int limit)
v.safe_push (i);
}
+/* Verify forms of initialization. */
+
+static void
+test_init ()
+{
+ {
+ vec<int> v1{ };
+ ASSERT_EQ (0, v1.length ());
+
+ vec<int> v2 (v1);
+ ASSERT_EQ (0, v2.length ());
+ }
+
+ {
+ vec<int> v1 = vec<int>();
+ ASSERT_EQ (0, v1.length ());
+
+ vec<int> v2 = v1;
+ ASSERT_EQ (0, v2.length ());
+ }
+
+ {
+ vec<int> v1 (vNULL);
+ ASSERT_EQ (0, v1.length ());
+ v1.safe_push (1);
+
+ vec<int> v2 (v1);
+ ASSERT_EQ (1, v1.length ());
+ v2.safe_push (1);
+
+ ASSERT_EQ (2, v1.length ());
+ ASSERT_EQ (2, v2.length ());
+ v1.release ();
+ }
+}
+
/* Verify that vec::quick_push works correctly. */
static void
@@ -547,6 +573,7 @@ test_auto_delete_vec ()
void
vec_c_tests ()
{
+ test_init ();
test_quick_push ();
test_safe_push ();
test_truncate ();