Skip to content

Commit dca3218

Browse files
committed
docs: update constexpr spec for linkage and qualifier restrictions
1 parent c311c0b commit dca3218

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

docs/design/constexpr.rst

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ constexpr variables
6666
~~~~~~~~~~~~~~~~~~~
6767

6868
- ``constexpr`` implies ``const``.
69+
- ``constexpr`` is not allowed on ``typedef`` declarations.
6970
- The initializer must be a constant expression (constant-evaluable).
7071
- Allowed v1 types:
7172
- atomic types (bool, int, float, double, etc.)
@@ -76,8 +77,7 @@ constexpr variables
7677
- Arrays must have fully specified sizes.
7778
- Pointer values are limited to null or addresses of globals/functions.
7879
- The value is available to constant-expression evaluation.
79-
- Storage class and linkage follow existing rules (``constexpr`` does not
80-
change them).
80+
- For variables, storage class and linkage follow existing rules.
8181

8282
constexpr functions
8383
~~~~~~~~~~~~~~~~~~~
@@ -87,6 +87,11 @@ constexpr functions
8787
- The selected overload must be ``constexpr`` for constant evaluation.
8888
- ``constexpr`` functions must be "constexpr-suitable" at definition time.
8989
- The return type can be any constexpr-supported type (including aggregates).
90+
- ``constexpr`` is not allowed on function parameters.
91+
- Linkage follows C++ constexpr function behavior:
92+
- non-``static`` constexpr functions are emitted with ODR linkage
93+
(``linkonce_odr``)
94+
- ``static`` constexpr functions have internal linkage
9095

9196
constexpr-suitable validation (definition time)
9297
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -111,8 +116,8 @@ Disallowed (v1):
111116

112117
- Writes to non-local storage (globals, captured references, or pointer
113118
dereference).
114-
- Taking the address of local variables; only global/function addresses are
115-
allowed.
119+
- Taking the address of local variables or parameters; only global/function
120+
addresses are allowed.
116121
- ``new``, ``delete``, ``launch``, ``invoke_sycl``, ``sync``, ``print``,
117122
atomics, and any other side-effecting builtins.
118123
- ``foreach*`` statements (``foreach``, ``foreach_active``, ``foreach_unique``).
@@ -272,6 +277,7 @@ constant-expression contexts.
272277
^^^^^^^^^^^^^^^^^^^^^^^
273278

274279
- ``constexpr`` implies ``const``.
280+
- ``constexpr`` is not allowed on ``typedef`` declarations.
275281
- The initializer must be a constant expression.
276282
- V1 supports atomic, enum, pointer, short vector, array, and struct types.
277283
- Arrays must have fully specified sizes.
@@ -301,11 +307,16 @@ Requirements (v1):
301307
- The function body must be constexpr-suitable at definition time.
302308
- The function must return a value (no ``void`` return in v1).
303309
- The function may only call other ``constexpr`` functions.
310+
- ``constexpr`` is not allowed on function parameters.
304311
- Control flow conditions must be uniform.
305312
- Pointer dereference is not allowed; address-of is limited to
306-
globals/functions.
313+
globals/functions (not locals/parameters).
307314
- ``task``, ``export``, and ``extern "C"/"SYCL"`` are not allowed on
308315
``constexpr`` functions in v1.
316+
- Linkage follows C++ constexpr function behavior:
317+
- non-``static`` constexpr functions are emitted with ODR linkage
318+
(``linkonce_odr``)
319+
- ``static`` constexpr functions have internal linkage
309320

310321
Examples:
311322

docs/ispc.rst

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3807,6 +3807,7 @@ enumerator values, non-type template arguments, and default parameter values.
38073807
**Constexpr variables**
38083808

38093809
- ``constexpr`` implies ``const``.
3810+
- ``constexpr`` is not allowed on ``typedef`` declarations.
38103811
- The initializer must be a constant expression.
38113812
- Supported types (v1): atomic, enum, pointer, short vector, array, and struct.
38123813
- Arrays must have fully specified sizes.
@@ -3844,10 +3845,16 @@ Requirements (v1):
38443845
- The function body must be constexpr-suitable at definition time.
38453846
- The function must return a value (no ``void`` return in v1).
38463847
- The function may only call other ``constexpr`` functions.
3848+
- ``constexpr`` is not allowed on function parameters.
38473849
- Control flow conditions must be uniform.
3848-
- Pointer dereference is not allowed; address-of is limited to globals/functions.
3850+
- Pointer dereference is not allowed; address-of is limited to globals/functions
3851+
(not locals/parameters).
38493852
- ``task``, ``export``, and ``extern "C"/"SYCL"`` are not allowed on
38503853
``constexpr`` functions in v1.
3854+
- Linkage follows C++ constexpr function behavior:
3855+
- non-``static`` constexpr functions are emitted with ODR linkage
3856+
(``linkonce_odr``)
3857+
- ``static`` constexpr functions have internal linkage
38513858

38523859
Example:
38533860

0 commit comments

Comments
 (0)