Skip to content

Commit 4b19bbb

Browse files
committed
Don't issue warning 204 if the assignment operator is overloaded
1 parent c03aa50 commit 4b19bbb

File tree

5 files changed

+25
-4
lines changed

5 files changed

+25
-4
lines changed

source/compiler/sc.h

+1
Original file line numberDiff line numberDiff line change
@@ -925,6 +925,7 @@ SC_VDECL short fnumber; /* number of files in the file table (debugging) *
925925
SC_VDECL short fcurrent; /* current file being processed (debugging) */
926926
SC_VDECL short sc_intest; /* true if inside a test */
927927
SC_VDECL int pc_sideeffect; /* true if an expression causes a side-effect */
928+
SC_VDECL int pc_ovlassignment;/* true if an expression contains an overloaded assignment */
928929
SC_VDECL int stmtindent; /* current indent of the statement */
929930
SC_VDECL int indent_nowarn; /* skip warning "217 loose indentation" */
930931
SC_VDECL int sc_tabsize; /* number of spaces that a TAB represents */

source/compiler/sc1.c

+5-1
Original file line numberDiff line numberDiff line change
@@ -891,6 +891,7 @@ static void resetglobals(void)
891891
fcurrent=0; /* current file being processed (debugging) */
892892
sc_intest=FALSE; /* true if inside a test */
893893
pc_sideeffect=0; /* true if an expression causes a side-effect */
894+
pc_ovlassignment=FALSE;/* true if an expression contains an overloaded assignment */
894895
stmtindent=0; /* current indent of the statement */
895896
indent_nowarn=FALSE; /* do not skip warning "217 loose indentation" */
896897
sc_allowtags=TRUE; /* allow/detect tagnames */
@@ -2380,7 +2381,7 @@ static int declloc(int fstatic)
23802381
lval.ident=iVARIABLE;
23812382
lval.constval=0;
23822383
lval.tag=tag;
2383-
check_userop(NULL,ctag,lval.tag,2,NULL,&ctag);
2384+
suppress_w240 |= check_userop(NULL,ctag,lval.tag,2,NULL,&ctag);
23842385
store(&lval);
23852386
markexpr(sEXPR,NULL,0); /* full expression ends after the store */
23862387
assert(staging); /* end staging phase (optimize expression) */
@@ -2426,6 +2427,8 @@ static int declloc(int fstatic)
24262427
} /* if */
24272428
if (explicit_init)
24282429
markinitialized(sym,!suppress_w240);
2430+
if (pc_ovlassignment)
2431+
sym->usage |= uREAD;
24292432
} while (matchtoken(',')); /* enddo */ /* more? */
24302433
needtoken(tTERM); /* if not comma, must be semicolumn */
24312434
return ident;
@@ -5535,6 +5538,7 @@ static int doexpr(int comma,int chkeffect,int allowarray,int mark_endexpr,
55355538
if (index!=stgidx)
55365539
markexpr(sEXPR,NULL,0);
55375540
pc_sideeffect=FALSE;
5541+
pc_ovlassignment=FALSE;
55385542
ident=expression(val,tag,symptr,chkfuncresult);
55395543
if (!allowarray && (ident==iARRAY || ident==iREFARRAY))
55405544
error(33,"-unknown-"); /* array must be indexed */

source/compiler/sc3.c

+5-3
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,8 @@ static void (*unopers[])(void) = { lneg, neg, user_inc, user_dec };
190190
if (sym==NULL /*|| (sym->usage & uDEFINE)==0*/)
191191
return FALSE;
192192
} /* if */
193+
if (oper==NULL)
194+
pc_ovlassignment=TRUE;
193195

194196
/* check existance and the proper declaration of this function */
195197
if ((sym->usage & uMISSING)!=0 || (sym->usage & uPROTOTYPED)==0) {
@@ -823,7 +825,6 @@ static int hier14(value *lval1)
823825
int bwcount,leftarray;
824826
cell arrayidx1[sDIMEN_MAX],arrayidx2[sDIMEN_MAX]; /* last used array indices */
825827
cell *org_arrayidx;
826-
int assignment=FALSE;
827828

828829
bwcount=bitwise_opercount;
829830
bitwise_opercount=0;
@@ -879,7 +880,6 @@ static int hier14(value *lval1)
879880
break;
880881
case '=': /* simple assignment */
881882
oper=NULL;
882-
assignment=TRUE;
883883
if (sc_intest)
884884
error(211); /* possibly unintended assignment */
885885
break;
@@ -1065,12 +1065,14 @@ static int hier14(value *lval1)
10651065
pc_sideeffect=TRUE;
10661066
bitwise_opercount=bwcount;
10671067
lval1->ident=iEXPRESSION;
1068-
if (assignment) {
1068+
if (oper==NULL) {
10691069
symbol *sym=lval3.sym;
10701070
assert(sym!=NULL);
10711071
if ((sym->usage & uASSIGNED)!=0 && (sym->vclass==sLOCAL || sym->vclass==sSTATIC))
10721072
error(240,sym->name); /* previously assigned value is unused */
10731073
markinitialized(sym,TRUE);
1074+
if (pc_ovlassignment)
1075+
markusage(sym,uREAD);
10741076
} /* if */
10751077
return FALSE; /* expression result is never an lvalue */
10761078
}

source/compiler/scvars.c

+1
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ SC_VDEFINE short fnumber=0; /* the file number in the file table
8080
SC_VDEFINE short fcurrent=0; /* current file being processed (debugging) */
8181
SC_VDEFINE short sc_intest=FALSE; /* true if inside a test */
8282
SC_VDEFINE int pc_sideeffect=0; /* true if an expression causes a side-effect */
83+
SC_VDEFINE int pc_ovlassignment=FALSE; /* true if an expression contains an overloaded assignment */
8384
SC_VDEFINE int stmtindent=0; /* current indent of the statement */
8485
SC_VDEFINE int indent_nowarn=FALSE; /* skip warning "217 loose indentation" */
8586
SC_VDEFINE int sc_tabsize=8; /* number of spaces that a TAB represents */

source/compiler/tests/warning_240.pwn

+13
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,18 @@ test_arg(arg)
5050
arg = 1; // warning 240, warning 204
5151
}
5252

53+
stock Tag:operator =(oper)
54+
return Tag:oper;
55+
56+
test_ovl_assignment()
57+
{
58+
// Overloaded assignments are essentially function calls which may have
59+
// desirable side effects, so they shouldn't trigger warning 204.
60+
new Tag:a = 1;
61+
new Tag:b;
62+
b = 2;
63+
}
64+
5365
main()
5466
{
5567
test_local();
@@ -58,4 +70,5 @@ main()
5870
test_global_static();
5971
new x = 0;
6072
test_arg(x);
73+
test_ovl_assignment();
6174
}

0 commit comments

Comments
 (0)