c++ - Workaround for lvalue-to-rvalue conversion of the inactive member of a union within relaxed constant expressions -


The larval-to-rivalview conversion is not a continuous expression for converting a union into a union. given:

  template   

and constexpr function foo :

  in the template's & lt; Square t, square u & gt; Constexpr auto foo () {A & lt; T, U & gt; On{}); Return a.u_; }   

The following program:

  int main () {constexpr auto test = foo & lt; Int, double> (); Return 0; }   

Fails with error message:

  Error: constexpr variable 'test' constexpr auto test = foo & lt start by a continuous expression should be done; Integer, double & gt; (); ^ ~~~~~~~~~~~~~~~~~~ NOTE: The member's member 'u_' is not allowed to be read with active member 'T_', in a continuous expression a.u_ ; ^ Note: In the call 'fu ()' constexpr auto test = foo & lt; Int, double> (); ^ 1 error occurred.   

Is this behavior achievable in C ++ 14 continuous expression? . reinterpret_cast is not allowed either

Inspiration:. I am trying to make the Google testing floating point compare utility constexpr

No, C ++ 14 There is no way of typing in continuous expression. There is no way to do this outside of continuous expression; The code you show will have undefined behavior in runtime.

For example, why not normally refuse, consider this:

  union y {int * p; Size_t n; }; Int a; Constexpr UU = {& amp; One}; Static_assert (u.n! = 0x400e158, "One is at my favorite address");   

If this permission was granted, the implementation would be required to determine the runtime address of a during the compilation.

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

C++ Array Type Not Assignable in Copy Constructor -