Beginning with the OpenMP API Version 2.5, this case should fail at compile-time. The gfortran compiler does not reject this case, but gets a segmentation fault at run-time.
The OpenMP API Version 3.0 (May 2008) lists the following restriction to a private clause on p 91. lines 29-30: " * Variables that appear in ... expressions for statement function definitions, may not appear in a private clause." Test case: > cat ISU3136.f90 ! derived from OpenMP test omp1/F2_6_2_1_2a.f90 ! According to OpenMP API Ver 2.5 May 2005 p. 75 lines 19/20 ! this is a negative test that should fail at compile-time. use omp_lib implicit none integer, parameter :: NT = 4 integer :: nThreads(NT) integer :: a, st_func, i st_func() = a + 1 !$ call omp_set_dynamic(.false.) !$ call omp_set_num_threads(NT) !$omp parallel private(a) a = omp_get_thread_num() !$omp barrier nThreads(omp_get_thread_num()+1) = st_func() !$omp end parallel do i = 1, NT if(nThreads(i) /= i) then print*, 'FAIL: non-private copy is used in a statement function.' endif enddo END > ftn -o x -fopenmp ISU3136.f90 > aprun -n 1 ./x Application 1190869 exit signals: Segmentation fault Application 1190869 resources: utime 0, stime 0 Expected output (using the Cray compiler) with a compile-time message: > module swap PrgEnv-gnu PrgEnv-cray > ftn -o x -h omp ISU3136.f90 !$omp parallel private(a) ^ ftn-1760 crayftn: ERROR $MAIN, File = ISU3136.f90, Line = 14, Column = 24 "A" is referenced in a statement function expression, so it must not be specified in the PRIVATE, FIRSTPRIVATE or LASTPRIVATE clause. -- Summary: OpenMP private variable referenced in a statement function Product: gcc Version: 4.4.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: fortran AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: longb at cray dot com GCC build triplet: x86_64-suse-linux GCC host triplet: x86_64-suse-linux GCC target triplet: x86_64-suse-linux http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40876