------- Comment #9 from dominiq at lps dot ens dot fr  2007-11-24 11:04 -------
The following test now fails:

! { dg-do run }
! A test to prove that, a sub-routine, variables from the module takes 
! precedence in case of name conflict with local entities.
! Reference Fortran 95 standard document section 11.3.2
        module modone
          real :: var1 = 11.
          contains
               subroutine set_real(a)
                  real, intent(in)   :: a
                  var1 = a
               end subroutine set_real
        end module modone

        program module_use_test
          integer :: failures=0
          real :: var1=5.
          call test1
          print *, failures
          call test2
          print *, failures
          call test3
          print *, failures
          call check_results

          contains
! A local sub-routine, with similar name from the module
             subroutine set_real(a)
                real :: a
             end subroutine set_real

             subroutine check_local_val(a)
                 real :: a
                 if ( var1 .eq. a ) then
                   failures = failures + 1
                 end if 
             end subroutine check_local_val

             subroutine test1
                 USE modone
                 call set_real(10.)
                 if ( var1 .ne. 10. ) then
                   failures = failures + 1
                 end if 
             end subroutine test1

! When used rename option as local_name => global_name, a global variable gets
referred by 
! the new name only,  and local_name takes precedence in case of name conflict
as in 
! this situation.
             subroutine test2
                 USE modone, global_var_ref1 => var1
                 USE modone, global_var_ref2 => var1

!  This should refer to the global variable 'var1' in the module scope
                 global_var_ref1 = 13        ! some value

!  This should refer to the local variable 'var1' in the scope of 'program'
                 var1 = 7                    ! some value
                 call check_local_val(global_var_ref1)

                 if ( global_var_ref1 .ne. global_var_ref2 ) then
                   failures = failures + 1
                 end if 

             end subroutine test2

! scoping tests for the local and global variables
             subroutine test3
                 USE modone, global_var => var1
                 USE modone

!  This should refer to the global variable var1' in the module
                 global_var = 13.

!  This should refer to the global variable 'var1' in the module
                 var1 = var1 + 0
                 if ( var1 .ne. global_var ) then
                   failures = failures + 1
                 end if 

!  This should refer to the local variable in the scope of 'program code'
                 call check_local_val(var1)

             end subroutine test3

             subroutine check_results
                 if ( failures .ne. 0 ) call abort()
             end subroutine check_results

        end program module_use_test

[ibook-dhum] f90/bug% a.out
           0
           1
           3
Abort


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33541

Reply via email to