[Bug c++/49171] [C++0x][constexpr] Constant expressions support reinterpret_cast
stsp at users dot sourceforge.net
gcc-bugzilla@gcc.gnu.org
Wed Feb 12 23:47:00 GMT 2020
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=49171
--- Comment #26 from Stas Sergeev <stsp at users dot sourceforge.net> ---
(In reply to Jonathan Wakely from comment #23)
> What you want (and what everybody I've seen asking for similar things)
But comment #17 shows the different use of
reinterpret_cast - offsetof in templates.
What work-around would you suggest for that case?
> A more limited extension that solves the problem is a lot more reasonable.
If it would have been done before the feature
is removed, and for every possible use-case, then
yes. :)
In any case, what limited extension would you
suggest for the offsetof case?
Would something like the below[1] considered as such extension
(currently doesn't compile):
---
template <auto O>
struct B {
static constexpr int off = O();
};
struct A {
char a;
B<[](){ return offsetof(A, a); }> b;
};
---
Below is the very similar code[2] that actually compiles:
---
template <auto O>
struct B {
static constexpr int off = O();
};
struct A {
char a;
static constexpr int off(void) { return offsetof(A, a); }
B<off> b;
};
---
So given that [2] compiles and works, and [1]
can be used as a limited work-around for the
offsetof case (at least in my case [1] is enough),
I wonder if it can be considered as a possible extension.
More information about the Gcc-bugs
mailing list