C++ Logo

liaison

Advanced search

[isocpp-wg14/wg21-liaison] Potentially-constant initialization (const variables in constant expressions): Lessons learned from C++ useful for C?

From: Hubert Tong <hubert.reinterpretcast_at_[hidden]>
Date: Mon, 20 Oct 2025 14:17:20 -0400
Hello,

N3693: Integer Constant Expression Initialized const Integer-Typed
Declarations are Implicitly constexpr
<https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3693.htm> proposes to
solidify, in C, the ability to evaluate variables in constant expressions
even when they are merely const-qualified.

The paper presents rationale for why such a change is desirable for C. It
can also increase the compatibility of code that may be present in headers
shared between C and C++.

The C++ wording maintains the ability to use the definitions of variables
with non-volatile const-qualified integral or enumeration type in constant
expressions via its wording for potentially-constant variables (
https://wg21.link/expr.const#def:potentially-constant).

In the thread starting with
http://lists.isocpp.org/lib-ext/2025/08/30600.php, "Paper fixing
problematic interaction between constexpr exception functions and
potentially-constant initialization", there are sentiments that being able
to use such non-constexpr variables in constant expressions is not exactly
desirable. However, such sentiments may have to do specifically with how
C++ is evolving.

I was not an active participant in said thread, and I am not in a position
to present the information from it.

I am hoping that people more informed than I can provide input on whether
adoption of N3693 by the C committee is of concern.

-- HT

Received on 2025-10-20 18:17:50