https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103414

--- Comment #4 from kargl at gcc dot gnu.org ---
This fixes/catches the type mismatch in the issue raised in comment #1.

diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c
index 705d2326a29..0a864da015b 100644
--- a/gcc/fortran/resolve.c
+++ b/gcc/fortran/resolve.c
@@ -1231,9 +1237,17 @@ get_pdt_constructor (gfc_expr *expr, gfc_constructor
**constr,
          if (!t)
            return t;
        }
-     else if ((comp->attr.pdt_kind || comp->attr.pdt_len)
+      else if ((comp->attr.pdt_kind || comp->attr.pdt_len)
               && derived->attr.pdt_template)
        {
+         if (comp->ts.type != cons->expr->ts.type)
+           {
+             gfc_error ("Type mismatch for a type parameter and an entity "
+                        "at %L in the structure constructor",
+                        &cons->expr->where);
+             return false;
+           }
+
          t = get_pdt_spec_expr (comp, cons->expr);
          if (!t)
            return t;

Reply via email to