aboutsummaryrefslogtreecommitdiff
path: root/gcc/vec.c
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@golang.org>2021-09-13 10:37:49 -0700
committerIan Lance Taylor <iant@golang.org>2021-09-13 10:37:49 -0700
commite252b51ccde010cbd2a146485d8045103cd99533 (patch)
treee060f101cdc32bf5e520de8e5275db9d4236b74c /gcc/vec.c
parentf10c7c4596dda99d2ee872c995ae4aeda65adbdf (diff)
parent104c05c5284b7822d770ee51a7d91946c7e56d50 (diff)
downloadgcc-e252b51ccde010cbd2a146485d8045103cd99533.zip
gcc-e252b51ccde010cbd2a146485d8045103cd99533.tar.gz
gcc-e252b51ccde010cbd2a146485d8045103cd99533.tar.bz2
Merge from trunk revision 104c05c5284b7822d770ee51a7d91946c7e56d50.
Diffstat (limited to 'gcc/vec.c')
-rw-r--r--gcc/vec.c47
1 files changed, 37 insertions, 10 deletions
diff --git a/gcc/vec.c b/gcc/vec.c
index f9dbb2c..6d767cc 100644
--- a/gcc/vec.c
+++ b/gcc/vec.c
@@ -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 ();