Disallow retagging enums or using implicit-int as an enum tag.
This commit is contained in:
parent
f573bdf784
commit
673ff572c5
@ -4593,14 +4593,20 @@ static void decl_enum(int vclass)
|
|||||||
* pc_addtag() here
|
* pc_addtag() here
|
||||||
*/
|
*/
|
||||||
if (lex(&val,&str)==tLABEL) {
|
if (lex(&val,&str)==tLABEL) {
|
||||||
int flags = ENUMTAG;
|
if (pc_findtag(str) == 0) {
|
||||||
if (isupper(*str))
|
error(169);
|
||||||
flags |= FIXEDTAG;
|
tag = 0;
|
||||||
tag = pc_addtag_flags(str, flags);
|
explicittag = FALSE;
|
||||||
spec = deduce_layout_spec_by_tag(tag);
|
} else {
|
||||||
if (!can_redef_layout_spec(spec, Layout_Enum))
|
int flags = ENUMTAG;
|
||||||
error(110, str, layout_spec_name(spec));
|
if (isupper(*str))
|
||||||
explicittag=TRUE;
|
flags |= FIXEDTAG;
|
||||||
|
tag = pc_addtag_flags(str, flags);
|
||||||
|
spec = deduce_layout_spec_by_tag(tag);
|
||||||
|
if (!can_redef_layout_spec(spec, Layout_Enum))
|
||||||
|
error(110, str, layout_spec_name(spec));
|
||||||
|
explicittag=TRUE;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
lexpush();
|
lexpush();
|
||||||
tag=0;
|
tag=0;
|
||||||
@ -4619,6 +4625,8 @@ static void decl_enum(int vclass)
|
|||||||
if (!can_redef_layout_spec(spec, Layout_Enum))
|
if (!can_redef_layout_spec(spec, Layout_Enum))
|
||||||
error(110, enumname, layout_spec_name(spec));
|
error(110, enumname, layout_spec_name(spec));
|
||||||
} else {
|
} else {
|
||||||
|
error(168);
|
||||||
|
|
||||||
spec = deduce_layout_spec_by_name(enumname);
|
spec = deduce_layout_spec_by_name(enumname);
|
||||||
if (!can_redef_layout_spec(spec, Layout_Enum))
|
if (!can_redef_layout_spec(spec, Layout_Enum))
|
||||||
error(110, enumname, layout_spec_name(spec));
|
error(110, enumname, layout_spec_name(spec));
|
||||||
|
@ -210,7 +210,9 @@ static const char *errmsg[] = {
|
|||||||
/*164*/ "allocated array type '%s' doesn't match original type '%s'\n",
|
/*164*/ "allocated array type '%s' doesn't match original type '%s'\n",
|
||||||
/*165*/ "cannot create dynamic arrays in static scope - did you mean to create a fixed-length array with brackets after the variable name?\n",
|
/*165*/ "cannot create dynamic arrays in static scope - did you mean to create a fixed-length array with brackets after the variable name?\n",
|
||||||
/*166*/ "cannot use 'this' outside of a methodmap method or property\n",
|
/*166*/ "cannot use 'this' outside of a methodmap method or property\n",
|
||||||
/*167*/ "cannot use delete, %s do not have destructors\n",
|
/*167*/ "cannot use delete, %s do not have destructors\n",
|
||||||
|
/*168*/ "re-tagging enums is no longer supported\n",
|
||||||
|
/*169*/ "cannot tag an enum as implicit-int\n",
|
||||||
#else
|
#else
|
||||||
"\315e\306\227\266k\217:\235\277bu\201fo\220\204\223\012",
|
"\315e\306\227\266k\217:\235\277bu\201fo\220\204\223\012",
|
||||||
"\202l\224\250s\205g\346\356e\233\201(\243\315\214\267\202) \253 f\255low ea\305 \042c\353e\042\012",
|
"\202l\224\250s\205g\346\356e\233\201(\243\315\214\267\202) \253 f\255low ea\305 \042c\353e\042\012",
|
||||||
|
23
sourcepawn/compiler/tests/fail-tag-enum-as-implicit-int.sp
Normal file
23
sourcepawn/compiler/tests/fail-tag-enum-as-implicit-int.sp
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
native Float:float(x);
|
||||||
|
native Float:FloatMul(Float:oper1, Float:oper2);
|
||||||
|
|
||||||
|
stock Float:operator*(Float:oper1, oper2)
|
||||||
|
{
|
||||||
|
return FloatMul(oper1, float(oper2));
|
||||||
|
}
|
||||||
|
|
||||||
|
native Float:GetRandomFloat();
|
||||||
|
|
||||||
|
enum _:Rocketeer {
|
||||||
|
bool:bActivated,
|
||||||
|
iRockets[20]
|
||||||
|
};
|
||||||
|
|
||||||
|
public OnPluginStart()
|
||||||
|
{
|
||||||
|
decl Float:fAngles[3];
|
||||||
|
|
||||||
|
fAngles[0] = GetRandomFloat() * 360;
|
||||||
|
fAngles[1] = GetRandomFloat() * 360;
|
||||||
|
fAngles[2] = GetRandomFloat() * 360;
|
||||||
|
}
|
@ -0,0 +1 @@
|
|||||||
|
(11) : error 169: cannot tag an enum as implicit-int
|
Loading…
Reference in New Issue
Block a user