]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: Fix -Wmisleading-indentation ICE on expansion stmt [PR123694]
authorJakub Jelinek <jakub@redhat.com>
Tue, 20 Jan 2026 16:06:54 +0000 (17:06 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Tue, 20 Jan 2026 16:06:54 +0000 (17:06 +0100)
The following testcase ICEs in the -Wmisleading-indentation warning.
For C++11 and later expansion statement can appear in the set of keywords
the warning sees and it is the first keyword of it (for expansion stmt
of a pair of keywords), so RID_TEMPLATE.

2026-01-20  Jakub Jelinek  <jakub@redhat.com>

PR c++/123694
* c-indentation.cc (guard_tinfo_to_string): Handle RID_TEMPLATE
for C++11 or later.

* g++.dg/cpp26/expansion-stmt28.C: New test.

gcc/c-family/c-indentation.cc
gcc/testsuite/g++.dg/cpp26/expansion-stmt28.C [new file with mode: 0644]

index 88867540e611baf7abe1e4478e89a70b966c784e..ec371686a2e06908e426f97c053a9634d45e44ae 100644 (file)
@@ -606,6 +606,9 @@ guard_tinfo_to_string (enum rid keyword)
       return "do";
     case RID_SWITCH:
       return "switch";
+    case RID_TEMPLATE:
+      gcc_assert (cxx_dialect >= cxx11);
+      return "template for";
     default:
       gcc_unreachable ();
     }
diff --git a/gcc/testsuite/g++.dg/cpp26/expansion-stmt28.C b/gcc/testsuite/g++.dg/cpp26/expansion-stmt28.C
new file mode 100644 (file)
index 0000000..957022a
--- /dev/null
@@ -0,0 +1,13 @@
+// PR c++/123694
+// { dg-do compile { target c++11 } }
+// { dg-options "-Wmisleading-indentation" }
+
+int
+foo ()
+{
+  int b = 0;
+  template for (constexpr auto a : { 1, 2L, 3.0 })     // { dg-warning "'template for' only available with" "" { target c++23_down } }
+    b += a;                                            // { dg-warning "this 'template for' clause does not guard\\.\\.\\." "" { target *-*-* } .-1 }
+    b++;                                               // { dg-message "\\.\\.\\.this statement, but the latter is misleadingly indented as if it were guarded by the 'template for'" }
+  return b;
+}