aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite
diff options
context:
space:
mode:
authorHannes Domani <ssbssa@yahoo.de>2020-03-31 14:49:06 +0200
committerHannes Domani <ssbssa@yahoo.de>2020-04-01 19:15:03 +0200
commit60e22c1eacb0df32aeeeb78c53cfd46c53a3770f (patch)
treee9870fa9aee3159d44e48cffce61f0d85abf8318 /gdb/testsuite
parent77bf7b5317195e092a9f18fef993c412e2e05f53 (diff)
downloadgdb-60e22c1eacb0df32aeeeb78c53cfd46c53a3770f.zip
gdb-60e22c1eacb0df32aeeeb78c53cfd46c53a3770f.tar.gz
gdb-60e22c1eacb0df32aeeeb78c53cfd46c53a3770f.tar.bz2
Allow pointer arithmetic with integer references
Considering these variables: int i = 3; int &iref = i; It's not possible to do any pointer arithmetic with iref: (gdb) p &i+iref Argument to arithmetic operation not a number or boolean. So this adds checks for references to integers in pointer arithmetic. gdb/ChangeLog: 2020-04-01 Hannes Domani <ssbssa@yahoo.de> PR gdb/24789 * eval.c (is_integral_or_integral_reference): New function. (evaluate_subexp_standard): Allow integer references in pointer arithmetic. gdb/testsuite/ChangeLog: 2020-04-01 Hannes Domani <ssbssa@yahoo.de> PR gdb/24789 * gdb.cp/misc.cc: Add integer reference variable. * gdb.cp/misc.exp: Add test.
Diffstat (limited to 'gdb/testsuite')
-rw-r--r--gdb/testsuite/ChangeLog6
-rw-r--r--gdb/testsuite/gdb.cp/misc.cc3
-rw-r--r--gdb/testsuite/gdb.cp/misc.exp8
3 files changed, 17 insertions, 0 deletions
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index cc2335e..58271cf 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,9 @@
+2020-04-01 Hannes Domani <ssbssa@yahoo.de>
+
+ PR gdb/24789
+ * gdb.cp/misc.cc: Add integer reference variable.
+ * gdb.cp/misc.exp: Add test.
+
2020-04-01 Tankut Baris Aktemur <tankut.baris.aktemur@intel.com>
* gdb.server/stop-reply-no-thread.exp: Enhance the test
diff --git a/gdb/testsuite/gdb.cp/misc.cc b/gdb/testsuite/gdb.cp/misc.cc
index d461d6d..41fb9d2 100644
--- a/gdb/testsuite/gdb.cp/misc.cc
+++ b/gdb/testsuite/gdb.cp/misc.cc
@@ -24,6 +24,9 @@ bool v_bool_array[2];
typedef struct fleep fleep;
struct fleep { int a; } s;
+int number;
+int &number_ref = number;
+
// ====================== simple class structures =======================
struct default_public_struct {
diff --git a/gdb/testsuite/gdb.cp/misc.exp b/gdb/testsuite/gdb.cp/misc.exp
index bceb73e..cd6f0f7 100644
--- a/gdb/testsuite/gdb.cp/misc.exp
+++ b/gdb/testsuite/gdb.cp/misc.exp
@@ -110,3 +110,11 @@ gdb_test "print (int)false" "\\$\[0-9\]* = 0" "(int)false"
gdb_test "print 'misc.cc'::v_bool" " = true" \
"expression using block qualifier"
+
+# pointer arithmetic
+gdb_test "print *(v_bool_array + number_ref)" "\\$\[0-9\]* = false" \
+ "pointer addition with integer reference"
+gdb_test "print *(number_ref + v_bool_array)" "\\$\[0-9\]* = false" \
+ "pointer addition with integer reference"
+gdb_test "print *(v_bool_array - number_ref)" "\\$\[0-9\]* = false" \
+ "pointer subtraction with integer reference"