-
Notifications
You must be signed in to change notification settings - Fork 258
[BUG] constexpr
without ==
#761
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
This could be considered a sufficiently niche issue for the sake of the general simplicity of Cpp2. There's similar issues with the mapping of Cpp1 specifiers to Cpp2.
The last one is for performance. |
From https://wg21.link/p2996r0#enum-to-string: template for (constexpr auto e : std::meta::members_of(^E)) { The non-
A way to support the proposed Cpp1 Another proposed syntax was |
It also seems that
The ordering metafunctions will be Only The
Or maybe |
Maybe
|
Doesn't seem possible without extending the reflection API. |
See also #959. |
Title:
constexpr
without==
.Description:
In reading P2996R0 Reflection for C++26 2.3 List of Types to List of Sizes,
I couldn't help but wonder,
how would we declare an uninitialized
constexpr
variable in Cpp2.This isn't a thing in Cpp1, yet.
But I think it's been mentioned as a possible relaxation to
constexpr
,including modifiable
constexpr
globals (per TU?).But there's actually a context that already affects Cpp2.
An
@interface
with aconstexpr
function (https://compiler-explorer.com/z/aro9K15b1):In Cpp2, the best approximation is (https://cpp2.godbolt.org/z/7Gha4YdK7):
But that errors with:
It's not possible for
X
to declare a constexpr default constructor orf
.We could attempt using
@polymorphic_base
.In Cpp1 (https://compiler-explorer.com/z/Y653WPM7j):
In Cpp2 (https://cpp2.godbolt.org/z/4MYv5E9vz):
That's a big jump in the API of
X
(a variable can be instantiated,
calling
f
on isn't a compile-time error,calling
std::terminate()
inf
helps at compile-time but otherwise delays to runtime).And it happens to work because the return type is a mere
char
(it could be a more complicated data type,
the data-less polymorphic base might need the help of globals).
Minimal reproducer (https://cpp2.godbolt.org/z/7Gha4YdK7):
Commands:
cppfront main.cpp2 clang++18 -std=c++23 -stdlib=libc++ -lc++abi -pedantic-errors -Wall -Wextra -Wconversion -Werror=unused-result -I . main.cpp
Expected result:
Consideration to
constexpr
without==
.It might be relevant to some users today.
Cpp1 language evolution might also make it very relevant.
Herb has mentioned limiting global variables to
constexpr
.That could make
x: int;
at namespace scope an uninitializedconstexpr
variable.But that wouldn't help with other entities that can be left uninitialized.
Actual result and error:
Cpp2 lowered to Cpp1:
Output:
See also:
=
and==
: Dropping one extra `=` from declarations to make them less divergent from Cpp1 syntax #742.f: (x) x;
is neverconstexpr
: Terser function syntax? #714 (reply in thread).The text was updated successfully, but these errors were encountered: