public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/105996] New: reinterpret_cast in constexpr failure creating a pair with a function pointer of class parent
@ 2022-06-16  8:40 jdapena at igalia dot com
  2022-06-16 11:02 ` [Bug c++/105996] [12/11/12/13 Regression] " redi at gcc dot gnu.org
                   ` (11 more replies)
  0 siblings, 12 replies; 13+ messages in thread
From: jdapena at igalia dot com @ 2022-06-16  8:40 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105996

            Bug ID: 105996
           Summary: reinterpret_cast in constexpr failure creating a pair
                    with a function pointer of class parent
           Product: gcc
           Version: 12.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jdapena at igalia dot com
  Target Milestone: ---

Created attachment 53150
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=53150&action=edit
Test case

When creating an std::pair with a parameter that is a function pointer of the
parent class (but declared as function pointer of the same class), libstdc++
implementation will try to forward the pointer, even if it is the same type
(see the attached example).

This code is valid in Clang and MSVC, and was valid in GCC 5.x-7.x.


This has been detected through Chromium development with errors to compile
https://chromium.googlesource.com/chromium/src.git/+/refs/tags/105.0.5123.1/pdf/pdf_view_web_plugin.cc#879

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug c++/105996] [12/11/12/13 Regression] reinterpret_cast in constexpr failure creating a pair with a function pointer of class parent
  2022-06-16  8:40 [Bug c++/105996] New: reinterpret_cast in constexpr failure creating a pair with a function pointer of class parent jdapena at igalia dot com
