Bug 24789 - gdb thinks an int is not an int
Summary: gdb thinks an int is not an int
Status: UNCONFIRMED
Alias: None
Product: gdb
Classification: Unclassified
Component: c++ (show other bugs)
Version: 8.3
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-07-09 07:44 UTC by Hi-Angel
Modified: 2019-07-09 07:44 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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>