diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index 458ed26..c446cd6 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -5135,6 +5135,9 @@ finish_transaction_stmt (tree stmt, tree compound_stmt, int flags, tree noex)
       TRANSACTION_EXPR_BODY (stmt) = body;
     }
 
+  if (TREE_SIDE_EFFECTS (TRANSACTION_EXPR_BODY (stmt)))
+    TREE_SIDE_EFFECTS (stmt) = 1;
+
   if (compound_stmt)
     finish_compound_stmt (compound_stmt);
   finish_stmt ();
diff --git a/gcc/testsuite/g++.dg/tm/pr56419.C b/gcc/testsuite/g++.dg/tm/pr56419.C
new file mode 100644
index 0000000..c9a33a8
--- /dev/null
+++ b/gcc/testsuite/g++.dg/tm/pr56419.C
@@ -0,0 +1,13 @@
+// { dg-do compile }
+// { dg-options "-fgnu-tm" }
+
+int x = 0;
+int inc_func(int i) {
+     for (int j = 0; j < i; ++j)
+     {
+         __transaction_atomic { x+=1; }
+     }
+     return 0;
+}
+
+// { dg-final { scan-assembler "ITM_commitTransaction" } }
