diff --git a/source/compiler/sc1.c b/source/compiler/sc1.c index b1ad703..df51854 100644 --- a/source/compiler/sc1.c +++ b/source/compiler/sc1.c @@ -3917,6 +3917,8 @@ static int declargs(symbol *sym,int chkshadow) case '&': if (ident!=iVARIABLE || numtags>0) error(1,"-identifier-","&"); + if (fconst) + error(238, "const reference"); /* meaningless combination of class specifiers */ ident=iREFERENCE; break; case tCONST: @@ -3991,6 +3993,8 @@ static int declargs(symbol *sym,int chkshadow) case tELLIPS: if (ident!=iVARIABLE) error(10); /* illegal function or declaration */ + if (fconst) + error(238, "const variable arguments"); /* meaningless combination of class specifiers */ if (numtags==0) tags[numtags++]=0; /* default tag */ if ((sym->usage & uPROTOTYPED)==0) { diff --git a/source/compiler/sc5.c b/source/compiler/sc5.c index c6af5a7..3f91485 100644 --- a/source/compiler/sc5.c +++ b/source/compiler/sc5.c @@ -191,7 +191,8 @@ static char *warnmsg[] = { /*234*/ "function is deprecated (symbol \"%s\") %s\n", /*235*/ "public function lacks forward declaration (symbol \"%s\")\n", /*236*/ "unknown parameter in substitution (incorrect #define pattern)\n", -/*237*/ "user warning: %s\n" +/*237*/ "user warning: %s\n", +/*238*/ "meaningless combination of class specifiers (%s)\n" }; #define NUM_WARNINGS (sizeof warnmsg / sizeof warnmsg[0]) diff --git a/source/compiler/tests/CMakeLists.txt b/source/compiler/tests/CMakeLists.txt index 9b3d52c..55ce454 100644 --- a/source/compiler/tests/CMakeLists.txt +++ b/source/compiler/tests/CMakeLists.txt @@ -48,6 +48,12 @@ set_tests_properties(gh_283 PROPERTIES PASS_REGULAR_EXPRESSION "\ add_compiler_test(too_many_args_crash_gh_298 ${CMAKE_CURRENT_SOURCE_DIR}/too_many_args_crash_gh_298.pwn) set_tests_properties(too_many_args_crash_gh_298 PROPERTIES PASS_REGULAR_EXPRESSION "too many function arguments") +add_compiler_test(meaningless_class_specifiers_gh_172 ${CMAKE_CURRENT_SOURCE_DIR}/meaningless_class_specifiers_gh_172.pwn) +set_tests_properties(meaningless_class_specifiers_gh_172 PROPERTIES PASS_REGULAR_EXPRESSION "\ +.*\\.pwn\\(1\\) : warning 238: meaningless combination of class specifiers \\(const reference\\)\ +.*\\.pwn\\(1 \\-\\- 2\\) : warning 238: meaningless combination of class specifiers \\(const variable arguments\\)\ +") + # Crashers # # These tests simply check that the compiler doesn't crash. diff --git a/source/compiler/tests/meaningless_class_specifiers_gh_172.pwn b/source/compiler/tests/meaningless_class_specifiers_gh_172.pwn new file mode 100755 index 0000000..68bfd02 --- /dev/null +++ b/source/compiler/tests/meaningless_class_specifiers_gh_172.pwn @@ -0,0 +1,20 @@ +f1(const &v) { } +f2(const ...) { } +f3(const v) { + #pragma unused v +} +f4(...) { } +f5(v) { + #pragma unused v +} +f6(&v) { } + +main() { + new a; + f1(a); + f2(a); + f3(a); + f4(a); + f5(a); + f6(a); +} \ No newline at end of file