Browse Source

Fix for Mantis #30729: don't allow other names for class constructors or destructors than Create and Destroy respectively.

+ added tests

git-svn-id: trunk@34712 -
svenbarth 8 years ago
parent
commit
4e5ed5b0e2
5 changed files with 57 additions and 2 deletions
  1. 2 0
      .gitattributes
  2. 7 1
      compiler/msg/errore.msg
  3. 8 1
      compiler/pdecsub.pas
  4. 20 0
      tests/webtbf/tw30729a.pp
  5. 20 0
      tests/webtbf/tw30729b.pp

+ 2 - 0
.gitattributes

@@ -13739,6 +13739,8 @@ tests/webtbf/tw3000.pp svneol=native#text/plain
 tests/webtbf/tw30022.pp svneol=native#text/plain
 tests/webtbf/tw30022.pp svneol=native#text/plain
 tests/webtbf/tw3047.pp svneol=native#text/plain
 tests/webtbf/tw3047.pp svneol=native#text/plain
 tests/webtbf/tw30494.pp svneol=native#text/pascal
 tests/webtbf/tw30494.pp svneol=native#text/pascal
+tests/webtbf/tw30729a.pp svneol=native#text/pascal
+tests/webtbf/tw30729b.pp svneol=native#text/pascal
 tests/webtbf/tw3114.pp svneol=native#text/plain
 tests/webtbf/tw3114.pp svneol=native#text/plain
 tests/webtbf/tw3116.pp svneol=native#text/plain
 tests/webtbf/tw3116.pp svneol=native#text/plain
 tests/webtbf/tw3126.pp svneol=native#text/plain
 tests/webtbf/tw3126.pp svneol=native#text/plain

+ 7 - 1
compiler/msg/errore.msg

@@ -2004,7 +2004,7 @@ type_e_function_reference_kind=04123_E_Subroutine references cannot be declared
 #
 #
 # Symtable
 # Symtable
 #
 #
-# 05095 is the last used one
+# 05097 is the last used one
 #
 #
 % \section{Symbol handling}
 % \section{Symbol handling}
 % This section lists all the messages that concern the handling of symbols.
 % This section lists all the messages that concern the handling of symbols.
@@ -2313,6 +2313,12 @@ sym_w_duplicate_id=05095_W_Duplicate identifier "$1"
 % same scope as the current identifier. This is a warning instead of an error,
 % same scope as the current identifier. This is a warning instead of an error,
 % because while this hides the identifier from the category, there are often
 % because while this hides the identifier from the category, there are often
 % many unused categories in scope.
 % many unused categories in scope.
+sym_e_class_constructor_must_be_create=05096_E_Class constructor must be named "Create"
+% The name of a class constructor must be "Create" (case insensitive of course)
+% as there can be only one per class anyway.
+sym_e_class_destructor_must_be_destroy=05097_E_Class destructor must be named "Destroy"
+% The name of a class destructor must be "Destroy" (case insensitive of cours)
+% as there can be only one per class anyway.
 % \end{description}
 % \end{description}
 #
 #
 # Codegenerator
 # Codegenerator

+ 8 - 1
compiler/pdecsub.pas

@@ -1053,7 +1053,14 @@ implementation
                   end
                   end
                 else
                 else
                 if (potype in [potype_class_constructor,potype_class_destructor]) then
                 if (potype in [potype_class_constructor,potype_class_destructor]) then
-                  aprocsym:=cprocsym.create('$'+lower(sp))
+                  begin
+                    sp:=lower(sp);
+                    if (potype=potype_class_constructor) and (sp<>'create') then
+                      message(sym_e_class_constructor_must_be_create);
+                    if (potype=potype_class_destructor) and (sp<>'destroy') then
+                      message(sym_e_class_destructor_must_be_destroy);
+                    aprocsym:=cprocsym.create('$'+sp)
+                  end
                 else
                 else
                   aprocsym:=cprocsym.create(orgsp);
                   aprocsym:=cprocsym.create(orgsp);
                 symtablestack.top.insert(aprocsym);
                 symtablestack.top.insert(aprocsym);

+ 20 - 0
tests/webtbf/tw30729a.pp

@@ -0,0 +1,20 @@
+{ %FAIL }
+
+{ class constructors *must* be named "Create" }
+
+program tw30729a;
+
+{$mode objfpc}
+
+type
+  TTest = class
+    class constructor Create2;
+  end;
+
+class constructor TTest.Create2;
+begin
+end;
+
+begin
+
+end.

+ 20 - 0
tests/webtbf/tw30729b.pp

@@ -0,0 +1,20 @@
+{ %FAIL }
+
+{ class destructors *must* be named "Destroy" }
+
+program tw30729b;
+
+{$mode objfpc}
+
+type
+  TTest = class
+    class destructor Destroy2;
+  end;
+
+class destructor TTest.Destroy2;
+begin
+end;
+
+begin
+
+end.