public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/102786] New: PMF constant evaluation bug
@ 2021-10-15 18:05 jakub at gcc dot gnu.org
  2021-10-15 19:22 ` [Bug c++/102786] " pinskia at gcc dot gnu.org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: jakub at gcc dot gnu.org @ 2021-10-15 18:05 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 102786
           Summary: PMF constant evaluation bug
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jakub at gcc dot gnu.org
  Target Milestone: ---

In the following testcase:

// { dg-do compile { target c++20 } }

struct S {
  virtual constexpr int foo () const { return 42; }
};

constexpr S s;
constexpr auto a = &S::foo;
constexpr auto b = (s.*a) ();
constexpr auto c = (s.*&S::foo) ();

we correctly accept b's initializer, but reject c's initializer with:
error: value ‘1’ of type ‘int (S::*)() const’ is not a constant expression

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

* [Bug c++/102786] PMF constant evaluation bug
  2021-10-15 18:05 [Bug c++/102786] New: PMF constant evaluation bug jakub at gcc dot gnu.org
@ 2021-10-15 19:22 ` pinskia at gcc dot gnu.org
  2021-10-15 20:32 ` pinskia at gcc dot gnu.org
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-10-15 19:22 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
This might be a dup.

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

* [Bug c++/102786] PMF constant evaluation bug
  2021-10-15 18:05 [Bug c++/102786] New: PMF constant evaluation bug jakub at gcc dot gnu.org
  2021-10-15 19:22 ` [Bug c++/102786] " pinskia at gcc dot gnu.org
@ 2021-10-15 20:32 ` pinskia at gcc dot gnu.org
  2021-10-19  7:25 ` [Bug c++/102786] [c++20] virtual pmf sometimes rejected as not a constant cvs-commit at gcc dot gnu.org
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-10-15 20:32 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2021-10-15

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed.

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

* [Bug c++/102786] [c++20] virtual pmf sometimes rejected as not a constant
  2021-10-15 18:05 [Bug c++/102786] New: PMF constant evaluation bug jakub at gcc dot gnu.org
  2021-10-15 19:22 ` [Bug c++/102786] " pinskia at gcc dot gnu.org
  2021-10-15 20:32 ` pinskia at gcc dot gnu.org
@ 2021-10-19  7:25 ` cvs-commit at gcc dot gnu.org
  2021-11-29  8:49 ` cvs-commit at gcc dot gnu.org
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-10-19  7:25 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jakub Jelinek <jakub@gcc.gnu.org>:

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

commit r12-4491-gf45610a45236e97616726ca042898d6ac46a082e
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Tue Oct 19 09:24:57 2021 +0200

    c++: Don't reject calls through PMF during constant evaluation [PR102786]

    The following testcase incorrectly rejects the c initializer,
    while in the s.*a case cxx_eval_* sees .__pfn reads etc.,
    in the s.*&S::foo case get_member_function_from_ptrfunc creates
    expressions which use INTEGER_CSTs with type of pointer to METHOD_TYPE.
    And cxx_eval_constant_expression rejects any INTEGER_CSTs with pointer
    type if they aren't 0.
    Either we'd need to make sure we defer such folding till cp_fold but the
    function and pfn_from_ptrmemfunc is used from lots of places, or
    the following patch just tries to reject only non-zero INTEGER_CSTs
    with pointer types if they don't point to METHOD_TYPE in the hope that
    all such INTEGER_CSTs with POINTER_TYPE to METHOD_TYPE are result of
    folding valid pointer-to-member function expressions.
    I don't immediately see how one could create such INTEGER_CSTs otherwise,
    cast of integers to PMF is rejected and would have the PMF RECORD_TYPE
    anyway, etc.

    2021-10-19  Jakub Jelinek  <jakub@redhat.com>

            PR c++/102786
            * constexpr.c (cxx_eval_constant_expression): Don't reject
            INTEGER_CSTs with type POINTER_TYPE to METHOD_TYPE.

            * g++.dg/cpp2a/constexpr-virtual19.C: New test.

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

