From: Andrew Burgess Date: Thu, 12 Feb 2026 18:22:50 +0000 (+0000) Subject: gdb/testsuite: update C++ tests for volatile changes in C++20 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=120072c7cdc;p=thirdparty%2Fbinutils-gdb.git gdb/testsuite: update C++ tests for volatile changes in C++20 I ran the testsuite on a machine where the C++ compiler was C++20 by default, and noticed a bunch of errors like this: gdb compile failed, /tmp/BUILD/gdb-17.1-build/gdb-17.1/gdb/testsuite/gdb.base/infcall-nested-structs.c: In function 'void breakpt()': /tmp/BUILD/gdb-17.1-build/gdb-17.1/gdb/testsuite/gdb.base/infcall-nested-structs.c:414:3: warning: '++' expression of 'volatile'-qualified type is deprecated [-Wvolatile] 414 | v++; | ^ UNRESOLVED: gdb.base/infcall-nested-structs-c++.exp: types-tl: failed to compile My understanding is that, in C++20, some operations on volatile variables are now deprecated. So things like: volatile int var = 0; ++var; --var var += 1; var -= 1; Are now, I believe, all deprecated. However, this is still allowed: var = var + 1; There are a few test cases where this impacts us, though in every case the increment of the volatile only existed in order to create filler work, as far as I can tell the volatile variable is never inspected from GDB. In gdb.base/infcall-nested-structs.c I just deleted the volatile completely. In the other tests I replaced the '++' with 'var = var + 1' type code. I don't believe there should be any change in what is actually being tested after this patch. --- diff --git a/gdb/testsuite/gdb.base/infcall-nested-structs.c b/gdb/testsuite/gdb.base/infcall-nested-structs.c index 4f194e81f27..9b083f15f11 100644 --- a/gdb/testsuite/gdb.base/infcall-nested-structs.c +++ b/gdb/testsuite/gdb.base/infcall-nested-structs.c @@ -406,12 +406,10 @@ call_all () return val; } -int volatile v = 1; - void __attribute__((noinline)) ATTRIBUTE_NOCLONE breakpt (void) { - v++; + /* Nothing. */ } int diff --git a/gdb/testsuite/gdb.cp/breakpoint-locs.h b/gdb/testsuite/gdb.cp/breakpoint-locs.h index f2fafeb9438..35779bec495 100644 --- a/gdb/testsuite/gdb.cp/breakpoint-locs.h +++ b/gdb/testsuite/gdb.cp/breakpoint-locs.h @@ -20,6 +20,6 @@ namespace N1 class C1 { public: - static void __attribute__((always_inline)) baz () { volatile unsigned i; i++; } + static void __attribute__((always_inline)) baz () { volatile unsigned i; i = i + 1; } }; } diff --git a/gdb/testsuite/gdb.opt/empty-inline-cxx.cc b/gdb/testsuite/gdb.opt/empty-inline-cxx.cc index 7ce3e13ec9a..c6a084a6e37 100644 --- a/gdb/testsuite/gdb.opt/empty-inline-cxx.cc +++ b/gdb/testsuite/gdb.opt/empty-inline-cxx.cc @@ -25,7 +25,7 @@ __attribute__((noinline)) ATTRIBUTE_NOCLONE void breakpt () { /* Some filler work. */ - global++; + global = global + 1; } struct MyClass; diff --git a/gdb/testsuite/gdb.threads/next-while-other-thread-longjmps.c b/gdb/testsuite/gdb.threads/next-while-other-thread-longjmps.c index fead05feb24..c4ebb1f6cfb 100644 --- a/gdb/testsuite/gdb.threads/next-while-other-thread-longjmps.c +++ b/gdb/testsuite/gdb.threads/next-while-other-thread-longjmps.c @@ -64,7 +64,7 @@ thread_try_catch (void *arg) } catch (...) { - counter++; + counter = counter + 1; } usleep (1);