From 18db8da7df3c1493384f1e6b420b081784087b22 Mon Sep 17 00:00:00 2001
From: Michael Matz <matz@suse.de>
Date: Sat, 20 Jun 2020 23:17:02 +0200
Subject: [PATCH] Workaround old GCC viz indexed string literals

GCCs before gcc8 didn't deal with these where constants are
required.
---
 tests/tcctest.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/tests/tcctest.c b/tests/tcctest.c
index 73a90ca7..b6f266d5 100644
--- a/tests/tcctest.c
+++ b/tests/tcctest.c
@@ -480,12 +480,17 @@ int ret(a)
     return 0;
 }
 
+#if !defined(__TINYC__) && (__GNUC__ >= 8)
+/* Old GCCs don't regard "foo"[1] as constant, even in GNU dialect. */
+#define CONSTANTINDEXEDSTRLIT
+#endif
 char str_ag1[] = "b";
 char str_ag2[] = { "b" };
 /*char str_bg1[] = ("cccc"); GCC accepts this with pedantic warning, TCC not */
+#ifdef CONSTANTINDEXEDSTRLIT
 char str_ag3[] = { "ab"[1], 0 };
-char str_ag4[2] = { "b" };
 char str_x[2] = { "xy" "z"[2], 0 };
+#endif
 char *str_ar[] = { "one", "two" };
 struct str_SS {unsigned char a[3], b; };
 struct str_SS str_sinit15 = { "r" };
@@ -500,12 +505,15 @@ static void string_test2()
     char *pa2 = { "xyz" + 1 };
     int i = 0;
     struct str_SS ss = { { [0 ... 1] = 'a' }, 0 };
+#ifndef CONSTANTINDEXEDSTRLIT
+    char str_ag3[] = { "ab"[1], 0 };
+    char str_x[2] = { "xy" "z"[2], 0 };
+#endif
     puts("string_test2");
     puts(str_ag1);
     puts(str_ag2);
     /*puts(str_bg1);*/
     puts(str_ag3);
-    puts(str_ag4);
     puts(str_x);
     puts(str_sinit15.a);
     puts(str_sinit16[0].a);