Index: flang/lib/Semantics/resolve-names.cpp =================================================================== --- flang/lib/Semantics/resolve-names.cpp +++ flang/lib/Semantics/resolve-names.cpp @@ -3885,7 +3885,15 @@ symbol = &MakeCommonBlockSymbol(name); symbol->attrs().set(Attr::BIND_C); } - SetBindNameOn(*symbol); + // 8.6.4(1) + if (symbol->has() || symbol->has() || + (symbol->has() && symbol->GetType())) { + // The named constant is checked elsewhere. + SetBindNameOn(*symbol); + } else { + Say(name, + "Only variable and named common block can be in BIND statement"_err_en_US); + } return false; } bool DeclarationVisitor::Pre(const parser::OldParameterStmt &x) { Index: flang/test/Semantics/bind-c02.f90 =================================================================== --- /dev/null +++ flang/test/Semantics/bind-c02.f90 @@ -0,0 +1,39 @@ +! RUN: %python %S/test_errors.py %s %flang_fc1 +! Check for 8.6.4(1) +! The BIND statement specifies the BIND attribute for a list of variables and +! common blocks. + +module m + + interface + subroutine proc() bind(c) + end + end interface + procedure(proc), bind(c) :: pc1 + !ERROR: Only variable and named common block can be in BIND statement + bind(c) :: proc + !ERROR: Only variable and named common block can be in BIND statement + bind(c) :: pc1 + + !ERROR: Only variable and named common block can be in BIND statement + bind(c) :: sub + + !ERROR: Only variable and named common block can be in BIND statement + bind(c) :: m + + type my_type + integer :: i + end type + !ERROR: Only variable and named common block can be in BIND statement + bind(c) :: my_type + + integer :: x, y, z = 1 + common /blk/ y + bind(c) :: x, /blk/, z ! no error for variable and common block + +contains + + subroutine sub() bind(c) + end + +end Index: flang/test/Semantics/modfile16.f90 =================================================================== --- flang/test/Semantics/modfile16.f90 +++ flang/test/Semantics/modfile16.f90 @@ -6,15 +6,6 @@ type, bind(c) :: t real :: c end type - real :: d - external :: d - bind(c, name='dd') :: d - real :: e - bind(c, name='ee') :: e - external :: e - bind(c, name='ff') :: f - real :: f - external :: f contains subroutine sub() bind(c, name='sub') end @@ -28,9 +19,6 @@ ! type,bind(c)::t ! real(4)::c ! end type -! procedure(real(4)),bind(c, name="dd")::d -! procedure(real(4)),bind(c, name="ee")::e -! procedure(real(4)),bind(c, name="ff")::f !contains ! subroutine sub() bind(c, name="sub") ! end