From 3c5269dede70a6dbe3ec40952595dd8c82d07a5e Mon Sep 17 00:00:00 2001 From: Kugel Fuhr <98353208+kugelfuhr@users.noreply.github.com> Date: Sun, 8 Sep 2024 09:11:47 +0200 Subject: [PATCH 1/2] Warn for braces around a pointer initializer. --- src/cc65/initdata.c | 7 +++++++ test/ref/bug2134.c | 2 ++ test/ref/bug2134.cref | 2 ++ 3 files changed, 11 insertions(+) create mode 100644 test/ref/bug2134.c create mode 100644 test/ref/bug2134.cref diff --git a/src/cc65/initdata.c b/src/cc65/initdata.c index 82cebefc2..addc7421b 100644 --- a/src/cc65/initdata.c +++ b/src/cc65/initdata.c @@ -302,6 +302,13 @@ static unsigned ParsePointerInit (const Type* T) /* Optional opening brace */ unsigned BraceCount = OpeningCurlyBraces (0); + /* We warn if an initializer for a scalar contains braces, because this is + ** quite unusual and often a sign for some problem in the input. + */ + if (BraceCount > 0) { + Warning ("Braces around scalar initializer"); + } + /* Expression */ ExprDesc ED = NoCodeConstExpr (hie1); TypeConversion (&ED, T); diff --git a/test/ref/bug2134.c b/test/ref/bug2134.c new file mode 100644 index 000000000..9e95e1daa --- /dev/null +++ b/test/ref/bug2134.c @@ -0,0 +1,2 @@ +int i = { 0 }; +char* p = { 0 }; diff --git a/test/ref/bug2134.cref b/test/ref/bug2134.cref new file mode 100644 index 000000000..72bbbad04 --- /dev/null +++ b/test/ref/bug2134.cref @@ -0,0 +1,2 @@ +bug2134.c:1: Warning: Braces around scalar initializer +bug2134.c:2: Warning: Braces around scalar initializer From d825a40add4ceb23c3b09840b6f0fe29ebe93b3a Mon Sep 17 00:00:00 2001 From: Kugel Fuhr <98353208+kugelfuhr@users.noreply.github.com> Date: Sun, 8 Sep 2024 09:36:40 +0200 Subject: [PATCH 2/2] The test needs a main() function. --- test/ref/bug2134.c | 1 + 1 file changed, 1 insertion(+) diff --git a/test/ref/bug2134.c b/test/ref/bug2134.c index 9e95e1daa..9dd1e5c55 100644 --- a/test/ref/bug2134.c +++ b/test/ref/bug2134.c @@ -1,2 +1,3 @@ int i = { 0 }; char* p = { 0 }; +int main() { return 0; }