application codes that expect exterior symbols whose names match
components to be visible in a derived-type definition's default initialization
expressions, and so f18 follows that precedent.
+
+* 19.3.1p1 "Within its scope, a local identifier of an entity of class (1)
+ or class (4) shall not be the same as a global identifier used in that scope..."
+ is read so as to allow the name of a module, submodule, main program,
+ or `BLOCK DATA` subprogram to also be the name of an local entity in its
+ scope, with a portability warning, since that global name is not actually
+ capable of being "used" in its scope.
if (scope.kind() == Scope::Kind::BlockData) {
CheckBlockData(scope);
}
+ if (auto name{scope.GetName()}) {
+ auto iter{scope.find(*name)};
+ if (iter != scope.end()) {
+ const char *kind{nullptr};
+ switch (scope.kind()) {
+ case Scope::Kind::Module:
+ kind = scope.symbol()->get<ModuleDetails>().isSubmodule()
+ ? "submodule"
+ : "module";
+ break;
+ case Scope::Kind::MainProgram:
+ kind = "main program";
+ break;
+ case Scope::Kind::BlockData:
+ kind = "BLOCK DATA subprogram";
+ break;
+ default:;
+ }
+ if (kind) {
+ messages_.Say(iter->second->name(),
+ "Name '%s' declared in a %s should not have the same name as the %s"_port_en_US,
+ *name, kind, kind);
+ }
+ }
+ }
CheckGenericOps(scope);
}
}
!ERROR: The module name or main program name cannot be in a DECLARE TARGET directive
!$omp declare target (mod1)
+ !PORTABILITY: Name 'main' declared in a main program should not have the same name as the main program
!ERROR: The module name or main program name cannot be in a DECLARE TARGET directive
!$omp declare target (main)
end
!ERROR: The module name or main program name cannot be in a THREADPRIVATE directive
!$omp threadprivate(mod1)
+ !PORTABILITY: Name 'main' declared in a main program should not have the same name as the main program
!ERROR: The module name or main program name cannot be in a THREADPRIVATE directive
!$omp threadprivate(main)
!ERROR: Only variable and named common block can be in BIND statement
bind(c) :: sub
+ !PORTABILITY: Name 'm' declared in a module should not have the same name as the module
bind(c) :: m ! no error for implicit type variable
type my_type
! RUN: %python %S/test_errors.py %s %flang_fc1
program p
- integer :: p ! this is ok
+ !PORTABILITY: Name 'p' declared in a main program should not have the same name as the main program
+ integer :: p
end
module m
- integer :: m ! this is ok
+ !PORTABILITY: Name 'm' declared in a module should not have the same name as the module
+ integer :: m
end
submodule(m) sm
- integer :: sm ! this is ok
+ !PORTABILITY: Name 'sm' declared in a submodule should not have the same name as the submodule
+ integer :: sm
+end
+block data bd
+ !PORTABILITY: Name 'bd' declared in a BLOCK DATA subprogram should not have the same name as the BLOCK DATA subprogram
+ type bd
+ end type
end
module m2
type :: t
type :: bad3
end type
- type :: m ! the name of a module can be used as a local identifier
+ !PORTABILITY: Name 'm' declared in a module should not have the same name as the module
+ type :: m
end type m
!ERROR: EXTERNAL attribute was already specified on 'a'