Bug 50375 - gfortran must complain on NULL() ambiguity without MOLD
Summary: gfortran must complain on NULL() ambiguity without MOLD
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.6.1
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: accepts-invalid, diagnostic
Depends on:
Blocks:
 
Reported: 2011-09-13 08:52 UTC by Vittorio Zecca
Modified: 2011-09-14 07:17 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
Just compile it (222 bytes, text/plain)
2011-09-13 08:54 UTC, Vittorio Zecca
Details
Draft patch (662 bytes, patch)
2011-09-13 13:55 UTC, Tobias Burnus
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Vittorio Zecca 2011-09-13 08:52:29 UTC
Please compile the attached code
Comment 1 Vittorio Zecca 2011-09-13 08:54:47 UTC
Created attachment 25254 [details]
Just compile it
Comment 2 Tobias Burnus 2011-09-13 09:37:39 UTC
c the following is wrong: the MOLD formal argument of null() is required
c gfortran simply picks the last routine defined in the interface, in this case s2

Which is consistent with NAG, Open64 and PathScale. With ifort and g95 one gets the expected error message:

      call gen(null())
               1
Error: Typeless NULL() at (1) must have a MOLD argument
      call gen(null())
           1
Error: Generic subroutine 'gen' at (1) is not consistent with a specific subroutine interface


error #6285: There is no matching specific subroutine for this generic subroutine call.   [GEN]

 * * *

From F2008's 13.7.125 NULL ([MOLD]):

"If MOLD is absent, the characteristics of the result are determined by the entity with which the reference is associated. See Table 13.2. MOLD shall not be absent in any other context. [...]"

"If the context of the reference to NULL is an actual argument in a generic procedure reference, MOLD shall be present if the type, type parameters, or rank are required to resolve the generic reference."


"Table 13.2: Characteristics of the result of NULL ( )
  Appearance of NULL ( )                    Type, type parameters,
                                            and rank of result:
  right side of a pointer assignment        pointer on the left side
  initialization for an object in a declaration   the object
  default initialization for a component    the component
  in a structure constructor                the corresponding component
  as an actual argument                     the corresponding dummy argument
  in a DATA statement                       the corresponding pointer object"
Comment 3 Tobias Burnus 2011-09-13 13:55:13 UTC
Created attachment 25262 [details]
Draft patch

This patch handles NULL() properly, including passing it to optional nonpointer, nonallocatable dummies.

Caveat: It currently prints two messages - I don't want to have the second one.

      call gen(null())
               1
Error: MOLD= required in NULL() argument at (1): Ambiguity between specific functions s2 and s1

      call gen(null())
                      1
Error: There is no specific subroutine for the generic 'gen' at (1)
Comment 4 Mikael Morin 2011-09-13 16:17:04 UTC
(In reply to comment #1)
> Created attachment 25254 [details]
> Just compile it
Please paste the code content directly instead of attaching for small (say, less than around 10-20 lines) files.


Related bugs: PR34547 (and it's duplicate PR44349 reported by the same author as this one). Unfortunately, they won't be fixed by Tobias' comment #3 patch.

(In reply to comment #3)
> Created attachment 25262 [details]
> Draft patch
> 
I think we'll be in trouble if there are more than one null argument.
Otherwise looks good.
Comment 5 Tobias Burnus 2011-09-14 06:26:14 UTC
Author: burnus
Date: Wed Sep 14 06:26:07 2011
New Revision: 178841

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=178841
Log:
2011-09-14  Tobias Burnus  <burnus@net-b.de>

        PR fortran/34547
        PR fortran/50375
        * check.c (gfc_check_null): Allow allocatables as MOLD to NULL.
        * resolve.c (resolve_transfer): Reject NULL without MOLD.
        * interface.c (gfc_procedure_use): Reject NULL without MOLD
        if no explicit interface is known.
        (gfc_search_interface): Reject NULL without MOLD if it would
        lead to ambiguity.

2011-09-14  Tobias Burnus  <burnus@net-b.de>

        PR fortran/34547
        PR fortran/50375
        * gfortran.dg/null_5.f90: New.
        * gfortran.dg/null_6.f90: New.


Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/check.c
    trunk/gcc/fortran/interface.c
    trunk/gcc/fortran/resolve.c
    trunk/gcc/testsuite/ChangeLog
Comment 6 Tobias Burnus 2011-09-14 06:27:30 UTC
Author: burnus
Date: Wed Sep 14 06:27:25 2011
New Revision: 178842

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=178842
Log:
Really add:

2011-09-14  Tobias Burnus  <burnus@net-b.de>

        PR fortran/34547
        PR fortran/50375
        * gfortran.dg/null_5.f90: New.
        * gfortran.dg/null_6.f90: New.


Added:
    trunk/gcc/testsuite/gfortran.dg/null_5.f90
    trunk/gcc/testsuite/gfortran.dg/null_6.f90
Comment 7 Tobias Burnus 2011-09-14 07:17:48 UTC
FIXED on the trunk (for 4.7).

Thanks for the report!