Static Analysis Problem Type Reference
A PRIVATE variable of class type lacks a required constructor.
A PRIVATE clause effectively creates a per-thread temporary variable. If the variable has class type, the declaration is performed using the default constructor. The default constructor must exist, be unambiguous, and visible.
|
ID |
Code Location |
Description |
|---|---|---|
|
1 |
OpenMP usage error |
The place where the variable was marked as PRIVATE |
#include <stdio.h>
#include <omp.h>
// Note: this class has no default constructor
class myClass {
int m_myInt;
public:
explicit myClass(int x) { m_myInt = x; }
void set(int x) { m_myInt = x; }
int get() { return m_myInt; }
};
myClass a(110);
int main(int argc, char **argv)
{
int i;
omp_set_num_threads(3);
// INCORRECT: a has no accessible default constructor
#pragma omp parallel for ordered private(a)
for (i = 1; i < 10; i++) {
a.set(i);
#pragma omp ordered
printf("i = %d, #threads = %d, a = %d\n", i, omp_get_thread_num(), a.get() );
}
return 0;
}