Skip to content

Commit 360e748

Browse files
committed
suppress const warnings for internal array indexing
1 parent 7c4eeec commit 360e748

File tree

7 files changed

+53
-2
lines changed

7 files changed

+53
-2
lines changed

src/compiler/parser-expr-variable.bas

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ private function hFieldAccess _
179179
'' Dynamic array field; access the descriptor field (same offset)
180180
desc = symbGetArrayDescriptor( fld )
181181
varexpr = astNewBOP( AST_OP_ADD, varexpr, offsetexpr )
182-
varexpr = astNewCONV( typeAddrOf( symbGetFullType( desc ) ), symbGetSubtype( desc ), varexpr, AST_CONVOPT_DONTCHKPTR )
182+
varexpr = astNewCONV( typeAddrOf( symbGetFullType( desc ) ), symbGetSubtype( desc ), varexpr, AST_CONVOPT_DONTCHKPTR or AST_CONVOPT_DONTWARNCONST )
183183

184184
tree = NULL
185185
if( astHasSideFx( varexpr ) ) then
@@ -190,7 +190,7 @@ private function hFieldAccess _
190190

191191
'' *cptr( dtype ptr, var->descriptor.data + index )
192192
varexpr = astNewBOP( AST_OP_ADD, varexpr, astNewCONSTi( symb.fbarray_data ) )
193-
varexpr = astNewCONV( typeMultAddrOf( dtype, 2 ), subtype, varexpr, AST_CONVOPT_DONTCHKPTR )
193+
varexpr = astNewCONV( typeMultAddrOf( dtype, 2 ), subtype, varexpr, AST_CONVOPT_DONTCHKPTR or AST_CONVOPT_DONTWARNCONST )
194194
varexpr = astNewDEREF( varexpr )
195195
varexpr = astNewBOP( AST_OP_ADD, varexpr, indexexpr )
196196
varexpr = astNewDEREF( varexpr )

tests/warnings/const-discard.bas

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,3 +1014,29 @@ scope
10141014
WARN(0)
10151015
memcpy( x + i, xc, 5 )
10161016
end scope
1017+
1018+
'' --------------------------------------------------------
1019+
1020+
'' from https://www.freebasic.net/forum/viewtopic.php?p=254288#p254288
1021+
1022+
#print "---- Array in Const UDT"
1023+
1024+
type point
1025+
x as single
1026+
y as single
1027+
end type
1028+
1029+
type shape
1030+
points(any) as point
1031+
end type
1032+
1033+
sub const_udt_array( byref s as const shape )
1034+
WARN(0)
1035+
print lbound(s.points)
1036+
WARN(0)
1037+
print ubound(s.points)
1038+
WARN(0)
1039+
print @s.points(0)
1040+
WARN(0)
1041+
print s.points(0).x
1042+
end sub

tests/warnings/r/dos/const-discard.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,3 +415,8 @@ none expected
415415
none expected
416416
none expected
417417
none expected
418+
---- Array in Const UDT
419+
none expected
420+
none expected
421+
none expected
422+
none expected

tests/warnings/r/linux-x86/const-discard.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,3 +415,8 @@ none expected
415415
none expected
416416
none expected
417417
none expected
418+
---- Array in Const UDT
419+
none expected
420+
none expected
421+
none expected
422+
none expected

tests/warnings/r/linux-x86_64/const-discard.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,3 +415,8 @@ none expected
415415
none expected
416416
none expected
417417
none expected
418+
---- Array in Const UDT
419+
none expected
420+
none expected
421+
none expected
422+
none expected

tests/warnings/r/win32/const-discard.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,3 +415,8 @@ none expected
415415
none expected
416416
none expected
417417
none expected
418+
---- Array in Const UDT
419+
none expected
420+
none expected
421+
none expected
422+
none expected

tests/warnings/r/win64/const-discard.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,3 +415,8 @@ none expected
415415
none expected
416416
none expected
417417
none expected
418+
---- Array in Const UDT
419+
none expected
420+
none expected
421+
none expected
422+
none expected

0 commit comments

Comments
 (0)