* [Bug c++/102786] [c++20] virtual pmf sometimes rejected as not a constant
  2021-10-15 18:05 [Bug c++/102786] New: PMF constant evaluation bug jakub at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2021-10-19  7:25 ` [Bug c++/102786] [c++20] virtual pmf sometimes rejected as not a constant cvs-commit at gcc dot gnu.org
@ 2021-11-29  8:49 ` cvs-commit at gcc dot gnu.org
  2021-11-29  9:08 ` jakub at gcc dot gnu.org
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-11-29  8:49 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-11 branch has been updated by Jakub Jelinek
<jakub@gcc.gnu.org>:

https://gcc.gnu.org/g:62e4f0e8977497e01d2c262a3bd459ab26a5aaca

commit r11-9326-g62e4f0e8977497e01d2c262a3bd459ab26a5aaca
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Tue Oct 19 09:24:57 2021 +0200

    c++: Don't reject calls through PMF during constant evaluation [PR102786]

    The following testcase incorrectly rejects the c initializer,
    while in the s.*a case cxx_eval_* sees .__pfn reads etc.,
    in the s.*&S::foo case get_member_function_from_ptrfunc creates
    expressions which use INTEGER_CSTs with type of pointer to METHOD_TYPE.
    And cxx_eval_constant_expression rejects any INTEGER_CSTs with pointer
    type if they aren't 0.
    Either we'd need to make sure we defer such folding till cp_fold but the
    function and pfn_from_ptrmemfunc is used from lots of places, or
    the following patch just tries to reject only non-zero INTEGER_CSTs
    with pointer types if they don't point to METHOD_TYPE in the hope that
    all such INTEGER_CSTs with POINTER_TYPE to METHOD_TYPE are result of
    folding valid pointer-to-member function expressions.
    I don't immediately see how one could create such INTEGER_CSTs otherwise,
    cast of integers to PMF is rejected and would have the PMF RECORD_TYPE
    anyway, etc.

    2021-10-19  Jakub Jelinek  <jakub@redhat.com>

            PR c++/102786
            * constexpr.c (cxx_eval_constant_expression): Don't reject
            INTEGER_CSTs with type POINTER_TYPE to METHOD_TYPE.

            * g++.dg/cpp2a/constexpr-virtual19.C: New test.

    (cherry picked from commit f45610a45236e97616726ca042898d6ac46a082e)

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

* [Bug c++/102786] [c++20] virtual pmf sometimes rejected as not a constant
  2021-10-15 18:05 [Bug c++/102786] New: PMF constant evaluation bug jakub at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2021-11-29  8:49 ` cvs-commit at gcc dot gnu.org
@ 2021-11-29  9:08 ` jakub at gcc dot gnu.org
  2022-05-10  8:21 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: jakub at gcc dot gnu.org @ 2021-11-29  9:08 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

--- Comment #5 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Fixed.

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

* [Bug c++/102786] [c++20] virtual pmf sometimes rejected as not a constant
  2021-10-15 18:05 [Bug c++/102786] New: PMF constant evaluation bug jakub at gcc dot gnu.org
                   ` (4 preceding siblings ...)
  2021-11-29  9:08 ` jakub at gcc dot gnu.org
@ 2022-05-10  8:21 ` cvs-commit at gcc dot gnu.org
  2022-05-11  6:22 ` cvs-commit at gcc dot gnu.org
  2022-10-28 23:28 ` pinskia at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-05-10  8:21 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-10 branch has been updated by Jakub Jelinek
<jakub@gcc.gnu.org>:

https://gcc.gnu.org/g:536b03642ad1a32100f71d414e6bd6dc54fc208a

commit r10-10650-g536b03642ad1a32100f71d414e6bd6dc54fc208a
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Tue Oct 19 09:24:57 2021 +0200

    c++: Don't reject calls through PMF during constant evaluation [PR102786]

    The following testcase incorrectly rejects the c initializer,
    while in the s.*a case cxx_eval_* sees .__pfn reads etc.,
    in the s.*&S::foo case get_member_function_from_ptrfunc creates
    expressions which use INTEGER_CSTs with type of pointer to METHOD_TYPE.
    And cxx_eval_constant_expression rejects any INTEGER_CSTs with pointer
    type if they aren't 0.
    Either we'd need to make sure we defer such folding till cp_fold but the
    function and pfn_from_ptrmemfunc is used from lots of places, or
    the following patch just tries to reject only non-zero INTEGER_CSTs
    with pointer types if they don't point to METHOD_TYPE in the hope that
    all such INTEGER_CSTs with POINTER_TYPE to METHOD_TYPE are result of
    folding valid pointer-to-member function expressions.
    I don't immediately see how one could create such INTEGER_CSTs otherwise,
    cast of integers to PMF is rejected and would have the PMF RECORD_TYPE
    anyway, etc.

    2021-10-19  Jakub Jelinek  <jakub@redhat.com>

            PR c++/102786
            * constexpr.c (cxx_eval_constant_expression): Don't reject
            INTEGER_CSTs with type POINTER_TYPE to METHOD_TYPE.

            * g++.dg/cpp2a/constexpr-virtual19.C: New test.

    (cherry picked from commit f45610a45236e97616726ca042898d6ac46a082e)

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

