diff --git a/.gitattributes b/.gitattributes index ef534cf480..21ec80552f 100644 --- a/.gitattributes +++ b/.gitattributes @@ -11149,6 +11149,7 @@ tests/test/cg/taddint.pp svneol=native#text/plain tests/test/cg/taddlong.pp svneol=native#text/plain tests/test/cg/taddr1.pp svneol=native#text/plain tests/test/cg/taddr2.pp svneol=native#text/plain +tests/test/cg/taddr3.pp svneol=native#text/plain tests/test/cg/taddreal1.pp svneol=native#text/plain tests/test/cg/taddreal2.pp svneol=native#text/plain tests/test/cg/taddreal3.pp svneol=native#text/plain diff --git a/compiler/pexpr.pas b/compiler/pexpr.pas index 217a1ef154..1cfe7ff2a4 100644 --- a/compiler/pexpr.pas +++ b/compiler/pexpr.pas @@ -583,9 +583,13 @@ implementation in_addr_x : begin consume(_LKLAMMER); - in_args:=true; - p1:=comp_expr(true,false); + got_addrn:=true; + p1:=factor(true,false,false); + { inside parentheses a full expression is allowed, see also tests\webtbs\tb27517.pp } + if token<>_RKLAMMER then + p1:=sub_expr(opcompare,true,false,p1); p1:=caddrnode.create(p1); + got_addrn:=false; consume(_RKLAMMER); statement_syssym:=p1; end; diff --git a/tests/test/cg/taddr3.pp b/tests/test/cg/taddr3.pp new file mode 100644 index 0000000000..e0ba75a716 --- /dev/null +++ b/tests/test/cg/taddr3.pp @@ -0,0 +1,28 @@ +program taddr3; + +{$ifndef FPC} +type + codepointer = pointer; +{$endif} + +procedure testproc; +begin +end; + +function testfunc: codepointer; +begin + testfunc:=nil; +end; + +var + p1, p2: codepointer; +begin + p1 := @testproc; + p2 := Addr(testproc); + if p1<>p2 then + Halt(1); + p1 := @testfunc; + p2 := Addr(testfunc); + if p1<>p2 then + Halt(2); +end.