[Bug exp/34203] [gdb/exp] Namespace variable found before using statement at end of block

"cvs-commit at gcc dot gnu.org via Gdb-prs" <[email protected]>
Newsgroups gmane.comp.gdb.bugs.discuss
Message-ID <[email protected]/bugzilla/>
https://sourceware.org/bugzilla/show_bug.cgi?id=34203

--- Comment #3 from Sourceware Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Tom de Vries <[email protected]>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=c20c23f2a738cfc641ae2ffd9574f6288c248b81

commit c20c23f2a738cfc641ae2ffd9574f6288c248b81
Author: Tom de Vries <[email protected]>
Date:   Mon Jul 13 18:13:24 2026 +0200

    [gdb/exp] Limit workaround in using_direct::valid_line to broken GCC
versions

    Consider test.c:
    ...
         1  namespace mod_a {
         2    int xxx = 10;
         3  }
         4
         5  static void
         6  foo ()
         7  {
         8  }
         9
        10  int
        11  main ()
        12  {
        13    {
        14      foo ();
        15      using namespace mod_a;
        16    }
        17
        18    return mod_a::xxx;
        19  }
    ...
    compiled with "g++ test.c -g".

    Attempting to print xxx at line 14 shouldn't find anything (because it's
    before the "using namespace mod_a"), but it does:
    ...
    $ gdb -q -batch a.out -ex start -ex "p xxx"
    ...
    Temporary breakpoint 1, main () at test.c:14
    14          foo ();
    $1 = 10
    ...

    This happens because using_direct::valid_line returns true here:
    ...
          return (decl_line <= curr_sal.line)
                 || (decl_line >= boundary);
    ...

    Since we have decl_line == 15 and curr_sal.line == 14,
    "(decl_line <= curr_sal.line)" evaluates to false.

    But boundary == 14, so "(decl_line >= boundary)" evaluates to true.

    The "(decl_line >= boundary)" bit was added as a workaround for
    GCC PR debug/108716.

    Since I'm using GCC 15, the workaround is not needed.

    Fix this by limiting the workaround to broken GCC versions.

    Tested on x86_64-linux, using GCC 15.2, and 7.5.

    Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=34203

-- 
You are receiving this mail because:
You are on the CC list for the bug.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.