Skip to content

Commit 87fbe9d

Browse files
committed
further edits
1 parent d96e8d3 commit 87fbe9d

File tree

1 file changed

+17
-19
lines changed

1 file changed

+17
-19
lines changed

clang-tools-extra/docs/clang-tidy/checks/portability/avoid-platform-specific-fundamental-types.rst

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,8 @@ portability-avoid-platform-specific-fundamental-types
55

66
Detects fundamental types (``int``, ``short``, ``long``, ``long long``, ``char``
77
, ``float``, etc) and warns against their use due to platform-dependent
8-
behavior.
9-
10-
This check detects fundamental types (``int``, ``short``, ``long``, ``float``,
11-
``char`` and their ``unsigned`` or ``signed`` variants) and warns against their
12-
use due to non-standard platform-dependent behavior. For example, ``long`` is
13-
64 bits on Linux but 32 bits on Windows. There is no standard rationale or
14-
intent for the sizes of these types.
8+
behaviour. For example, ``long`` is 64 bits on Linux but 32 bits on Windows.
9+
There is no standard rationale or intent for the sizes of these types.
1510

1611
Instead of fundamental types, use fixed-width types such as ``int32_t`` or
1712
implementation-defined types with standard semantics, e.g. ``int_fast32_t`` for
@@ -58,7 +53,7 @@ Examples
5853
Rationale
5954
---------
6055

61-
Fundamental types have platform-dependent sizes and behavior:
56+
Examples of platform-dependent behaviour:
6257

6358
- ``int`` is typically 32 bits on modern platforms but is only guaranteed to be
6459
16 bits by the spec
@@ -78,19 +73,18 @@ fixed at 32 bits for backwards compatibility with code that relied on a 32-bit
7873
implementation of ``int``.
7974

8075
If code is explicitly relying on the size of an ``int`` being 32 bits, it is
81-
better to say so in the typename with ``int32_t``. Otherwise, use an
82-
appropriate implementation-defined type such as ``fast_int32_t`` or
83-
``least_int32_t`` that communicates the appropriate time/space tradeoff.
76+
better to say so in the typename with ``int32_t``. Otherwise, use an appropriate
77+
implementation-defined type such as ``fast_int32_t`` or ``least_int32_t`` that
78+
communicates the appropriate time/space tradeoff.
8479

8580
Likewise, ``float`` and ``double`` should be replaced by ``float32_t`` and
86-
``float64_t`` which are guaranteed to be standard IEEE754 floats for a given
87-
size.
81+
``float64_t`` which, if they exist, are guaranteed to be standard IEEE754 floats
82+
of the given size.
8883

8984
``char`` should be replaced by ``char8_t`` when used in the representation of
9085
Unicode text. When used to represent a byte on a given platform, ``std::byte``
91-
is an appropriate replacement. ``char`` can be either signed or unsigned
92-
depending on the platform (unsigned on ARM, signed on x86), while ``char8_t``
93-
and ``std::byte`` are guaranteed to be implemented as unsigned.
86+
is the correct replacement. ``char8_t`` and ``std::byte`` are guaranteed to be
87+
implemented with similar behaviour to unsigned char.
9488

9589
Types Not Flagged
9690
-----------------
@@ -102,8 +96,8 @@ The following types are intentionally not flagged:
10296
- Already typedef'd types, though the check will flag the typedef itself.
10397

10498
``bool`` is excluded because it can only be true or false, and is not
105-
vulnerable to overflow or narrowing issues that occur as a result of using
106-
types of an implementation-defined size.
99+
vulnerable to overflow or narrowing issues that occur as a result of it being an
100+
implementation-defined size.
107101

108102
Options
109103
-------
@@ -113,7 +107,9 @@ Options
113107
When `true`, the check will warn about fundamental integer types
114108
(``short``, ``int``, ``long``, ``long long`` and their ``signed`` and
115109
``unsigned`` variants).
116-
When `false`, integer types are not flagged. Default is `true`.
110+
When `false`, integer types are not flagged.
111+
112+
Default is `true`.
117113

118114
.. option:: WarnOnFloats
119115

@@ -128,3 +124,5 @@ Options
128124
When `true`, the check will warn about character types (``char``,
129125
``signed char``, and ``unsigned char``).
130126
When `false`, character types are not flagged.
127+
128+
Default is `true`

0 commit comments

Comments
 (0)