From ce17cff7f725fef6ed670ecf02ae92ee4dba79dc Mon Sep 17 00:00:00 2001 From: Yashas Date: Fri, 8 Jun 2018 21:17:11 +0530 Subject: [PATCH 1/2] trigger destructor not implemented error ``` #include forward operator~(Error:right[], size); main() { new Error:e; } ``` ``` CODE 0 ; 0 ;program exit point halt 0 proc ; main ; line 4 ; line 5 break ; c ;$lcl e fffffffc push.c 0 ;$exp push.pri push.c 1 addr.pri fffffffc push.pri push.c 8 call .~4000000f ; operator~(Error:) pop.pri stack 4 zero.pri retn STKSIZE 1000 ``` The compiler tries to call a non-existent function. This commit instead throws "function not implemented" error when destructor definition is missing. --- source/compiler/sc1.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/source/compiler/sc1.c b/source/compiler/sc1.c index 116a65e..655678b 100644 --- a/source/compiler/sc1.c +++ b/source/compiler/sc1.c @@ -4967,6 +4967,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 */ From 6e2f17fa5365cca5a349785dc5f2ce2e45a5fcb0 Mon Sep 17 00:00:00 2001 From: Yashas Date: Wed, 1 Aug 2018 14:11:45 +0530 Subject: [PATCH 2/2] add test for i310 --- source/compiler/tests/CMakeLists.txt | 6 ++++++ source/compiler/tests/destructor_not_impl_gh_310.pwn | 4 ++++ 2 files changed, 10 insertions(+) create mode 100644 source/compiler/tests/destructor_not_impl_gh_310.pwn diff --git a/source/compiler/tests/CMakeLists.txt b/source/compiler/tests/CMakeLists.txt index 2cf5a31..7f92852 100644 --- a/source/compiler/tests/CMakeLists.txt +++ b/source/compiler/tests/CMakeLists.txt @@ -70,6 +70,12 @@ set_tests_properties(const_array_args_and_literals_gh_276 PROPERTIES PASS_REGULA .*\\.pwn\\(41\\) : warning 239: literal array/string passed to a non-const parameter ") +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; +}