diff --git a/source/compiler/sc1.c b/source/compiler/sc1.c index 09d25df..616da3c 100644 --- a/source/compiler/sc1.c +++ b/source/compiler/sc1.c @@ -4971,6 +4971,14 @@ static void destructsymbols(symbol *root,int level) /* check that the '~' operator is defined for this tag */ operator_symname(symbolname,"~",sym->tag,0,1,0); if ((opsym=findglb(symbolname,sGLOBAL))!=NULL) { + if ((opsym->usage & uMISSING)!=0 || (opsym->usage & uPROTOTYPED)==0) { + char symname[2*sNAMEMAX+16]; /* allow space for user defined operators */ + funcdisplayname(symname,opsym->name); + if ((opsym->usage & uMISSING)!=0) + error(4,symname); /* function not defined */ + if ((opsym->usage & uPROTOTYPED)==0) + error(71,symname); /* operator must be declared before use */ + } /* if */ /* save PRI, in case of a return statment */ if (!savepri) { pushreg(sPRI); /* right-hand operand is in PRI */ diff --git a/source/compiler/tests/CMakeLists.txt b/source/compiler/tests/CMakeLists.txt index b1538ce..02110b4 100644 --- a/source/compiler/tests/CMakeLists.txt +++ b/source/compiler/tests/CMakeLists.txt @@ -80,6 +80,12 @@ set_tests_properties(md_array_size_chk_gh_314 PROPERTIES PASS_REGULAR_EXPRESSION ") set_tests_properties(md_array_size_chk_gh_314 PROPERTIES WILL_FAIL TRUE) +add_compiler_test(destructor_not_impl_gh_310 ${CMAKE_CURRENT_SOURCE_DIR}/destructor_not_impl_gh_310.pwn) +set_tests_properties(destructor_not_impl_gh_310 PROPERTIES PASS_REGULAR_EXPRESSION +".*\\.pwn\\(6\\) : error 004: function \"operator~(Error:)\" is not implemented +") +set_tests_properties(destructor_not_impl_gh_310 PROPERTIES WILL_FAIL TRUE) + # Crashers # # These tests simply check that the compiler doesn't crash. diff --git a/source/compiler/tests/destructor_not_impl_gh_310.pwn b/source/compiler/tests/destructor_not_impl_gh_310.pwn new file mode 100644 index 0000000..7855e78 --- /dev/null +++ b/source/compiler/tests/destructor_not_impl_gh_310.pwn @@ -0,0 +1,4 @@ +forward operator~(Error:right[], size); +main() { + new Error:e; +}