This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug fortran/46328] [OOP] type-bound operator call with non-trivial polymorphic operand


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46328

--- Comment #11 from Tobias Burnus <burnus at gcc dot gnu.org> 2012-01-06 18:06:37 UTC ---
The following patchlet fixes the issue of comment 2 [or at least, the program
now compiles]; it does not fix the issue of comment 0 / comment 4.

Regarding the latter:

One gets now a segfault for:
  at 0x50C5A0: gfc_add_component_ref(gfc_expr*, char const*) (class.c:63)
  by 0x57BDFC: resolve_typebound_function(gfc_expr*) (resolve.c:5958)
  by 0x573D74: gfc_resolve_expr(gfc_expr*) (resolve.c:6280)

which is because of:
63        gfc_symbol *derived = e->symtree->n.sym->ts.u.derived;
which fails as we have: e->expr_type == EXPR_FUNCTION


If one adds to the example in comment 2:
  use foo_module
  class(foo), pointer :: xx
  xx = xx * 4
  end
one gets:
  Error: Operands of binary numeric operator '*' at (1)
         are CLASS(foo)/INTEGER(4)
I have not checked whether that's correct or whether it should have worked.


--- a/gcc/fortran/interface.c
+++ b/gcc/fortran/interface.c
@@ -3172,3 +3172,6 @@ matching_typebound_op (gfc_expr** tb_base,
          {
-           if (!gfc_expr_attr (base->expr).class_ok)
+           if ((base->expr->expr_type == EXPR_VARIABLE
+                && !gfc_expr_attr (base->expr).class_ok)
+               || (base->expr->expr_type != EXPR_VARIABLE
+                   && !base->expr->ts.u.derived->components))
              continue;
diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c
index 79245ce..8d02d6e 100644
--- a/gcc/fortran/resolve.c
+++ b/gcc/fortran/resolve.c
@@ -5685,4 +5685,6 @@ get_declared_from_expr (gfc_ref **class_ref, gfc_ref
**new_ref,

-  if (declared == NULL)
+  if (declared == NULL && e->expr_type == EXPR_VARIABLE)
     declared = e->symtree->n.sym->ts.u.derived;
+  else
+    declared = e->ts.u.derived;


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]