File: statically-constructed-objects.rst

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (43 lines) | stat: -rw-r--r-- 1,112 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
.. title:: clang-tidy - fuchsia-statically-constructed-objects

fuchsia-statically-constructed-objects
======================================

Warns if global, non-trivial objects with static storage are constructed, unless
the object is statically initialized with a ``constexpr`` constructor or has no
explicit constructor.

For example:

.. code-block:: c++

  class A {};

  class B {
  public:
    B(int Val) : Val(Val) {}
  private:
    int Val;
  };

  class C {
  public:
    C(int Val) : Val(Val) {}
    constexpr C() : Val(0) {}

  private:
    int Val;
  };

  static A a;         // No warning, as there is no explicit constructor
  static C c(0);      // No warning, as constructor is constexpr

  static B b(0);      // Warning, as constructor is not constexpr
  static C c2(0, 1);  // Warning, as constructor is not constexpr

  static int i;       // No warning, as it is trivial

  extern int get_i();
  static C(get_i())   // Warning, as the constructor is dynamically initialized

See the features disallowed in Fuchsia at https://fuchsia.dev/fuchsia-src/development/languages/c-cpp/cxx?hl=en