Bug 24789

Summary: gdb thinks an int is not an int
Product: gdb Reporter: Hi-Angel <hi-angel>
Component: c++Assignee: Not yet assigned to anyone <unassigned>
Status: UNCONFIRMED ---    
Severity: normal    
Priority: P2    
Version: 8.3   
Target Milestone: ---   
Host: Target:
Build: Last reconfirmed:

Description Hi-Angel 2019-07-09 07:44:28 UTC
# Steps to reproduce (in terms of terminal commands)

    $ cat -n test.cpp
         1  #include <cstdio>
         2  #include <utility>
         3
         4  using namespace std;
         5
         6  int main() {
         7      pair<int,int> mypair = {10, 10};
         8      auto [myint1,myint2] = mypair;
         9      char* ptr = nullptr;
        10      printf("%p\n", ptr + myint1);
        11  }
    $ g++ test.cpp -o a -g3 -O0 -std=c++17
    $ gdb ./a                             
    Reading symbols from ./a...
    gdb λ br 10
    Breakpoint 1 at 0x11a6: file test.cpp, line 10.
    gdb λ r
    Starting program: /tmp/a 

    Breakpoint 1, main () at test.cpp:10
    10          printf("%p\n", ptr + myint1);
    gdb λ p ptr + myint1

# Expected
    $1 = 0xa <error: Cannot access memory at address 0xa>

# Actual
    Argument to arithmetic operation not a number or boolean.

# Possible workarounds

Explicitly casting the int to int makes it work:

    gdb λ p ptr + (int)myint1
    $1 = 0xa <error: Cannot access memory at address 0xa>