Debian Codegraph @

clang-tools-extra/docs/clang-tidy/checks/openmp/use-default-none.rst

raw
1 .. title:: clang-tidy - openmp-use-default-none
2
3 openmp-use-default-none
4 =======================
5
6 Finds OpenMP directives that are allowed to contain a ``default`` clause,
7 but either don't specify it or the clause is specified but with the kind
8 other than ``none``, and suggests to use the ``default(none)`` clause.
9
10 Using ``default(none)`` clause forces developers to explicitly specify data
11 sharing attributes for the variables referenced in the construct,
12 thus making it obvious which variables are referenced, and what is their
13 data sharing attribute, thus increasing readability and possibly making errors
14 easier to spot.
15
16 Example
17 -------
18
19 .. code-block:: c++
20
21 // ``for`` directive cannot have ``default`` clause, no diagnostics.
22 void n0(const int a) {
23 #pragma omp for
24 for (int b = 0; b < a; b++)
25 ;
26 }
27
28 // ``parallel`` directive.
29
30 // ``parallel`` directive can have ``default`` clause, but said clause is not
31 // specified, diagnosed.
32 void p0_0() {
33 #pragma omp parallel
34 ;
35 // WARNING: OpenMP directive ``parallel`` does not specify ``default``
36 // clause. Consider specifying ``default(none)`` clause.
37 }
38
39 // ``parallel`` directive can have ``default`` clause, and said clause is
40 // specified, with ``none`` kind, all good.
41 void p0_1() {
42 #pragma omp parallel default(none)
43 ;
44 }
45
46 // ``parallel`` directive can have ``default`` clause, and said clause is
47 // specified, but with ``shared`` kind, which is not ``none``, diagnose.
48 void p0_2() {
49 #pragma omp parallel default(shared)
50 ;
51 // WARNING: OpenMP directive ``parallel`` specifies ``default(shared)``
52 // clause. Consider using ``default(none)`` clause instead.
53 }
54
55 // ``parallel`` directive can have ``default`` clause, and said clause is
56 // specified, but with ``firstprivate`` kind, which is not ``none``, diagnose.
57 void p0_3() {
58 #pragma omp parallel default(firstprivate)
59 ;
60 // WARNING: OpenMP directive ``parallel`` specifies ``default(firstprivate)``
61 // clause. Consider using ``default(none)`` clause instead.
62 }