summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorflorian <florian@3ad0048d-3df7-0310-abae-a5850022a9f2>2021-04-25 19:49:26 +0000
committerflorian <florian@3ad0048d-3df7-0310-abae-a5850022a9f2>2021-04-25 19:49:26 +0000
commit8d4e1bf0c2fd6635c735b42aebc3fe0645f270bf (patch)
tree747a5a117190d5240da1a995fe97a8c6deae0b90
parent39aa8a14702f49b1d129b181c411823cf82177f2 (diff)
downloadfpc-8d4e1bf0c2fd6635c735b42aebc3fe0645f270bf.tar.gz
* decrease macro nesting counter early when expanding empty macro
to avoid errors about too depth macro nesting, resolves #38802 git-svn-id: https://svn.freepascal.org/svn/fpc/trunk@49265 3ad0048d-3df7-0310-abae-a5850022a9f2
-rw-r--r--compiler/scanner.pas19
-rw-r--r--tests/webtbs/tw38802.pp24
2 files changed, 38 insertions, 5 deletions
diff --git a/compiler/scanner.pas b/compiler/scanner.pas
index b33f7a73c5..9632471f24 100644
--- a/compiler/scanner.pas
+++ b/compiler/scanner.pas
@@ -4883,12 +4883,21 @@ type
inc(yylexcount);
substitutemacro(pattern,mac.buftext,mac.buflen,
mac.fileinfo.line,mac.fileinfo.fileindex);
- { handle empty macros }
+ { handle empty macros }
if c=#0 then
- reload;
- readtoken(false);
- { that's all folks }
- dec(yylexcount);
+ begin
+ reload;
+ { avoid macro nesting error in case of
+ a sequence of empty macros, see #38802 }
+ dec(yylexcount);
+ readtoken(false);
+ end
+ else
+ begin
+ readtoken(false);
+ { that's all folks }
+ dec(yylexcount);
+ end;
exit;
end
else
diff --git a/tests/webtbs/tw38802.pp b/tests/webtbs/tw38802.pp
new file mode 100644
index 0000000000..87237eb77b
--- /dev/null
+++ b/tests/webtbs/tw38802.pp
@@ -0,0 +1,24 @@
+{$mode objfpc} {$h+} {$macro on}
+
+begin
+ // Warning: Expanding of macros exceeds a depth of 16.
+ // If macros contain any source code (barring comments and directives) — even 'begin end;', this will compile.
+ {$define do_A :=}
+ {$define do_B :=}
+ {$define do_C :=}
+ {$define do_D :=}
+ {$define do_E :=}
+ {$define do_F :=}
+ {$define do_G :=}
+ {$define do_H :=}
+ {$define do_I :=}
+ {$define do_J :=}
+ {$define do_K :=}
+ {$define do_L :=}
+ {$define do_M :=}
+ {$define do_N :=}
+ {$define do_O :=}
+ {$define do_P :=}
+ {$define do_Q :=}
+ do_A do_B do_C do_D do_E do_F do_G do_H do_I do_J do_K do_L do_M do_N do_O do_P do_Q
+end.