* [Bug c++/102786] [c++20] virtual pmf sometimes rejected as not a constant
  2021-10-15 18:05 [Bug c++/102786] New: PMF constant evaluation bug jakub at gcc dot gnu.org
                   ` (5 preceding siblings ...)
  2022-05-10  8:21 ` cvs-commit at gcc dot gnu.org
@ 2022-05-11  6:22 ` cvs-commit at gcc dot gnu.org
  2022-10-28 23:28 ` pinskia at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-05-11  6:22 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-9 branch has been updated by Jakub Jelinek
<jakub@gcc.gnu.org>:

https://gcc.gnu.org/g:662de049d63759b731bed62f9df60edb47120658

commit r9-10106-g662de049d63759b731bed62f9df60edb47120658
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Tue Oct 19 09:24:57 2021 +0200

    c++: Don't reject calls through PMF during constant evaluation [PR102786]

    The following testcase incorrectly rejects the c initializer,
    while in the s.*a case cxx_eval_* sees .__pfn reads etc.,
    in the s.*&S::foo case get_member_function_from_ptrfunc creates
    expressions which use INTEGER_CSTs with type of pointer to METHOD_TYPE.
    And cxx_eval_constant_expression rejects any INTEGER_CSTs with pointer
    type if they aren't 0.
    Either we'd need to make sure we defer such folding till cp_fold but the
    function and pfn_from_ptrmemfunc is used from lots of places, or
    the following patch just tries to reject only non-zero INTEGER_CSTs
    with pointer types if they don't point to METHOD_TYPE in the hope that
    all such INTEGER_CSTs with POINTER_TYPE to METHOD_TYPE are result of
    folding valid pointer-to-member function expressions.
    I don't immediately see how one could create such INTEGER_CSTs otherwise,
    cast of integers to PMF is rejected and would have the PMF RECORD_TYPE
    anyway, etc.

    2021-10-19  Jakub Jelinek  <jakub@redhat.com>

            PR c++/102786
            * constexpr.c (cxx_eval_constant_expression): Don't reject
            INTEGER_CSTs with type POINTER_TYPE to METHOD_TYPE.

            * g++.dg/cpp2a/constexpr-virtual19.C: New test.

    (cherry picked from commit f45610a45236e97616726ca042898d6ac46a082e)

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

* [Bug c++/102786] [c++20] virtual pmf sometimes rejected as not a constant
  2021-10-15 18:05 [Bug c++/102786] New: PMF constant evaluation bug jakub at gcc dot gnu.org
                   ` (6 preceding siblings ...)
  2022-05-11  6:22 ` cvs-commit at gcc dot gnu.org
@ 2022-10-28 23:28 ` pinskia at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-10-28 23:28 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to work|                            |10.4.0, 12.1.0, 9.5.0
   Target Milestone|---                         |9.5

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

end of thread, other threads:[~2022-10-28 23:28 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-15 18:05 [Bug c++/102786] New: PMF constant evaluation bug jakub at gcc dot gnu.org
2021-10-15 19:22 ` [Bug c++/102786] " pinskia at gcc dot gnu.org
2021-10-15 20:32 ` pinskia at gcc dot gnu.org
2021-10-19  7:25 ` [Bug c++/102786] [c++20] virtual pmf sometimes rejected as not a constant cvs-commit at gcc dot gnu.org
2021-11-29  8:49 ` cvs-commit at gcc dot gnu.org
2021-11-29  9:08 ` jakub at gcc dot gnu.org
2022-05-10  8:21 ` cvs-commit at gcc dot gnu.org
2022-05-11  6:22 ` cvs-commit at gcc dot gnu.org
2022-10-28 23:28 ` pinskia 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).