Skip to content

Commit de457f6

Browse files
committed
[flang] Error message situation should be a warning
f18 emits an error message when the same name is used in a scope for both a procedure and a generic interface, and the procedure is not a specific procedure of the generic interface. It may be questionable usage, and not portable, but it does not appear to be non-conforming by a strict reading of the standard, and many popular Fortran compilers accept it. Differential Revision: https://reviews.llvm.org/D135205
1 parent 8100374 commit de457f6

File tree

4 files changed

+35
-4
lines changed

4 files changed

+35
-4
lines changed

flang/docs/Extensions.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,3 +440,34 @@ end subroutine
440440
The precedent among the most commonly used compilers
441441
agrees with f18's interpretation: a `DATA` statement without any other
442442
specification of the name refers to the host-associated object.
443+
444+
* Many Fortran compilers allow a non-generic procedure to be `USE`-associated
445+
into a scope that also contains a generic interface of the same name
446+
but does not have the `USE`-associated non-generic procedure as a
447+
specific procedure.
448+
```
449+
module m1
450+
contains
451+
subroutine foo(n)
452+
integer, intent(in) :: n
453+
end subroutine
454+
end module
455+
456+
module m2
457+
use m1, only: foo
458+
interface foo
459+
module procedure noargs
460+
end interface
461+
contains
462+
subroutine noargs
463+
end subroutine
464+
end module
465+
```
466+
467+
This case elicits a warning from f18, as it should not be treated
468+
any differently than the same case with the non-generic procedure of
469+
the same name being defined in the same scope rather than being
470+
`USE`-associated into it, which is explicitly non-conforming in the
471+
standard and not allowed by most other compilers.
472+
If the `USE`-associated entity of the same name is not a procedure,
473+
most compilers disallow it as well.

flang/lib/Semantics/resolve-names.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3196,8 +3196,8 @@ void InterfaceVisitor::CheckGenericProcedures(Symbol &generic) {
31963196
auto &details{generic.get<GenericDetails>()};
31973197
if (auto *proc{details.CheckSpecific()}) {
31983198
auto msg{
3199-
"'%s' may not be the name of both a generic interface and a"
3200-
" procedure unless it is a specific procedure of the generic"_err_en_US};
3199+
"'%s' should not be the name of both a generic interface and a"
3200+
" procedure unless it is a specific procedure of the generic"_warn_en_US};
32013201
if (proc->name().begin() > generic.name().begin()) {
32023202
Say(proc->name(), std::move(msg));
32033203
} else {

flang/test/Semantics/resolve17.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ module m2
1111
interface s
1212
end interface
1313
contains
14-
!ERROR: 's' may not be the name of both a generic interface and a procedure unless it is a specific procedure of the generic
14+
!WARNING: 's' should not be the name of both a generic interface and a procedure unless it is a specific procedure of the generic
1515
subroutine s
1616
end subroutine
1717
end module

flang/test/Semantics/resolve18.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ subroutine foo(x)
1111
module m2
1212
use m1
1313
implicit none
14-
!ERROR: 'foo' may not be the name of both a generic interface and a procedure unless it is a specific procedure of the generic
14+
!WARNING: 'foo' should not be the name of both a generic interface and a procedure unless it is a specific procedure of the generic
1515
interface foo
1616
module procedure s
1717
end interface

0 commit comments

Comments
 (0)