Repository navigation
expression must have a constant value / cannot use reinterpret_cast in constant-expression evaluation #347
akenter-mathworks
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Hi,
I would like to report an issue but I cannot create one with the New Issue button, so I follow the suggestion in Contributing.md of posting it here in the discussions.
WIth this repro.cpp:
struct S { int a; int b; };
constexpr long off =
reinterpret_cast<const char*>(
&reinterpret_cast<const S*>(16)->b) -
reinterpret_cast<const char*>(16);
I get the following messages on Windows with edgcpfe --microsoft --microsoft_version=1944 --ms_c++20 -w repro.cpp:
"repro.cpp", line 3: error: expression must have a constant value
reinterpret_cast<const char*>(
^
"repro.cpp", line 3: note: cannot use reinterpret_cast in constant-expression evaluation
reinterpret_cast<const char*>(
^
I checked on godbolt.org that all versions of Visual accept this repro. The problem was observed with Boost header protobuf3\include\google\protobuf\implicit_weak_message.h. The reinterpret_casts come from macro PROTOBUF_FIELD_OFFSET, when neither of clang and GNUC is defined.
I investigated and I could solve it by adding these lines:
if (microsoft_mode) {
allow_reinterpret_cast = TRUE;
}
at line 34333 of interpret_dynamic_init_full (immediately after the if (!in_front_end || il_lowering_underway) at the beginning of the function.
That works with our regression tests (we have ~30,000 at my company), but I must admit I didn't verify with the EDG tests, yet.
I built the front-end with this configuration:
#define DEFAULT_USE_PREDEFINED_MACRO_FILE 0
#include "defines_win32.h"
Thanks,
Arjan Kenter
All reactions