https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88203

--- Comment #3 from Zbyszek <zkoza at ift dot uni.wroc.pl> ---
(In reply to Jakub Jelinek from comment #2)
> Note, in OpenMP 3.1 and earlier this would be actually valid:
> "Variables with const-qualified type having no mutable member are shared."
> and __PRETTY_FUNCTION__ etc. is const qualified (const char []).
> This has changed in OpenMP 4.0, such variables are no longer predetermined
> shared, so must be explicitly listed in data sharing clauses for
> default(none).
> There is nothing wrong on the compiler side here.

OK. I rewrote the test program to:

#include <cassert> 
#include <iostream> 

int main()
{
  std::cout << __PRETTY_FUNCTION__ << "\n";
#pragma omp parallel for default(none) shared(__PRETTY_FUNCTION__) 
  for (int i = 0; i < 10; i++)
  {
    assert (i < 10);
  }
}

======
Effect:
> g++ -fopenmp main.cpp 
main.cpp: In function ‘int main()’:
main.cpp:7:47: error: expected unqualified-id before ‘__PRETTY_FUNCTION__’
 #pragma omp parallel for default(none) shared(__PRETTY_FUNCTION__)
                                               ^~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/8.2.1/cassert:44,
                 from main.cpp:1:
main.cpp:10:5: error: ‘__PRETTY_FUNCTION__’ not specified in enclosing
‘parallel’
     assert (i < 10);
     ^~~~~~
main.cpp:7:9: error: enclosing ‘parallel’
 #pragma omp parallel for default(none) shared(__PRETTY_FUNCTION__)
         ^~~
======

So, __PRETTY_FUNCTION__ is understood by the compiler as long as it does not
enter the OpenMP mode. When in OpenMP, __PRETTY_FUNCTION__  suddenly becomes a
standard variable that needs to be explicitly declared.  

I even don't know how to declare  __PRETTY_FUNCTION__, I am a bit surprised
that this is implemented as a variable rater than a "gcc extension" macro.  

=====
Let's compare with clang:

> clang++ -fopenmp main.cpp 
main.cpp:7:47: error: expected variable name
#pragma omp parallel for default(none) shared(__PRETTY_FUNCTION__) 
                                              ^~~~~~~~~~~~~~~~~~~
1 error generated.

======

So, clang also does not allow __PRETTY_FUNCTION__ to be declared inside shared
clause. 

Let's remove this shared clause and go back to the original c++ example

=======

> clang++ -fopenmp main.cpp

clean compilation!


=======
Conclusion: clang compiles the original example, g++ doesn't.

I think that it would be strange if the implementation of OpenMP's shared
clause would be in conflict with the implementation of assert to the point
where one is forced to give up one of them.

Reply via email to