# constexpr in C++26

> C++26 lets constant evaluation cast from void*, use placement new, throw and catch exceptions, bind constexpr structured bindings and construct classes with virtual bases. The rule underneath stays the same, though, because nothing may leak out of the evaluation.

- **Source:** C++ Atlas (https://cppatlas.com/topics/constexpr-in-cpp26)
- **Track:** C++26
- **Estimated reading time:** 13 minutes
- **ISO C++ clauses:** [expr.const.core] (https://eel.is/c++draft/expr.const.core), [expr.const.const] (https://eel.is/c++draft/expr.const.const), [expr.const.init] (https://eel.is/c++draft/expr.const.init), [dcl.constexpr] (https://eel.is/c++draft/dcl.constexpr), [dcl.pre] (https://eel.is/c++draft/dcl.pre), [dcl.struct.bind] (https://eel.is/c++draft/dcl.struct.bind), [meta.const.eval] (https://eel.is/c++draft/meta.const.eval), [propagation] (https://eel.is/c++draft/propagation), [std.exceptions] (https://eel.is/c++draft/std.exceptions), [library.c] (https://eel.is/c++draft/library.c), [basic.indet] (https://eel.is/c++draft/basic.indet)
- **cppreference links:** [Constant expressions](https://en.cppreference.com/w/cpp/language/constant_expression), [constexpr specifier](https://en.cppreference.com/w/cpp/language/constexpr), [static_assert declaration](https://en.cppreference.com/w/cpp/language/static_assert), [Structured binding declaration](https://en.cppreference.com/w/cpp/language/structured_binding), [std::is_within_lifetime](https://en.cppreference.com/w/cpp/types/is_within_lifetime), [new expression (placement new)](https://en.cppreference.com/w/cpp/language/new), [Common mathematical functions](https://en.cppreference.com/w/cpp/numeric/math)
- **Prerequisites:** constant-expressions, object-lifetime-and-storage, exceptions-and-stack-unwinding, structured-bindings

## The one idea

C++26 does not change the model of constant evaluation. It removes special cases from it. The evaluator was always an interpreter that tracks every object's type and lifetime, and it rejects anything it cannot check. Each C++26 addition is an operation the interpreter can now check: a `void*` cast back to the right type, a placement new into storage it created, or an exception that is thrown and caught before the evaluation ends.

The rule underneath is unchanged. Whatever the evaluation creates must be gone, or be safely representable, by the time it finishes. Memory from `new` must be freed, exception objects must be destroyed, and the result may not point at anything the program could not name.

This is C++26. The text here follows N5050, the final C++26 draft sent to the international ballot. That ballot closed in October 2026 and was reported as not approved, with contracts at the centre of the dispute, so check the status before you quote it as published ISO C++. GCC 16 implements most of the language parts with `-std=c++26` and differs from the draft in places noted below. Clang 21 implements fewer of them.

> **Mental model.** Constant evaluation is a sandbox with a strict exit check. C++26 adds toys to the sandbox; it does not relax the exit check.

The pre-C++26 rules, including transient allocation and `consteval`, are covered in the constant-expressions topic.

## Type erasure: void* casts and placement new

Until C++23, a cast from `void*` to an object pointer type disqualified an expression outright. That blocked type-erased code such as `std::any`-like storage and `function_ref`-like callbacks. P2738R1 allows the cast when the `void*` is null or points to an object whose type is *similar* to the target, which means the same type up to cv-qualification. Anything else is still not a constant expression, so a wrong-type cast is diagnosed instead of becoming undefined behaviour.

```cpp
constexpr int roundtrip() {
  int x = 42;
  void* p = &x;
  return *static_cast<int*>(p);      // OK since C++26: p points to an int
}
static_assert(roundtrip() == 42);

constexpr int pun() {
  int x = 42;
  void* p = &x;
  return *static_cast<short*>(p);    // not similar: not a constant expression
}
// static_assert(pun() == 42);        // error
```

Placement new followed naturally, in P2747R2. A non-allocating `new (p) T(args)` is allowed when `p` points to an object that the new `T` can *transparently replace*, roughly an object of the same type, and the storage was created within the same evaluation. In practice, that means storage from `std::allocator<T>::allocate` or a local of the same type. You can no longer construct an `int` inside an `unsigned char` buffer, and you cannot touch globals. `std::construct_at`, available since C++20, already covered most uses, but placement new now works in generic code that spells it directly. Both papers bumped `__cpp_constexpr`, and GCC 16 reports `202406L`.

```cpp
#include <memory>
#include <new>

struct S { int v; constexpr S(int x) : v(x) {} };

constexpr int build() {
  std::allocator<S> a;
  S* p = a.allocate(1);
  ::new (p) S(7);          // OK since C++26
  int r = p->v;
  p->~S();
  a.deallocate(p, 1);      // still mandatory: no leaks out of the evaluation
  return r;
}
static_assert(build() == 7);
```

> **Pitfall.** GCC 16 accepts some `void*` casts that the draft rejects. One example is casting a `void*` that points to a `Derived` back to `Base*`, and another is casting a pointer to an array's first element to a pointer to the array. Clang 21 rejects both. Write the cast back to the exact type that was erased.

## Exceptions during constant evaluation

P3068R6 removes the blanket ban on `throw`. An exception may now be thrown, unwound and caught inside a constant evaluation, provided the exception object and every copy made by `std::rethrow_exception` are destroyed before the evaluation ends. If the exception escapes, the expression is not constant, so an uncaught throw is still a compile-time error. The difference is that you can now handle it.

```cpp
#include <optional>
#include <stdexcept>

constexpr int digit(char c) {
  if (c < '0' || c > '9') throw std::invalid_argument("not a digit");
  return c - '0';
}

constexpr std::optional<int> try_digit(char c) {
  try { return digit(c); }
  catch (const std::invalid_argument&) { return std::nullopt; }
}

static_assert(try_digit('7') == 7);
static_assert(!try_digit('x'));            // caught during constant evaluation
// constexpr int bad = digit('x');         // error: exception escapes
```

The library followed. `std::exception` and its `what()`, `bad_alloc`, `bad_cast` and the other language-support exceptions became constexpr in P3068. P3378R2 did the same for the `<stdexcept>` classes and for `bad_optional_access`, `bad_variant_access` and `bad_expected_access`. So `vector::at` out of range now throws a catchable `out_of_range` at compile time. `make_exception_ptr` and `rethrow_exception` are constexpr as well, but an `exception_ptr` cannot be stored in a `constexpr` variable, because the exception object would outlive the evaluation.

Two functions were taken back. P3068 had made `std::current_exception` and `std::uncaught_exceptions` constexpr. Both depend on the program's global exception state, which a constant evaluation could observe in surprising places. P3842R2 removed `constexpr` from both before C++26 shipped, and N5050 reflects that. The rethrowing form `throw;` still works when the handled exception was created inside the evaluation.

> **Standardese.** [expr.const.core] now disqualifies "a construction of an exception object, unless the exception object and all of its implicit copies created by invocations of `std::current_exception` or `std::rethrow_exception` are destroyed within the evaluation". It also disqualifies a `dynamic_cast`, `typeid` or new-expression that would throw where no definition of the exception type is reachable.

GCC 16 implements all of this. It defines `__cpp_constexpr_exceptions` as `202411L` and `__cpp_lib_constexpr_exceptions` as `202502L`, and it already rejects `current_exception` in a constant expression. Clang 21 does not support constexpr exceptions.

## constexpr structured bindings and references to locals

P2686R5 makes two related changes. First, a structured binding declaration may be `constexpr` or `constinit`, and the specifier goes to the hidden variable `e` that holds the initializer. Second, a `constexpr` reference or pointer may refer to an automatic variable, as long as it is used inside the same function invocation. The draft calls such an object *constexpr-referenceable*. A reference that could escape, such as a `static constexpr` one or a use inside a nested lambda, is still rejected.

```cpp
#include <utility>

struct P { int x, y; };
constexpr auto [a, b] = P{1, 2};          // OK since C++26
static_assert(a + b == 3);
constexpr auto [c, d] = std::pair{3, 4};  // tuple-like, namespace scope
static_assert(c * d == 12);

void f() {
  constexpr auto [u, v] = P{5, 6};        // OK: block scope, aggregate
  static_assert(u < v);
  int x = 0;
  (void)x;
  // constexpr int& rx = x;               // OK in C++26: same function
  // static constexpr int& sx = x;        // error: could escape the invocation
}
```

The structured-binding name is treated as the member or element access on `e` that it stands for. A binding to a `mutable` member therefore cannot be read in a constant expression, even though the declaration itself is fine.

> **Pitfall.** GCC 16 implements only half of P2686. It accepts `constexpr` structured bindings for arrays and aggregates, but it still rejects `constexpr` references and pointers to automatic variables, including `constexpr const int& r = k;` where `k` is itself `constexpr`. As a result, it also rejects a block-scope `constexpr auto [p, q] = std::pair{...}`, because tuple-like bindings are references. Clang 21 implements neither part.

## Virtual bases, static_assert messages and is_within_lifetime

P3533R2 removes the rule that a class with a virtual base cannot have a constexpr constructor or destructor. In N5050, the only remaining condition for a function to be *constexpr-suitable* is that it is not a coroutine. The interpreter already knows the dynamic type of every object it creates, so a virtual base costs it nothing.

```cpp
struct Base { int v; constexpr Base(int x) : v(x) {} };
struct L : virtual Base { constexpr L() : Base(1) {} };
struct R : virtual Base { constexpr R() : Base(2) {} };
struct Diamond : L, R { constexpr Diamond() : Base(3) {} };

constexpr int share() {
  Diamond d;
  L& l = d;
  R& r = d;
  return l.v * 10 + r.v;   // one shared Base, built by Diamond
}
static_assert(share() == 33);  // C++26; GCC 16 accepts, Clang 21 rejects
```

P2741R3 lets the second argument of `static_assert` be any constant expression with `size()` and `data()` members, such as a `std::string` built at compile time, instead of only a string literal. The message is used only when the assertion fails. In that case `size()` must be a converted constant expression of type `std::size_t`, every character must be a constant, and the text is that many code units of the ordinary literal encoding. When the condition is true, the message is an unevaluated operand.

```cpp
#include <cstddef>

struct Msg {
  constexpr std::size_t size() const { return 5; }
  constexpr const char* data() const { return "hello world"; }
};
static_assert(sizeof(char) == 1, Msg{});      // passes; message unused
// static_assert(sizeof(char) == 2, Msg{});   // error: static assertion failed: hello
```

P2641R4 adds `std::is_within_lifetime(p)` to `<type_traits>`. It is `consteval`, and it returns whether `p` points to an object within its lifetime. The motivating use is asking which union member is active without reading it. An `optional<bool>`-like type can store a sentinel in a `char` member and still answer `has_value()` during constant evaluation, where reading the inactive member would be disqualified.

```cpp
#include <type_traits>

struct OptBool {
  union { bool b; char c; };
  constexpr OptBool() : c(2) {}
  constexpr OptBool(bool x) : b(x) {}
  constexpr bool has_value() const {
    if consteval { return std::is_within_lifetime(&b); }
    else { return c != 2; }   // at run time, bytes are all we have
  }
};
```

GCC 16 implements virtual bases and string-like messages, but libstdc++ 16 has no `std::is_within_lifetime`, so the last example does not compile there. Clang 21 has only the `__builtin_is_within_lifetime` builtin, which libc++ 21 does not yet wrap.

## The library catches up

N5050 marks far more of the library constexpr than C++23 did:

- **Containers and adaptors** (P3372R3): `deque`, `list`, `forward_list`, `map`, `set`, the unordered containers and their multi variants, plus `queue`, `stack` and `priority_queue`. `inplace_vector` is constexpr by design.
- **Algorithms**: `stable_sort`, `stable_partition` and `inplace_merge` (P2562R1).
- **`<cmath>`** (P1383R2): nearly everything, including `sin`, `exp`, `pow` and `sqrt`. `rint`, `nearbyint` and the rounding-mode-dependent conversions are excluded, as are `nan` and the special functions.
- **Atomics** (P3309R3): `std::atomic` and `std::atomic_ref`, which behave as ordinary objects during constant evaluation.
- **Formatting** (P3391R2): `std::format`, `format_to` and the integral `to_string` overloads, but not floating-point or pointer formatting.

For `<cmath>`, [library.c] sets the boundary. A call is a non-constant library call if it raises a floating-point exception other than `FE_INEXACT`. Rounding is fine, so `std::sqrt(2.0)` is a constant. `std::sqrt(-1.0)` raises `FE_INVALID` and `std::log(0.0)` raises `FE_DIVBYZERO`, so neither is a constant, even though both return a value at run time.

Implementations lag here. GCC 16 provides constexpr `stable_sort` and `inplace_vector`, and it has folded `<cmath>` calls as a GCC extension for years, but it defines no `__cpp_lib_constexpr_cmath`. It rejects constexpr `map`, `set`, `list`, `deque`, `unordered_map`, `priority_queue`, `atomic`, `format` and `to_string`. libc++ 21 offers constexpr `list` and `priority_queue` but not the others.

## What is still impossible

- **Escaping allocations.** `constexpr std::vector<int> v{1, 2, 3};` is still ill-formed, because the heap storage would outlive the evaluation. A `constexpr std::string` holding a short literal compiles on both libstdc++ and libc++, but only because of the small-string optimisation, which the standard does not promise.
- **Escaping exceptions**, and any `exception_ptr` that would outlive the evaluation.
- **`reinterpret_cast`**, wrong-type `void*` casts, reading an inactive union member, and `std::bit_cast` involving pointers.
- **`goto`**, `asm`, `va_arg`, `co_await` and `co_yield`, and a call to a non-constexpr function, all of which are disqualified when evaluated.
- **Undefined and erroneous behaviour.** In C++26, an uninitialized automatic variable holds an *erroneous value*, and reading it at run time is erroneous behaviour rather than undefined behaviour. In constant evaluation, erroneous behaviour disqualifies the expression just as undefined behaviour does, and the result of a constant expression may not contain an erroneous value. A variable marked `[[indeterminate]]` has an indeterminate value instead, and reading it is also rejected. The erroneous-behaviour-and-cpp26-language-changes topic covers the run-time side.

```cpp
constexpr int fine() { int x; x = 3; return x; }  // OK: written before read
static_assert(fine() == 3);
// constexpr int bad() { int x; return x; }       // erroneous read: not constant
```

> **Pitfall.** "It compiled as constexpr on my compiler" proves less than it seems. GCC folds `<cmath>` in any mode, and SSO lets short `constexpr` strings through. For portable code, check the `__cpp_lib_constexpr_*` macros, not one compiler's behaviour.

## What to remember

- The sandbox rule is unchanged. Allocations, exception objects and pointers to locals must not escape a constant evaluation.
- A `void*` may be cast back only to a type similar to the object it points to (P2738R1). Placement new is allowed into storage created by the same evaluation (P2747R2).
- `throw`, `try` and `catch` work at compile time (P3068R6), and the `<stdexcept>` types are constexpr (P3378R2). An escaping exception is still an error. `current_exception` and `uncaught_exceptions` are not constexpr (P3842R2).
- Structured bindings may be `constexpr`, and `constexpr` references may refer to locals of the same function invocation (P2686R5). GCC 16 implements only the first part.
- Constexpr constructors now work with virtual bases (P3533R2). `static_assert` accepts computed messages (P2741R3), and those messages are unevaluated when the assertion passes.
- `std::is_within_lifetime` is `consteval` and detects the active union member (P2641R4). Neither GCC 16 nor libc++ 21 ships it.
- Most of `<cmath>` is constexpr, unless the call raises a floating-point exception other than `FE_INEXACT`. Node-based containers, atomics and `format` are constexpr in the draft, but GCC 16 does not implement them yet.
- Erroneous behaviour, like undefined behaviour, disqualifies a constant expression.

## Concept Map Outline

- **constexpr in C++26:** New operations the constant evaluator can check; nothing may still escape the evaluation.
  - **Type erasure:** Operations that make any-like and function_ref-like code usable at compile time.
    - **void* cast (P2738):** Allowed back to a type similar to the pointed-to object; any other target type is not constant.
    - **Placement new (P2747):** Allowed into storage created in the same evaluation, for an object that transparently replaces the old one.
    - **Still banned:** reinterpret_cast, reading inactive union members, and bit_cast involving pointers.
  - **Exceptions (P3068):** throw, try and catch work during constant evaluation.
    - **Must be caught:** An exception that escapes the evaluation makes the expression non-constant.
    - **Library exception types:** std::exception, bad_alloc and, via P3378, logic_error, out_of_range and the bad_*_access types are constexpr.
    - **exception_ptr:** make_exception_ptr and rethrow_exception are constexpr, but an exception_ptr cannot persist in a constexpr variable.
    - **Rolled back (P3842):** current_exception and uncaught_exceptions are not constexpr in N5050.
  - **Bindings and references:** P2686 lets constexpr reach structured bindings and local objects.
    - **constexpr auto [a, b]:** constexpr and constinit apply to the hidden variable e; mutable members are still unreadable.
    - **References to locals:** constexpr int& r = x; is OK when x is an automatic variable of the same function invocation.
    - **Escape is rejected:** A static constexpr reference or a use inside a nested lambda cannot refer to the local.
    - **GCC 16 gap:** Accepts constexpr aggregate bindings but rejects constexpr references and pointers to automatics.
  - **Smaller language changes:** Three constexpr additions that each remove a long-standing workaround.
    - **Virtual bases (P3533):** Constexpr constructors and destructors may have virtual bases; only coroutines are not constexpr-suitable.
    - **static_assert messages (P2741):** Any constant with size() and data(); evaluated only when the assertion fails.
    - **is_within_lifetime (P2641):** consteval test of whether p points to a live object; finds the active union member. Not in GCC 16.
  - **Library:** Large parts of the library became constexpr in C++26.
    - **Containers (P3372):** list, deque, map, set, unordered containers and the adaptors; GCC 16 does not implement these yet.
    - **Stable algorithms (P2562):** stable_sort, stable_partition and inplace_merge are constexpr; GCC 16 supports stable_sort.
    - **cmath (P1383):** Constant unless the call raises a floating-point exception other than FE_INEXACT, so sqrt(-1.0) is not.
    - **atomic and format:** P3309 makes atomic constexpr and P3391 does the same for format and integral to_string; neither is in GCC 16.
  - **Still impossible:** The exit check and the disqualifying operations remain.
    - **Escaping allocations:** constexpr std::vector with elements is ill-formed; short strings pass only through SSO.
    - **Disqualified operations:** goto, asm, va_arg, co_await, co_yield, and calls to non-constexpr functions.
    - **Erroneous behaviour:** Reading an uninitialized local is erroneous in C++26 and, like UB, makes the expression non-constant.

## Standardese Quiz Questions

### Question 1 [warmup] ([expr.const.core], [expr.static.cast])

Under the C++26 draft, what is true of this program?

```cpp
constexpr int roundtrip() {
  int x = 42;
  void* p = &x;
  return *static_cast<int*>(p);
}

static_assert(roundtrip() == 42);

int main() {}
```

A. Ill-formed: a cast from `void*` is never allowed in a constant expression
B. Ill-formed: `static_cast` from `void*` must be written as `reinterpret_cast`
C. Well-formed: the `void*` points to an `int`, so casting it back to `int*` is allowed
D. Undefined behavior, because the type information is lost in `void*`

**Answer (C):** Well-formed: the `void*` points to an `int`, so casting it back to `int*` is allowed

**Why:** C++26 (P2738R1) allows a conversion from `void*` to an object pointer type in a constant expression when the pointer is null or points to an object whose type is similar to the target type. Here it points to an `int` and is cast to `int*`, so the assertion is a valid constant expression. The first option was the rule through C++23. A cast to an unrelated type such as `short*` is still not a constant expression, and `reinterpret_cast` is still banned outright.

### Question 2 [warmup] ([expr.const.core], [except.throw], [std.exceptions])

In C++26, is this program well-formed?

```cpp
#include <stdexcept>

constexpr int digit(char c) {
  if (c < '0' || c > '9') throw std::invalid_argument("not a digit");
  return c - '0';
}

constexpr int digit_or(char c, int fallback) {
  try { return digit(c); }
  catch (const std::invalid_argument&) { return fallback; }
}

static_assert(digit_or('x', -1) == -1);

int main() {}
```

A. Yes: the exception is thrown and caught within the constant evaluation
B. No: a throw-expression is never a core constant expression
C. No: `std::invalid_argument` is not a literal type, so it cannot be constructed at compile time
D. Yes, but only because the compiler skips the `throw` in constant evaluation

**Answer (A):** Yes: the exception is thrown and caught within the constant evaluation

**Why:** P3068R6 lets an exception be thrown and caught during constant evaluation, provided the exception object and any copies of it are destroyed before the evaluation ends. Here the handler in `digit_or` catches it, so the whole call is a constant expression with value -1. The `std::invalid_argument` objection was true before C++26, but P3378R2 made the `<stdexcept>` classes constexpr. An exception that escaped, as in `constexpr int bad = digit('x');`, would still make the initialization ill-formed.

### Question 3 [warmup] ([dcl.pre])

In C++26, what happens, and what text does the standard's recommended practice say the diagnostic should include?

```cpp
#include <cstddef>

struct Msg {
  constexpr std::size_t size() const { return 5; }
  constexpr const char* data() const { return "hello world"; }
};

static_assert(sizeof(char) == 2, Msg{});

int main() {}
```

A. Ill-formed, and the diagnostic should include `hello world`
B. Ill-formed, and the diagnostic should include `hello`
C. Ill-formed, because a `static_assert` message must be a string literal
D. Well-formed, because the message object makes the assertion non-fatal

**Answer (B):** Ill-formed, and the diagnostic should include `hello`

**Why:** `sizeof(char)` is 1 by definition, so the assertion fails and the program is ill-formed. Since C++26 (P2741R3), the message can be any constant expression with `size()` and `data()` members. Its text is the first `size()` code units starting at `data()`, which here is `hello`, not the whole null-terminated string. The string-literal-only rule held through C++23.

### Question 4 [tricky] ([dcl.constexpr], [expr.const.init])

Under the C++26 draft N5050, which of the two declarations in `f` is ill-formed?

```cpp
void f() {
  int x = 0;
  constexpr int& r = x;         // #1
  static constexpr int& s = x;  // #2
  (void)r; (void)s;
}

int main() {}
```

A. Neither
B. Only #1
C. Only #2
D. Both

**Answer (C):** Only #2

**Why:** P2686R5 made an automatic object constexpr-referenceable from points in the same function invocation, so a `constexpr` reference to the local `x` is allowed (#1). A `static` reference outlives the invocation, and the draft checks it against the nearest namespace-scope point after the declaration, where `x` is not constexpr-referenceable, so #2 is ill-formed. N5050 uses this exact pair as an example in [dcl.constexpr]. "Both" is the C++23 answer, and it is also what GCC 16 does, because GCC has not implemented this part of P2686.

### Question 5 [tricky] ([propagation], [exception.syn], [expr.const.core])

Under the C++26 draft N5050, is this program well-formed?

```cpp
#include <exception>

constexpr bool handling() {
  try {
    throw 1;
  } catch (...) {
    return std::current_exception() != nullptr;
  }
}

static_assert(handling());

int main() {}
```

A. Yes: P3068 made `std::current_exception` constexpr
B. No: a `catch (...)` handler cannot appear in a constexpr function
C. Yes, but the value of `handling()` is unspecified
D. No: `std::current_exception` is not constexpr, so calling it is not a constant expression

**Answer (D):** No: `std::current_exception` is not constexpr, so calling it is not a constant expression

**Why:** P3068 originally marked `std::current_exception` and `std::uncaught_exceptions` constexpr. Because both read global exception state, P3842R2 removed that before C++26 was finalized, and in N5050 only an exposition-only constexpr helper remains. Calling a non-constexpr function disqualifies the expression, so the `static_assert` is ill-formed. Throwing, catching and `throw;` are still fine, which is why the first option is tempting. GCC 16 rejects the call to the non-constexpr function.

### Question 6 [tricky] ([library.c], [c.math], [expr.const.core])

In C++26, on an implementation that uses IEEE 754 `double`, which of these declarations is ill-formed?

```cpp
#include <cmath>

constexpr double a = std::sqrt(2.0);
constexpr double b = std::sqrt(-1.0);

int main() {}
```

A. Neither: both calls return a value, so both are constant
B. Only `b`: it raises `FE_INVALID`
C. Only `a`: its result is inexact, so it is not a constant
D. Both: `<cmath>` functions are not constexpr

**Answer (B):** Only `b`: it raises `FE_INVALID`

**Why:** P1383R2 made most of `<cmath>` constexpr. [library.c] says a call is a non-constant library call if it raises a floating-point exception other than `FE_INEXACT`. `sqrt(2.0)` raises only `FE_INEXACT`, so `a` is fine. `sqrt(-1.0)` raises `FE_INVALID` under Annex F, so `b` is not constant-initialized, even though at run time the call would just return a NaN. The "Both" answer describes C++23, where only a small set of functions such as `fabs` were constexpr.

### Question 7 [standardese] ([dcl.pre], [expr.context])

Under the C++26 draft, is this declaration well-formed?

```cpp
#include <cstddef>

std::size_t runtime_size();

struct RT {
  std::size_t size() const { return runtime_size(); }
  const char* data() const { return "x"; }
};

static_assert(sizeof(int) >= 1, RT{});

int main() {}
```

A. Yes: the condition is true, so the message is an unevaluated operand
B. No: `size()` must be a converted constant expression
C. No: `RT` is not a literal type
D. Yes, but only if `runtime_size()` is defined

**Answer (A):** Yes: the condition is true, so the message is an unevaluated operand

**Why:** [dcl.pre] only requires that `M.size()` be implicitly convertible to `std::size_t` and that `M.data()` be implicitly convertible to `const char*`, which is true here. The constant-expression requirements on `size()` and `data()` apply only when the assertion fails. When the condition is true, the declaration has no effect and the message is an unevaluated operand, so nothing is odr-used. GCC 16 accepts the declaration. Clang 21 reports it through a warning that is an error by default, `-Winvalid-static-assert-message`, which is stricter than the draft.

### Question 8 [standardese] ([meta.const.eval], [basic.life])

Which statement about `std::is_within_lifetime` matches the C++26 draft?

A. It is `constexpr`, and at run time it inspects the object's bytes to find the active union member
B. It reads `*p` and returns `false` instead of failing if the read would be undefined
C. It is `consteval`, returns whether `p` points to an object within its lifetime, and does not read the object
D. It works for any pointer, including pointers to globals that are not usable in constant expressions

**Answer (C):** It is `consteval`, returns whether `p` points to an object within its lifetime, and does not read the object

**Why:** [meta.const.eval] declares `template<class U = void, class T> consteval bool is_within_lifetime(const T* p) noexcept`. It returns true if `p` points to an object within its lifetime, without performing a read, which is how it can detect the active member of a union. Because it is `consteval`, run-time code needs `if consteval` and a separate path. A call is ill-formed unless `p` points to an object usable in constant expressions or to one whose complete object's lifetime began within the evaluation. That rules out the last option.
