From 154d84668b37c3051148b3df1568aa5e067ee281 Mon Sep 17 00:00:00 2001 From: Ryan Stecker Date: Wed, 17 Dec 2014 16:23:33 -0600 Subject: [PATCH] Old style retagging should emit a compiler warning when newdecls are required. --- sourcepawn/compiler/sc3.cpp | 6 +++++- sourcepawn/compiler/sc5-in.scp | 1 + .../compiler/tests/warn-oldstyle-cast.sp | 18 ++++++++++++++++++ .../compiler/tests/warn-oldstyle-cast.txt | 2 ++ 4 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 sourcepawn/compiler/tests/warn-oldstyle-cast.sp create mode 100644 sourcepawn/compiler/tests/warn-oldstyle-cast.txt diff --git a/sourcepawn/compiler/sc3.cpp b/sourcepawn/compiler/sc3.cpp index 7b5e6d00..d247978e 100644 --- a/sourcepawn/compiler/sc3.cpp +++ b/sourcepawn/compiler/sc3.cpp @@ -334,7 +334,7 @@ const char *type_to_name(int tag) const char *name = pc_tagname(tag); if (name) - return "unknown"; + return name; if (tag & FUNCTAG) return "function"; @@ -1698,6 +1698,10 @@ static int hier2(value *lval) } case tLABEL: /* tagname override */ tag=pc_addtag(st); + if (sc_require_newdecls) { + // Warn: old style cast used when newdecls pragma is enabled + error(240, st, type_to_name(tag)); + } lval->cmptag=tag; lvalue=hier2(lval); if ((lval->tag & OBJECTTAG) || (tag & OBJECTTAG)) { diff --git a/sourcepawn/compiler/sc5-in.scp b/sourcepawn/compiler/sc5-in.scp index 064ffd4b..0c8d1528 100644 --- a/sourcepawn/compiler/sc5-in.scp +++ b/sourcepawn/compiler/sc5-in.scp @@ -462,6 +462,7 @@ static const char *warnmsg[] = { /*237*/ "coercing functions to and from primitives is unsupported and will be removed in the future\n", /*238*/ "'%s:' is an illegal cast; use view_as<%s>(expression)\n", /*239*/ "'%s' is an illegal tag; use %s as a type\n", +/*240*/ "'%s:' is an old-style tag operation; use view_as<%s>(expression) instead\n", #else "\327 \275tr\242\231\227\266 %\204\305\206a\306\210\260", "\214\343i\215 \330\371\213t/\321cro \365", diff --git a/sourcepawn/compiler/tests/warn-oldstyle-cast.sp b/sourcepawn/compiler/tests/warn-oldstyle-cast.sp new file mode 100644 index 00000000..5f6c899c --- /dev/null +++ b/sourcepawn/compiler/tests/warn-oldstyle-cast.sp @@ -0,0 +1,18 @@ + +#pragma newdecls required + +enum MyType:{}; + +native void Print(MyType value); +native void PrintF(float value); + +public void main() +{ + int val = 2; + MyType otherVal = MyType:val; + + float value2 = Float:val; + + Print(otherVal); + PrintF(value2); +} diff --git a/sourcepawn/compiler/tests/warn-oldstyle-cast.txt b/sourcepawn/compiler/tests/warn-oldstyle-cast.txt new file mode 100644 index 00000000..21696a51 --- /dev/null +++ b/sourcepawn/compiler/tests/warn-oldstyle-cast.txt @@ -0,0 +1,2 @@ +(12) : warning 240: 'MyType:' is an old-style tag operation; use view_as(expression) instead +(14) : warning 240: 'Float:' is an old-style tag operation; use view_as(expression) instead