Page 1 of 1

Restrictions on directives with no language statement

PostPosted: Wed Jan 23, 2008 10:17 am
by dmikh
I have a question about example A.23.
A.23 (p216, l17-18) says "The following example is non-conforming, because the flush, barrier, and taskwait directives cannot be the immediate substatement of an if statement." but would the following program be conforming?

Code: Select all
void foo()
{
  int a = 1;
#pragma omp parallel
  {
    if (a != 0)
#pragma omp flush(a)
    {
    }

    if (a != 0)
#pragma omp barrier
    {
    }

    if (a != 0)
#pragma omp taskwait
    {
    }
  }
}

void bar()
{
  int a = 1;
#pragma omp parallel
  {
    if (a != 0)
#pragma omp flush(a)
      ;

    if (a != 0)
#pragma omp barrier
      ;

    if (a != 0)
#pragma omp taskwait
      ;
  }
}


The program also has flush, barrier, and taskwait directives as "immediate substatements" (although this term is not defined anywhere).
In my opinion this program is valid, because all these directives can be deleted without getting incorrect syntax. It conforms to 2.8.3 (p64, l6-9), 2.8.6 (p69, l12-15) and 2.8.4 (p65, l13-16) "The directive ... may only be placed in the program at a position where ignoring or deleting the directive would result in a program with correct syntax".

Also, flush, barrier, and taskwait directives have no sense if placed at file-scope level. But according to previously noted Draft sections it is allowed.

Re: Restrictions on directives with no language statement

PostPosted: Tue Jan 29, 2008 2:58 pm
by lfm
I have added this to the language committee's list. Thanks.