summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjonas <jonas@3ad0048d-3df7-0310-abae-a5850022a9f2>2021-04-10 10:56:02 +0000
committerjonas <jonas@3ad0048d-3df7-0310-abae-a5850022a9f2>2021-04-10 10:56:02 +0000
commit22f28adf30c02acc719b905fd005e95c6305967b (patch)
tree939cdb76e5a3d493973699dcaed1773845bdb017
parentfaab385f28c8c2c66521dcb1be6ed9ccb0fd02ab (diff)
downloadfpc-22f28adf30c02acc719b905fd005e95c6305967b.tar.gz
* fix conversion of true/false macro definitions to boolean values
(mantis #38492) o since the macro lookups are recursive, "mac" will usually be nil afterwards (unless we found an undefined macro) git-svn-id: https://svn.freepascal.org/svn/fpc/trunk@49160 3ad0048d-3df7-0310-abae-a5850022a9f2
-rw-r--r--compiler/scanner.pas7
-rw-r--r--tests/webtbs/tw38492.pp13
2 files changed, 18 insertions, 2 deletions
diff --git a/compiler/scanner.pas b/compiler/scanner.pas
index 649d2bc75a..b33f7a73c5 100644
--- a/compiler/scanner.pas
+++ b/compiler/scanner.pas
@@ -1649,6 +1649,7 @@ type
mac: tmacro;
macrocount,
len: integer;
+ foundmacro: boolean;
begin
if not eval then
begin
@@ -1657,6 +1658,7 @@ type
end;
mac:=nil;
+ foundmacro:=false;
{ Substitue macros and compiler variables with their content/value.
For real macros also do recursive substitution. }
macrocount:=0;
@@ -1684,6 +1686,7 @@ type
move(mac.buftext^,hs[1],len);
searchstr:=upcase(hs);
mac.is_used:=true;
+ foundmacro:=true;
end
else
begin
@@ -1702,9 +1705,9 @@ type
result:=texprvalue.try_parse_number(searchstr);
if not assigned(result) then
begin
- if assigned(mac) and (searchstr='FALSE') then
+ if foundmacro and (searchstr='FALSE') then
result:=texprvalue.create_bool(false)
- else if assigned(mac) and (searchstr='TRUE') then
+ else if foundmacro and (searchstr='TRUE') then
result:=texprvalue.create_bool(true)
else if (m_mac in current_settings.modeswitches) and
(not assigned(mac) or not mac.defined) and
diff --git a/tests/webtbs/tw38492.pp b/tests/webtbs/tw38492.pp
new file mode 100644
index 0000000000..0376165388
--- /dev/null
+++ b/tests/webtbs/tw38492.pp
@@ -0,0 +1,13 @@
+{ %opt=-Sm -dmydefine:=false }
+
+{$mode macpas}
+{$setc def := mydefine}
+program setcbug;
+begin
+{$ifc def}
+ writeln( 'mydefine is true')
+ halt(1);
+{$elsec}
+ writeln( 'mydefine is false')
+{$endc}
+end.