Bug 677637

Summary: OpenMP C++ Code refuses to compile due to const modifier
Product: Red Hat Enterprise Linux 6 Reporter: Peter Klotz <peter.klotz>
Component: gccAssignee: Jakub Jelinek <jakub>
Status: CLOSED NOTABUG QA Contact: qe-baseos-tools-bugs
Severity: medium Docs Contact:
Priority: unspecified    
Version: 6.0   
Target Milestone: rc   
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2011-02-15 13:01:50 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Attachments:
Description Flags
Code that shows the problem none

Description Peter Klotz 2011-02-15 12:29:17 UTC
Created attachment 478870 [details]
Code that shows the problem

Description of problem:
The attached code results in the following compiler error:

main.cpp: In function ‘int main(int, char**)’:
main.cpp:22: error: ‘values’ is predetermined ‘shared’ for ‘shared’

Version-Release number of selected component (if applicable):

gcc version 4.4.4 20100726 (Red Hat 4.4.4-13) (GCC)

How reproducible:

Compile the attached program using this command:

g++ -c -o main.o -fopenmp -pipe -Wall -Wextra main.cpp
 
Actual results:

The above compiler error.

Expected results:

The code should compile. It compiles, if the "const" in line 17 is removed. It also compiles using gcc 4.1 under RHEL5.

Additional info:

Comment 2 Jakub Jelinek 2011-02-15 13:01:50 UTC
See OpenMP 3.0 standard, section 2.9.1.1, line 19 on page 78:
"Variables with const-qualified type having no mutable member are shared."
and lines 1-7 on page 79:
"Variables with predetermined data-sharing attributes may not be listed in data-sharing attribute clauses, except for the cases listed below. For these exceptions only, listing a predetermined variable in a data-sharing attribute clause is allowed and overrides the variable’s predetermined data-sharing attributes.
C/C++
The loop iteration variable(s) in the associated for-loop(s) of a for or parallel
for construct may be listed in a private or lastprivate clause.

Therefore your testcase is not valid OpenMP program and it is correct that GCC rejects it.  Just remove the const var from shared clause.

Comment 3 Peter Klotz 2011-02-15 16:04:30 UTC
Thanks a lot for this detailed explanation.

Regards, Peter.