User account creation filtered due to spam.

Bug 53655 - [F03] "default initializer" warnings
Summary: [F03] "default initializer" warnings
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.8.0
: P3 normal
Target Milestone: ---
Assignee: janus
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2012-06-13 09:10 UTC by Tobias Burnus
Modified: 2013-08-20 14:19 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2013-08-19 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Burnus 2012-06-13 09:10:34 UTC

    
Comment 1 Tobias Burnus 2012-06-13 09:18:40 UTC
The following code has several warning issues:

a) For foo's "x" there is the warning:
"Derived-type dummy argument 'x' at (1) was declared INTENT(OUT) but was not set and does not have a default initializer"
As "t" has no components, the warning doesn't make sense.

b) For bar's "x" there is no warning as it is sym->attr.referenced, but I think one should warn that the "declared type" does not have an initializer.
(I think sym->attr.referenced gets set for "allocatable" dummies, thus, no warning is printed.)

c) One gets the bogus error:
  warning: ‘__copy_MAIN___T2’ defined but not used [-Wunused-function]
It probably should be marked as DECL_ARTIFICIAL().


type t
end type t

type t2
  integer :: i
end type t2
contains
  subroutine foo(x)
    type(t), intent(out) :: x
  end subroutine foo

  subroutine bar(x)
    class(t2), intent(out) :: x
  end subroutine bar
end
Comment 2 Tobias Burnus 2012-06-13 09:20:56 UTC
(In reply to comment #1)
> (I think sym->attr.referenced gets set for "allocatable" dummies, thus, no
> warning is printed.)

(As clarification: That wasn't a remark to the issue (b) but a general one. Note that for allocatables, no warning initializer-related warning should be be printed. Thus, the current result is okay.)
Comment 3 janus 2013-08-19 14:25:42 UTC
(In reply to Tobias Burnus from comment #1)
> c) One gets the bogus error:
>   warning: ‘__copy_MAIN___T2’ defined but not used [-Wunused-function]
> It probably should be marked as DECL_ARTIFICIAL().

This problem has apparently been fixed at some point. I see it neither with 4.7.4, 4.8.2 nor with trunk.
Comment 4 janus 2013-08-19 15:04:04 UTC
(In reply to Tobias Burnus from comment #1)
> a) For foo's "x" there is the warning:
> "Derived-type dummy argument 'x' at (1) was declared INTENT(OUT) but was not
> set and does not have a default initializer"
> As "t" has no components, the warning doesn't make sense.

This is easily fixed by the following:

Index: gcc/fortran/trans-decl.c
===================================================================
--- gcc/fortran/trans-decl.c	(revision 201834)
+++ gcc/fortran/trans-decl.c	(working copy)
@@ -4745,7 +4745,8 @@
 		gfc_warning ("Dummy argument '%s' at %L was declared "
 			     "INTENT(OUT) but was not set",  sym->name,
 			     &sym->declared_at);
-	      else if (!gfc_has_default_initializer (sym->ts.u.derived))
+	      else if (!gfc_has_default_initializer (sym->ts.u.derived)
+		       && !sym->ts.u.derived->attr.zero_comp)
 		gfc_warning ("Derived-type dummy argument '%s' at %L was "
 			     "declared INTENT(OUT) but was not set and "
 			     "does not have a default initializer",
Comment 5 janus 2013-08-19 15:25:01 UTC
(In reply to Tobias Burnus from comment #1)
> b) For bar's "x" there is no warning as it is sym->attr.referenced, but I
> think one should warn that the "declared type" does not have an initializer.

With 4.9 trunk, the following code is generated for 'bar':


bar (struct __class_MAIN___T2 & restrict x)
{
  if (x->_vptr->_final != 0B)
    {
      {
        struct array0_unknown desc.0;

        desc.0.dtype = 600;
        desc.0.data = (void * restrict) x->_data;
        x->_vptr->_final (&desc.0, x->_vptr->_size, 0);
      }
    }
  (void) __builtin_memcpy ((void *) x->_data, (void *) x->_vptr->_def_init, (unsigned long) x->_vptr->_size);
}


The _final call is new in 4.9, but the memcpy from _def_init appeared already with 4.7 and 4.8. (Possibly this is what sets sym->referenced?)


However, I'm not convinced that one should throw a warning here: Even if the declared type does not have a default initializer, an extended type might have one and of course we don't know the actual (dynamic) type of the class variable at compile time (that's why we have the _def_init after all).
Comment 6 janus 2013-08-19 20:45:23 UTC
The patch in comment 4 regtests cleanly. Will commit as obvious.
Comment 7 janus 2013-08-20 14:19:23 UTC
(In reply to janus from comment #6)
> The patch in comment 4 regtests cleanly. Will commit as obvious.


Author: janus
Date: Tue Aug 20 14:16:26 2013
New Revision: 201884

URL: http://gcc.gnu.org/viewcvs?rev=201884&root=gcc&view=rev
Log:
2013-08-20  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/53655
	* trans-decl.c (generate_local_decl): Check if type has any components.

2013-08-20  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/53655
	* gfortran.dg/intent_out_8.f90: New.

Added:
    trunk/gcc/testsuite/gfortran.dg/intent_out_8.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/trans-decl.c
    trunk/gcc/testsuite/ChangeLog


After this fixes case a), case b) turned out to be a non-bug and case c) has been fixed earlier, I think we can close this PR.