]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb/testsuite: update C++ tests for volatile changes in C++20
authorAndrew Burgess <aburgess@redhat.com>
Thu, 12 Feb 2026 18:22:50 +0000 (18:22 +0000)
committerAndrew Burgess <aburgess@redhat.com>
Thu, 19 Feb 2026 10:43:37 +0000 (10:43 +0000)
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.

gdb/testsuite/gdb.base/infcall-nested-structs.c
gdb/testsuite/gdb.cp/breakpoint-locs.h
gdb/testsuite/gdb.opt/empty-inline-cxx.cc
gdb/testsuite/gdb.threads/next-while-other-thread-longjmps.c

index 4f194e81f27cf06b690b5dbdecaa48afe4bb0a3e..9b083f15f11c1b197c2c40b2823cafa109a8e2b8 100644 (file)
@@ -406,12 +406,10 @@ call_all ()
   return val;
 }
 
-int volatile v = 1;
-
 void __attribute__((noinline)) ATTRIBUTE_NOCLONE
 breakpt (void)
 {
-  v++;
+  /* Nothing.  */
 }
 
 int
index f2fafeb9438be3f60c45f0a4d581a089b625aac6..35779bec495ff2d51ae6f4d1c0178049436e21c4 100644 (file)
@@ -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; }
   };
 }
index 7ce3e13ec9a2924ec108356fb421a75fb2b90912..c6a084a6e375b5d2637b4e2cbbc92f5fa5a43d04 100644 (file)
@@ -25,7 +25,7 @@ __attribute__((noinline)) ATTRIBUTE_NOCLONE void
 breakpt ()
 {
   /* Some filler work.  */
-  global++;
+  global = global + 1;
 }
 
 struct MyClass;
index fead05feb2416b8461744877bd4bf0c71931beca..c4ebb1f6cfbbe387fe1a1e553a99f258e4ecd51f 100644 (file)
@@ -64,7 +64,7 @@ thread_try_catch (void *arg)
        }
       catch (...)
        {
-         counter++;
+         counter = counter + 1;
        }
 
       usleep (1);