public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r13-4764] Add a check for invalid use of BOZ with a derived type.
@ 2022-12-18  3:39 Jerry DeLisle
  0 siblings, 0 replies; only message in thread
From: Jerry DeLisle @ 2022-12-18  3:39 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:09710f9934969dcb07131e1ed78b72e648123a3a

commit r13-4764-g09710f9934969dcb07131e1ed78b72e648123a3a
Author: Steve Kargl <kargl@gcc.gnu.org>
Date:   Sat Dec 17 19:15:43 2022 -0800

    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.

Diff:
---
 gcc/fortran/decl.cc                    | 8 ++++++++
 gcc/testsuite/gfortran.dg/pr107397.f90 | 9 +++++++++
 2 files changed, 17 insertions(+)

diff --git a/gcc/fortran/decl.cc b/gcc/fortran/decl.cc
index 0f9b2ced4c2..1562dc22bc6 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 00000000000..4592a275e70
--- /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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-12-18  3:39 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-18  3:39 [gcc r13-4764] Add a check for invalid use of BOZ with a derived type Jerry DeLisle

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).