@ 2022-06-16 11:02 ` redi at gcc dot gnu.org
  2022-06-16 15:36 ` [Bug c++/105996] [10/11/12/13 " jakub at gcc dot gnu.org
                   ` (10 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: redi at gcc dot gnu.org @ 2022-06-16 11:02 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105996

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|reinterpret_cast in         |[12/11/12/13 Regression]
                   |constexpr failure creating  |reinterpret_cast in
                   |a pair with a function      |constexpr failure creating
                   |pointer of class parent     |a pair with a function
                   |                            |pointer of class parent
   Last reconfirmed|                            |2022-06-16
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1
      Known to fail|                            |10.3.0, 11.3.0, 12.1.0,
                   |                            |13.0, 8.1.0
                 CC|                            |jakub at gcc dot gnu.org
      Known to work|                            |7.5.0

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Reduced:

template<typename T, typename U> constexpr int make_pair(T&&, U&&) { return 0;
}

struct A {
  void CB() {}
};

struct B : public A {
  void Test() {
  using MyCB = void (B::*)();
  static constexpr auto p = make_pair<int, MyCB>(1, &B::CB);
  }
};


105996.C: In member function 'void B::Test()':
105996.C:10:53: error: a reinterpret_cast is not a constant expression
   static constexpr auto p = make_pair<int, MyCB>(1, &B::CB);
                                                     ^~
Started to fail some time before r256448, probably 


commit e99ef40892b598eeb3fa496cc472e111675d7f6c
Author: Jakub Jelinek 
Date:   Wed Jan 10 16:59:09 2018

    re PR c++/81327 (cast to void* does not suppress -Wclass-memaccess)

            PR c++/81327
            * call.c (maybe_warn_class_memaccess): Add forward declaration.
            Change last argument from tree * to const vec<tree, va_gc> *,
adjust
            args uses and check number of operands too.  Don't strip away any
            nops.  Use maybe_constant_value when looking for INTEGER_CST args.
            Deal with src argument not having pointer type.  Check
            tree_fits_uhwi_p before calling tree_to_uhwi.  Remove useless
            test.
            (build_over_call): Call maybe_warn_class_memaccess here on the
            original arguments.
            (build_cxx_call): Rather than here on converted arguments.

            * g++.dg/Wclass-memaccess-2.C: Don't expect a warning when
explicitly
            cast to void *.

    From-SVN: r256440

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug c++/105996] [10/11/12/13 Regression] reinterpret_cast in constexpr failure creating a pair with a function pointer of class parent
  2022-06-16  8:40 [Bug c++/105996] New: reinterpret_cast in constexpr failure creating a pair with a function pointer of class parent jdapena at igalia dot com
  2022-06-16 11:02 ` [Bug c++/105996] [12/11/12/13 Regression] " redi at gcc dot gnu.org
@ 2022-06-16 15:36 ` jakub at gcc dot gnu.org
  2022-06-16 15:39 ` jakub at gcc dot gnu.org
                   ` (9 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: jakub at gcc dot gnu.org @ 2022-06-16 15:36 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105996

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jason at gcc dot gnu.org

--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
The problem is that build_ptrmemfunc in
9587          if (TREE_CODE (pfn) != PTRMEM_CST)
9588            {
9589              if (same_type_p (to_type, pfn_type))
9590                return pfn;
9591              else if (integer_zerop (n) && TREE_CODE (pfn) != CONSTRUCTOR)
9592                return build_reinterpret_cast (input_location, to_type,
pfn, 
9593                                               complain);
9594            }
calls build_reintepret_cast from void (A::*)() typed pfn to void (B::*)() type,
and when we then constant expression evaluate it, we reject it because
reinterpret_cast is not a core constant expression as per
https://eel.is/c++draft/expr.const#5.16
Now, is this reinterpret cast just some implementation detail under the hood in
which we should somehow arrange for REINTERPRET_CAST_P bit not be set (or
afterwards remove it)?

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug c++/105996] [10/11/12/13 Regression] reinterpret_cast in constexpr failure creating a pair with a function pointer of class parent
  2022-06-16  8:40 [Bug c++/105996] New: reinterpret_cast in constexpr failure creating a pair with a function pointer of class parent jdapena at igalia dot com
  2022-06-16 11:02 ` [Bug c++/105996] [12/11/12/13 Regression] " redi at gcc dot gnu.org
  2022-06-16 15:36 ` [Bug c++/105996] [10/11/12/13 " jakub at gcc dot gnu.org
@ 2022-06-16 15:39 ` jakub at gcc dot gnu.org
  2022-06-20  9:49 ` rguenth at gcc dot gnu.org
                   ` (8 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: jakub at gcc dot gnu.org @ 2022-06-16 15:39 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105996

--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Or can we say just call cp_convert instead of build_reinterpret_cast in that
case?

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug c++/105996] [10/11/12/13 Regression] reinterpret_cast in constexpr failure creating a pair with a function pointer of class parent
  2022-06-16  8:40 [Bug c++/105996] New: reinterpret_cast in constexpr failure creating a pair with a function pointer of class parent jdapena at igalia dot com
                   ` (2 preceding siblings ...)
  2022-06-16 15:39 ` jakub at gcc dot gnu.org
@ 2022-06-20  9:49 ` rguenth at gcc dot gnu.org
  2022-06-28 10:49 ` jakub at gcc dot gnu.org
                   ` (7 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-06-20  9:49 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105996

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |10.4
           Priority|P3                          |P2

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug c++/105996] [10/11/12/13 Regression] reinterpret_cast in constexpr failure creating a pair with a function pointer of class parent
  2022-06-16  8:40 [Bug c++/105996] New: reinterpret_cast in constexpr failure creating a pair with a function pointer of class parent jdapena at igalia dot com
                   ` (3 preceding siblings ...)
  2022-06-20  9:49 ` rguenth at gcc dot gnu.org
@ 2022-06-28 10:49 ` jakub at gcc dot gnu.org
  2023-03-23 20:55 ` jason at gcc dot gnu.org
                   ` (6 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: jakub at gcc dot gnu.org @ 2022-06-28 10:49 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105996

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|10.4                        |10.5

--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
GCC 10.4 is being released, retargeting bugs to GCC 10.5.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug c++/105996] [10/11/12/13 Regression] reinterpret_cast in constexpr failure creating a pair with a function pointer of class parent
  2022-06-16  8:40 [Bug c++/105996] New: reinterpret_cast in constexpr failure creating a pair with a function pointer of class parent jdapena at igalia dot com
                   ` (4 preceding siblings ...)
  2022-06-28 10:49 ` jakub at gcc dot gnu.org
@ 2023-03-23 20:55 ` jason at gcc dot gnu.org
  2023-03-23 21:39 ` cvs-commit at gcc dot gnu.org
                   ` (5 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: jason at gcc dot gnu.org @ 2023-03-23 20:55 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105996

Jason Merrill <jason at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|unassigned at gcc dot gnu.org      |jason at gcc dot gnu.org
             Status|NEW                         |ASSIGNED

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug c++/105996] [10/11/12/13 Regression] reinterpret_cast in constexpr failure creating a pair with a function pointer of class parent
  2022-06-16  8:40 [Bug c++/105996] New: reinterpret_cast in constexpr failure creating a pair with a function pointer of class parent jdapena at igalia dot com
                   ` (5 preceding siblings ...)
  2023-03-23 20:55 ` jason at gcc dot gnu.org
@ 2023-03-23 21:39 ` cvs-commit at gcc dot gnu.org
  2023-04-18 20:46 ` [Bug c++/105996] [10/11/12 " cvs-commit at gcc dot gnu.org
                   ` (4 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-03-23 21:39 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105996

--- Comment #5 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Jason Merrill <jason@gcc.gnu.org>:

https://gcc.gnu.org/g:c4792bd1de0621932a47fb86aca09fafafdb2972

commit r13-6840-gc4792bd1de0621932a47fb86aca09fafafdb2972
Author: Jason Merrill <jason@redhat.com>
Date:   Thu Mar 23 16:50:09 2023 -0400

    c++: constexpr PMF conversion [PR105996]

    Here, we were calling build_reinterpret_cast regardless of whether there
was
    actually a cast, and that now sets REINTERPRET_CAST_P.  But that
    optimization seems dodgy anyway, as it involves NOP_EXPR from one
    RECORD_TYPE to another and we try to reserve NOP_EXPR for fundamental
types.
    And the generated code seems the same, so let's drop it.  And also strip
    location wrappers.

            PR c++/105996

    gcc/cp/ChangeLog:

            * typeck.cc (build_ptrmemfunc): Drop 0-offset optimization
            and location wrappers.

    gcc/testsuite/ChangeLog:

            * g++.dg/cpp0x/constexpr-pmf3.C: New test.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug c++/105996] [10/11/12 Regression] reinterpret_cast in constexpr failure creating a pair with a function pointer of class parent
  2022-06-16  8:40 [Bug c++/105996] New: reinterpret_cast in constexpr failure creating a pair with a function pointer of class parent jdapena at igalia dot com
                   ` (6 preceding siblings ...)
  2023-03-23 21:39 ` cvs-commit at gcc dot gnu.org
@ 2023-04-18 20:46 ` cvs-commit at gcc dot gnu.org
  2023-04-21 20:28 ` [Bug c++/105996] [10/11 " cvs-commit at gcc dot gnu.org
                   ` (3 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-04-18 20:46 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105996

--- Comment #6 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-12 branch has been updated by Jason Merrill
<jason@gcc.gnu.org>:

https://gcc.gnu.org/g:12d7fb7e5810cc5e394d3cbea43d1b19ea7f9348

commit r12-9442-g12d7fb7e5810cc5e394d3cbea43d1b19ea7f9348
Author: Jason Merrill <jason@redhat.com>
Date:   Thu Mar 23 16:50:09 2023 -0400

    c++: constexpr PMF conversion [PR105996]

    Here, we were calling build_reinterpret_cast regardless of whether there
was
    actually a cast, and that now sets REINTERPRET_CAST_P.  But that
    optimization seems dodgy anyway, as it involves NOP_EXPR from one
    RECORD_TYPE to another and we try to reserve NOP_EXPR for fundamental
types.
    And the generated code seems the same, so let's drop it.  And also strip
    location wrappers.

            PR c++/105996

    gcc/cp/ChangeLog:

            * typeck.cc (build_ptrmemfunc): Drop 0-offset optimization
            and location wrappers.

    gcc/testsuite/ChangeLog:

            * g++.dg/cpp0x/constexpr-pmf3.C: New test.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug c++/105996] [10/11 Regression] reinterpret_cast in constexpr failure creating a pair with a function pointer of class parent
  2022-06-16  8:40 [Bug c++/105996] New: reinterpret_cast in constexpr failure creating a pair with a function pointer of class parent jdapena at igalia dot com
                   ` (7 preceding siblings ...)
  2023-04-18 20:46 ` [Bug c++/105996] [10/11/12 " cvs-commit at gcc dot gnu.org
@ 2023-04-21 20:28 ` cvs-commit at gcc dot gnu.org
  2023-04-22  0:23 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-04-21 20:28 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105996

--- Comment #7 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-10 branch has been updated by Jason Merrill
<jason@gcc.gnu.org>:

https://gcc.gnu.org/g:da17a9049ee0a8ca9f93edf137df92e824a7593e

commit r10-11306-gda17a9049ee0a8ca9f93edf137df92e824a7593e
Author: Jason Merrill <jason@redhat.com>
Date:   Thu Mar 23 16:50:09 2023 -0400

    c++: constexpr PMF conversion [PR105996]

    Here, we were calling build_reinterpret_cast regardless of whether there
was
    actually a cast, and that now sets REINTERPRET_CAST_P.  But that
    optimization seems dodgy anyway, as it involves NOP_EXPR from one
    RECORD_TYPE to another and we try to reserve NOP_EXPR for fundamental
types.
    And the generated code seems the same, so let's drop it.  And also strip
    location wrappers.

            PR c++/105996

    gcc/cp/ChangeLog:

            * typeck.c (build_ptrmemfunc): Drop 0-offset optimization
            and location wrappers.

    gcc/testsuite/ChangeLog:

            * g++.dg/cpp0x/constexpr-pmf3.C: New test.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug c++/105996] [10/11 Regression] reinterpret_cast in constexpr failure creating a pair with a function pointer of class parent
  2022-06-16  8:40 [Bug c++/105996] New: reinterpret_cast in constexpr failure creating a pair with a function pointer of class parent jdapena at igalia dot com
                   ` (8 preceding siblings ...)
  2023-04-21 20:28 ` [Bug c++/105996] [10/11 " cvs-commit at gcc dot gnu.org
@ 2023-04-22  0:23 ` cvs-commit at gcc dot gnu.org
  2023-07-07 10:43 ` [Bug c++/105996] [11 " rguenth at gcc dot gnu.org
  2023-11-09 19:54 ` ppalka at gcc dot gnu.org
  11 siblings, 0 replies; 13+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-04-22  0:23 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105996

--- Comment #8 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-11 branch has been updated by Jason Merrill
<jason@gcc.gnu.org>:

https://gcc.gnu.org/g:b6c8048cdd2c1e523f663f248ba39caed5af90e7

commit r11-10646-gb6c8048cdd2c1e523f663f248ba39caed5af90e7
Author: Jason Merrill <jason@redhat.com>
Date:   Thu Mar 23 16:50:09 2023 -0400

    c++: constexpr PMF conversion [PR105996]

    Here, we were calling build_reinterpret_cast regardless of whether there
was
    actually a cast, and that now sets REINTERPRET_CAST_P.  But that
    optimization seems dodgy anyway, as it involves NOP_EXPR from one
    RECORD_TYPE to another and we try to reserve NOP_EXPR for fundamental
types.
    And the generated code seems the same, so let's drop it.  And also strip
    location wrappers.

            PR c++/105996

    gcc/cp/ChangeLog:

            * typeck.c (build_ptrmemfunc): Drop 0-offset optimization
            and location wrappers.

    gcc/testsuite/ChangeLog:

            * g++.dg/cpp0x/constexpr-pmf3.C: New test.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug c++/105996] [11 Regression] reinterpret_cast in constexpr failure creating a pair with a function pointer of class parent
  2022-06-16  8:40 [Bug c++/105996] New: reinterpret_cast in constexpr failure creating a pair with a function pointer of class parent jdapena at igalia dot com
                   ` (9 preceding siblings ...)
  2023-04-22  0:23 ` cvs-commit at gcc dot gnu.org
@ 2023-07-07 10:43 ` rguenth at gcc dot gnu.org
  2023-11-09 19:54 ` ppalka at gcc dot gnu.org
  11 siblings, 0 replies; 13+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-07-07 10:43 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105996

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|10.5                        |11.5

--- Comment #9 from Richard Biener <rguenth at gcc dot gnu.org> ---
GCC 10 branch is being closed.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug c++/105996] [11 Regression] reinterpret_cast in constexpr failure creating a pair with a function pointer of class parent
  2022-06-16  8:40 [Bug c++/105996] New: reinterpret_cast in constexpr failure creating a pair with a function pointer of class parent jdapena at igalia dot com
                   ` (10 preceding siblings ...)
  2023-07-07 10:43 ` [Bug c++/105996] [11 " rguenth at gcc dot gnu.org
@ 2023-11-09 19:54 ` ppalka at gcc dot gnu.org
  11 siblings, 0 replies; 13+ messages in thread
From: ppalka at gcc dot gnu.org @ 2023-11-09 19:54 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105996

Patrick Palka <ppalka at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|https://gcc.gnu.org/bugzill |
                   |a/show_bug.cgi?id=102637    |
                 CC|                            |officesamurai at gmail dot com

--- Comment #10 from Patrick Palka <ppalka at gcc dot gnu.org> ---
*** Bug 102637 has been marked as a duplicate of this bug. ***

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2023-11-09 19:54 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-16  8:40 [Bug c++/105996] New: reinterpret_cast in constexpr failure creating a pair with a function pointer of class parent jdapena at igalia dot com
2022-06-16 11:02 ` [Bug c++/105996] [12/11/12/13 Regression] " redi at gcc dot gnu.org
2022-06-16 15:36 ` [Bug c++/105996] [10/11/12/13 " jakub at gcc dot gnu.org
2022-06-16 15:39 ` jakub at gcc dot gnu.org
2022-06-20  9:49 ` rguenth at gcc dot gnu.org
2022-06-28 10:49 ` jakub at gcc dot gnu.org
2023-03-23 20:55 ` jason at gcc dot gnu.org
2023-03-23 21:39 ` cvs-commit at gcc dot gnu.org
2023-04-18 20:46 ` [Bug c++/105996] [10/11/12 " cvs-commit at gcc dot gnu.org
2023-04-21 20:28 ` [Bug c++/105996] [10/11 " cvs-commit at gcc dot gnu.org
2023-04-22  0:23 ` cvs-commit at gcc dot gnu.org
2023-07-07 10:43 ` [Bug c++/105996] [11 " rguenth at gcc dot gnu.org
2023-11-09 19:54 ` ppalka at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).