From 2b9d332580283b976bb7adb7432bd77bda5dc9b4 Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Sun, 22 Aug 2021 20:33:34 -0500 Subject: [PATCH] Give an appropriate error for an illegal operator in a constant expression. This was being reported as an "illegal type cast". --- Expression.pas | 2 +- Scanner.pas | 1 + cc.notes | 2 ++ 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Expression.pas b/Expression.pas index 88e6cf4..474c722 100644 --- a/Expression.pas +++ b/Expression.pas @@ -2163,7 +2163,7 @@ if token.kind in startExpression then begin and (token.kind = sizeofsy)) or ((kind <> initializerExpression) and (token.kind = uand)) then begin - Error(40); + Error(161); errorFound := true; end; {if} if token.kind in {make sure we get what we want} diff --git a/Scanner.pas b/Scanner.pas index 4057b20..2c0c881 100644 --- a/Scanner.pas +++ b/Scanner.pas @@ -714,6 +714,7 @@ if list or (numErr <> 0) then begin 158: msg := @'_Generic expression includes two compatible types'; 159: msg := @'_Generic expression includes multiple default cases'; 160: msg := @'no matching association in _Generic expression'; + 161: msg := @'illegal operator in a constant expression'; otherwise: Error(57); end; {case} writeln(msg^); diff --git a/cc.notes b/cc.notes index 42902c6..4ed80d8 100644 --- a/cc.notes +++ b/cc.notes @@ -1196,6 +1196,8 @@ int foo(int[42]); 157. An error was not reported if code tried to define an enumeration constant with a value in the range 0xFFFF8000 to 0xFFFFFFFF. (Enumeration constants are limited to values representable as an int.) +158. An "illegal type cast" error would be reported when an illegal operator was used in a constant expression. An appropriate error message is now produced. + -- Bugs from C 2.1.0 that have been fixed ----------------------------------- 1. In some situations, fread() reread the first 1K or so of the file.