diff --git a/gcc/testsuite/c-c++-common/analyzer/compound-assignment-1.c b/gcc/testsuite/c-c++-common/analyzer/compound-assignment-1.c
index 0ab006d505ffc7a4f313c6a808995a0c7424529d..b7389e2808371d042a997a24dbe0b0ebcd61d68d 100644
--- a/gcc/testsuite/c-c++-common/analyzer/compound-assignment-1.c
+++ b/gcc/testsuite/c-c++-common/analyzer/compound-assignment-1.c
@@ -68,5 +68,8 @@ called_by_test_5b (void)
 
 void test_5b (void)
 {
-  called_by_test_5b ();
-} /* { dg-warning "leak of '<anonymous>.ptr_wrapper::ptr'" "" { target c++ } } */
+  called_by_test_5b (); }
+/* { dg-warning "leak of '<anonymous>.ptr_wrapper::ptr'" "" { target c++ } .-1 } */
+/* The closing } above is intentionally on the same line as the call, because
+   otherwise the exact line of the diagnostics depends on whether the
+   called_by_test_5b () call satisfies aggregate_value_p or not.  */