The following program doesn't work correctly when compiled with -fopenmp: ============================== #include<cstdio> #include<omp.h> #include<unistd.h>
template<int> void foo() { #pragma omp parallel { if (omp_get_thread_num()==0) sleep(1); printf("ONE\n"); #pragma omp barrier printf("TWO\n"); } } int main() { foo<0>(); return 0; } ============================== The output (with two threads) is: ONE TWO ONE TWO If I make foo a non-template function, I get the correct output: ONE ONE TWO TWO Maybe related to PR 24734. -- Summary: [gomp] "#pragma omp barrier" doesn't work in templates Product: gcc Version: unknown Status: UNCONFIRMED Keywords: wrong-code, openmp Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: reichelt at gcc dot gnu dot org http://gcc.gnu.org/bugzilla/show_bug.cgi?id=24735