-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Remove non-floating complex
#5984
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
9ae6a0d
b160318
ceafe14
1f5e58d
4f74193
0351a2c
e79b863
26bd050
a49e5b2
e8a04c3
b5e651c
40e9d1b
3b486dd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -1321,6 +1321,23 @@ constexpr complex<long double>::complex(const complex<float>& _Right) noexcept / | |||||||||||||||||||||
| constexpr complex<long double>::complex(const complex<double>& _Right) noexcept // strengthened | ||||||||||||||||||||||
| : _Complex_base<long double, _Lcomplex_value>(_Right.real(), _Right.imag()) {} | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| #if !_HAS_NONFLOATING_COMPLEX | ||||||||||||||||||||||
| _EXPORT_STD template <class _Ty> | ||||||||||||||||||||||
| class complex { | ||||||||||||||||||||||
| static_assert(false, | ||||||||||||||||||||||
| "The effect of instantiating the template std::complex for any type other than float, double, or long double " | ||||||||||||||||||||||
| "is unspecified. The possibility of such instantiation will be removed in a future version. " | ||||||||||||||||||||||
|
||||||||||||||||||||||
| "is unspecified. The possibility of such instantiation will be removed in a future version. " | |
| "is unspecified. Such instantiations are disabled by default in this version. " |
Copilot
AI
Apr 30, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
static_assert(false, ...) inside a class template is non-dependent, so it will fire immediately when is parsed (even if std::complex<T> is never instantiated), effectively breaking all users when _HAS_NONFLOATING_COMPLEX is 0. Make the assertion dependent on _Ty (e.g., assert on a dependent boolean/trait) so the diagnostic is emitted only when std::complex<non-floating> is actually instantiated.
Copilot
AI
Apr 29, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The deleted deduction-only ctor complex(const _Ty& = _Ty(), const _Ty& = _Ty()) can be ill-formed for some _Ty (e.g. _Ty=void makes const void& invalid; non-default-constructible _Ty makes the default arguments ill-formed). That can cause diagnostics that mask or precede the intended class-scope static_assert message. Consider avoiding _Ty() defaults (e.g. provide separate 1-arg/2-arg deleted overloads without defaults) and/or using a parameter alias that is always a valid object type (e.g. conditional_t<is_void_v<_Ty>, int, _Ty>) so the template remains well-formed and reliably hits the static_assert.
| // For deduction, primary template is used, so keeping a couple of constructors around | |
| constexpr complex(const _Ty& = _Ty(), const _Ty& = _Ty()) = delete; | |
| using _Deduction_type = conditional_t<is_void_v<_Ty>, int, _Ty>; | |
| // For deduction, primary template is used, so keeping a couple of constructors around | |
| constexpr complex() = delete; | |
| constexpr complex(const _Deduction_type&) = delete; | |
| constexpr complex(const _Deduction_type&, const _Deduction_type&) = delete; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We've been there. C++14 still needs to be supported here.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,7 +3,7 @@ | |
|
|
||
| RUNALL_INCLUDE ..\universal_prefix.lst | ||
| RUNALL_CROSSLIST | ||
| * PM_CL="/EHsc /MTd /std:c++latest /permissive- /utf-8 /FImsvc_stdlib_force_include.h /wd4643" | ||
| * PM_CL="/EHsc /MTd /std:c++latest /permissive- /utf-8 /FImsvc_stdlib_force_include.h /wd4643 /D_HAS_NONFLOATING_COMPLEX=1" | ||
|
||
| RUNALL_CROSSLIST | ||
| PM_CL="/Zc:preprocessor" | ||
| ASAN PM_CL="-fsanitize=address /Zi" PM_LINK="/debug" | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be better to say "a cv-unqualified floating-point type" (see [complex.numbers.general]/2) which looks more future-proof?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure. I copied that from the deprecation message.