[Bug c++/103511] __builtin_bit_cast requires a constructor call

2024-04-14 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103511

Andrew Pinski  changed:

   What|Removed |Added

   Last reconfirmed||2024-04-14
 Status|UNCONFIRMED |NEW
 Ever confirmed|0   |1

--- Comment #6 from Andrew Pinski  ---
Confirmed. Both clang and MSVC accept this.

[Bug c++/103511] __builtin_bit_cast requires a constructor call

2023-07-07 Thread ldionne.2 at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103511

--- Comment #5 from Louis Dionne  ---
Note that my claim about TriviallyCopyable is taken from the Standard here, for
reference (even though Jason probably knows this by heart :-).

https://eel.is/c++draft/class.prop#1:

> A trivially copyable class is a class:
> (1.1) that has at least one eligible copy constructor, move constructor, copy 
> assignment operator, or move assignment operator ([special], 
> [class.copy.ctor], [class.copy.assign]),
> (1.2) where each eligible copy constructor, move constructor, copy assignment 
> operator, and move assignment operator is trivial, and
> (1.3) that has a trivial, non-deleted destructor ([class.dtor]).

[Bug c++/103511] __builtin_bit_cast requires a constructor call

2023-07-07 Thread jakub at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103511

--- Comment #4 from Jakub Jelinek  ---
Jason, your call on this?

[Bug c++/103511] __builtin_bit_cast requires a constructor call

2023-07-07 Thread ldionne.2 at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103511

Louis Dionne  changed:

   What|Removed |Added

 CC||ldionne.2 at gmail dot com

--- Comment #3 from Louis Dionne  ---
I concur with the reporter of this issue. `bit_cast` requires the types to be
TriviallyCopyable. In turn, TriviallyCopyable requires (for class types) that
there's at least one eligible copy constructor, move constructor, copy
assignment operator, or move assignment operator. It doesn't say which of those
has to be valid, but at least one of those has to be valid.

However, GCC's implementation of __builtin_bit_cast seems to always require at
least a copy or a move constructor, which seems like a bug to me.

For example, the following code should be valid IIUC, but it fails with GCC:

  struct CopyAssignable {
CopyAssignable() = default;
int value = 0;

CopyAssignable(const CopyAssignable&)= delete;
CopyAssignable(CopyAssignable&&) = delete;
CopyAssignable& operator=(const CopyAssignable&) = default;
CopyAssignable& operator=(CopyAssignable&&)  = delete;
  };

  struct MoveAssignable {
MoveAssignable() = default;
int value = 0;

MoveAssignable(const MoveAssignable&)= delete;
MoveAssignable(MoveAssignable&&) = delete;
MoveAssignable& operator=(const MoveAssignable&) = delete;
MoveAssignable& operator=(MoveAssignable&&)  = default;
  };

  int main(int, char**) {
CopyAssignable foo1;
(void)__builtin_bit_cast(CopyAssignable, foo1); // doesn't work
MoveAssignable foo2;
(void)__builtin_bit_cast(MoveAssignable, foo2); // doesn't work
  }

Full example on Godbolt showing that this is accepted by Clang and MSVC but
rejected by GCC: https://godbolt.org/z/548YKndrK
I am running into this issue while trying to fix something in libc++ here:
https://reviews.llvm.org/D154613

[Bug c++/103511] __builtin_bit_cast requires a constructor call

2021-12-01 Thread jakub at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103511

Jakub Jelinek  changed:

   What|Removed |Added

 CC||jakub at gcc dot gnu.org,
   ||jason at gcc dot gnu.org

--- Comment #2 from Jakub Jelinek  ---
If __builtin_bit_cast should bypass the ctors, then perhaps something like:
--- gcc/cp/semantics.c.jj
+++ gcc/cp/semantics.c
@@ -11673,7 +11673,7 @@ cp_build_bit_cast (location_t loc, tree type, tree arg,
   SET_EXPR_LOCATION (ret, loc);

   if (!processing_template_decl && CLASS_TYPE_P (type))
-ret = get_target_expr_sfinae (ret, complain);
+ret = force_target_expr (type, ret, complain);

   return ret;
 }
would handle it, but I don't know if that is desirable or the right thing.

[Bug c++/103511] __builtin_bit_cast requires a constructor call

2021-12-01 Thread redi at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103511

--- Comment #1 from Jonathan Wakely  ---
This seems like a defect in the standard.