aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Kargl <kargl@gcc.gnu.org>2022-12-17 19:15:43 -0800
committerJerry DeLisle <jvdelisle@gcc.gnu.org>2022-12-17 19:36:59 -0800
commit09710f9934969dcb07131e1ed78b72e648123a3a (patch)
tree02d6fe0b2c3fd3e7d27744d3c4a2abc942f443c0
parent92bc3617572dd1f0ab22729b3c54a263668dbf52 (diff)
downloadgcc-09710f9934969dcb07131e1ed78b72e648123a3a.zip
gcc-09710f9934969dcb07131e1ed78b72e648123a3a.tar.gz
gcc-09710f9934969dcb07131e1ed78b72e648123a3a.tar.bz2
Add a check for invalid use of BOZ with a derived type.
PR fortran/107397 gcc/fortran/ChangeLog: * decl.cc (add_init_expr_to_sym): Add check with new error message. gcc/testsuite/ChangeLog: * gfortran.dg/pr107397.f90: New test.
-rw-r--r--gcc/fortran/decl.cc8
-rw-r--r--gcc/testsuite/gfortran.dg/pr107397.f909
2 files changed, 17 insertions, 0 deletions
diff --git a/gcc/fortran/decl.cc b/gcc/fortran/decl.cc
index 0f9b2ce..1562dc2 100644
--- a/gcc/fortran/decl.cc
+++ b/gcc/fortran/decl.cc
@@ -2221,6 +2221,14 @@ add_init_expr_to_sym (const char *name, gfc_expr **initp, locus *var_locus)
sym->ts.f90_type = init->ts.f90_type;
}
+ /* Catch the case: type(t), parameter :: x = z'1'. */
+ if (sym->ts.type == BT_DERIVED && init->ts.type == BT_BOZ)
+ {
+ gfc_error ("Entity %qs at %L is incompatible with a BOZ "
+ "literal constant", name, &sym->declared_at);
+ return false;
+ }
+
/* Add initializer. Make sure we keep the ranks sane. */
if (sym->attr.dimension && init->rank == 0)
{
diff --git a/gcc/testsuite/gfortran.dg/pr107397.f90 b/gcc/testsuite/gfortran.dg/pr107397.f90
new file mode 100644
index 0000000..4592a27
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr107397.f90
@@ -0,0 +1,9 @@
+!{ dg-do compile }
+!
+program p
+ type t
+ real :: a = 1.0
+ end type
+ type(t), parameter :: x = z'1' ! { dg-error "incompatible with BOZ" }
+ x%a = x%a + 2 ! { dg-error "has no IMPLICIT type"}
+end