public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/99374] New: C++17/20 mode fails to recognise pointer-to-member functions of incomplete types in conditional expression
@ 2021-03-03 23:57 cjdb.ns at gmail dot com
  2021-03-04 10:38 ` [Bug c++/99374] " redi at gcc dot gnu.org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: cjdb.ns at gmail dot com @ 2021-03-03 23:57 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 99374
           Summary: C++17/20 mode fails to recognise pointer-to-member
                    functions of incomplete types in conditional
                    expression
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: cjdb.ns at gmail dot com
  Target Milestone: ---

Created attachment 50296
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=50296&action=edit
Failure with -std=c++17

GCC seems to be unable to handle pointer-to-member functions of incomplete
types in conditional expressions. The following works on both Clang and MSVC,
and some invocations of GCC.

```
struct S;
using F1 = int (S::*)();
using F2 = int (S::*)() noexcept;

auto v = true ? F1() : F2();
auto w = true ? F2() : F1();
```

This appears to work if `-std=c++14`, but not `-std=c++17` or `-std=c++20` for
GCC versions >= 7. GCC < 7 doesn't have a problem compiling even in C++17 mode.

# Versions

* All GCC releases from 7.1.0 through trunk.

# System type

* Ubuntu 18.04 (checked GCC 10.1)
* Ubuntu 20.04 on WSL2 (checked GCC 10.2)
* Debian (checked GCC 10.2.1)
* Compiler Explorer (checked all other reported versions).

# Options given to GCC

`g++ -save-temps fail-17.cpp -c -std=c++17`

# Diagnostic

```
fail-17.cpp:5:27: error: could not convert ‘((int (S::*)() noexcept)0)’ from
‘int (S::*)() noexcept’ to ‘int (S::*)()’
    5 | auto v = true ? F1() : F2();
      |                           ^
      |                           |
      |                           int (S::*)() noexcept
fail-17.cpp:6:27: error: could not convert ‘((int (S::*)() noexcept)0)’ from
‘int (S::*)() noexcept’ to ‘int (S::*)()’
    6 | auto w = true ? F2() : F1();
      |                           ^
      |                           |
      |                           int (S::*)() noexcept
```

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

* [Bug c++/99374] C++17/20 mode fails to recognise pointer-to-member functions of incomplete types in conditional expression
  2021-03-03 23:57 [Bug c++/99374] New: C++17/20 mode fails to recognise pointer-to-member functions of incomplete types in conditional expression cjdb.ns at gmail dot com
@ 2021-03-04 10:38 ` redi at gcc dot gnu.org
  2021-03-04 10:41 ` redi at gcc dot gnu.org
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: redi at gcc dot gnu.org @ 2021-03-04 10:38 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2021-03-04

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Bisection says this started to fail with r241958 which makes no sense.

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

* [Bug c++/99374] C++17/20 mode fails to recognise pointer-to-member functions of incomplete types in conditional expression
  2021-03-03 23:57 [Bug c++/99374] New: C++17/20 mode fails to recognise pointer-to-member functions of incomplete types in conditional expression cjdb.ns at gmail dot com
  2021-03-04 10:38 ` [Bug c++/99374] " redi at gcc dot gnu.org
@ 2021-03-04 10:41 ` redi at gcc dot gnu.org
  2021-03-04 10:44 ` redi at gcc dot gnu.org
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: redi at gcc dot gnu.org @ 2021-03-04 10:41 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
It seems more likely (i.e. very likely) to be caused by r241944 instead.

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

* [Bug c++/99374] C++17/20 mode fails to recognise pointer-to-member functions of incomplete types in conditional expression
  2021-03-03 23:57 [Bug c++/99374] New: C++17/20 mode fails to recognise pointer-to-member functions of incomplete types in conditional expression cjdb.ns at gmail dot com
  2021-03-04 10:38 ` [Bug c++/99374] " redi at gcc dot gnu.org
  2021-03-04 10:41 ` redi at gcc dot gnu.org
@ 2021-03-04 10:44 ` redi at gcc dot gnu.org
  2021-03-04 18:42 ` [Bug c++/99374] [8/9/10/11 Regression] " mpolacek at gcc dot gnu.org
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: redi at gcc dot gnu.org @ 2021-03-04 10:44 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
The change (and the reason it works pre-C++17) is noexcept being part of the
type. Apparently G++ thinks the implicit conversion from R (C::*)() noexcept to
R(C::*)() depends on C being complete.

So it has nothing to do with conditional expressions and can be reduced to:

struct S;
using F1 = int (S::*)();
using F2 = int (S::*)() noexcept;
F1 f1 = F2();

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

* [Bug c++/99374] [8/9/10/11 Regression] C++17/20 mode fails to recognise pointer-to-member functions of incomplete types in conditional expression
  2021-03-03 23:57 [Bug c++/99374] New: C++17/20 mode fails to recognise pointer-to-member functions of incomplete types in conditional expression cjdb.ns at gmail dot com
                   ` (2 preceding siblings ...)
  2021-03-04 10:44 ` redi at gcc dot gnu.org
@ 2021-03-04 18:42 ` mpolacek at gcc dot gnu.org
  2021-03-04 18:43 ` mpolacek at gcc dot gnu.org
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2021-03-04 18:42 UTC (permalink / raw)
  To: gcc-bugs

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

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
   Target Milestone|---                         |8.5
            Summary|C++17/20 mode fails to      |[8/9/10/11 Regression]
                   |recognise pointer-to-member |C++17/20 mode fails to
                   |functions of incomplete     |recognise pointer-to-member
                   |types in conditional        |functions of incomplete
                   |expression                  |types in conditional
                   |                            |expression
           Assignee|unassigned at gcc dot gnu.org      |mpolacek at gcc dot gnu.org
                 CC|                            |mpolacek at gcc dot gnu.org

--- Comment #4 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
I suspect we can treat it as a regression then; g++-6 accepted the code even
with -std=c++17.

I think I have a patch.

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

* [Bug c++/99374] [8/9/10/11 Regression] C++17/20 mode fails to recognise pointer-to-member functions of incomplete types in conditional expression
  2021-03-03 23:57 [Bug c++/99374] New: C++17/20 mode fails to recognise pointer-to-member functions of incomplete types in conditional expression cjdb.ns at gmail dot com
                   ` (3 preceding siblings ...)
  2021-03-04 18:42 ` [Bug c++/99374] [8/9/10/11 Regression] " mpolacek at gcc dot gnu.org
@ 2021-03-04 18:43 ` mpolacek at gcc dot gnu.org
  2021-03-05 23:08 ` cvs-commit at gcc dot gnu.org
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2021-03-04 18:43 UTC (permalink / raw)
  To: gcc-bugs

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

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P3                          |P2

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

* [Bug c++/99374] [8/9/10/11 Regression] C++17/20 mode fails to recognise pointer-to-member functions of incomplete types in conditional expression
  2021-03-03 23:57 [Bug c++/99374] New: C++17/20 mode fails to recognise pointer-to-member functions of incomplete types in conditional expression cjdb.ns at gmail dot com
                   ` (4 preceding siblings ...)
  2021-03-04 18:43 ` mpolacek at gcc dot gnu.org
@ 2021-03-05 23:08 ` cvs-commit at gcc dot gnu.org
  2021-03-05 23:09 ` [Bug c++/99374] [8/9/10 " mpolacek at gcc dot gnu.org
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-03-05 23:08 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Marek Polacek <mpolacek@gcc.gnu.org>:

https://gcc.gnu.org/g:02a3554879001e8f1405d17e096ed68fc3f76975

commit r11-7536-g02a3554879001e8f1405d17e096ed68fc3f76975
Author: Marek Polacek <polacek@redhat.com>
Date:   Thu Mar 4 14:25:01 2021 -0500

    c++: Pointer-to-member fn conversion with noexcept [PR99374]

    The issue in this PR is that we wrongly reject converting pointers to
    member function of incomplete types, one of which has noexcept.  Recall
    that pointers (including pointers to member functions) to non-throwing
    functions can be implicitly converted to potentially-throwing functions
    (but not vice versa).

    We reject the conversion when called from can_convert_arg_bad because
    standard_conversion can't create such a conversion.  It comes down to
    the DERIVED_FROM_P check in the TYPE_PTRMEMFUNC_P block.  It considers
    every class derived from itself, but not when the class is incomplete.
    But surely we want to reach fnptr_conv_p when tbase is fbase (one of
    them could be an alias to the other so use same_type_p instead of ==).

    Another approach would be to not perform DERIVED_FROM_P at all when
    either tbase or fbase are incomplete (so perhaps something like at the
    end of ptr_reasonably_similar).

    gcc/cp/ChangeLog:

            PR c++/99374
            * call.c (standard_conversion): When converting pointers to
            member, don't return NULL when the bases are equivalent but
            incomplete.

    gcc/testsuite/ChangeLog:

            PR c++/99374
            * g++.dg/cpp1z/noexcept-type23.C: New test.

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

* [Bug c++/99374] [8/9/10 Regression] C++17/20 mode fails to recognise pointer-to-member functions of incomplete types in conditional expression
  2021-03-03 23:57 [Bug c++/99374] New: C++17/20 mode fails to recognise pointer-to-member functions of incomplete types in conditional expression cjdb.ns at gmail dot com
                   ` (5 preceding siblings ...)
  2021-03-05 23:08 ` cvs-commit at gcc dot gnu.org
@ 2021-03-05 23:09 ` mpolacek at gcc dot gnu.org
  2021-04-09 22:36 ` cvs-commit at gcc dot gnu.org
  2021-04-09 22:37 ` mpolacek at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2021-03-05 23:09 UTC (permalink / raw)
  To: gcc-bugs

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

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|[8/9/10/11 Regression]      |[8/9/10 Regression]
                   |C++17/20 mode fails to      |C++17/20 mode fails to
                   |recognise pointer-to-member |recognise pointer-to-member
                   |functions of incomplete     |functions of incomplete
                   |types in conditional        |types in conditional
                   |expression                  |expression

--- Comment #6 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Fixed on trunk so far.

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

* [Bug c++/99374] [8/9/10 Regression] C++17/20 mode fails to recognise pointer-to-member functions of incomplete types in conditional expression
  2021-03-03 23:57 [Bug c++/99374] New: C++17/20 mode fails to recognise pointer-to-member functions of incomplete types in conditional expression cjdb.ns at gmail dot com
                   ` (6 preceding siblings ...)
  2021-03-05 23:09 ` [Bug c++/99374] [8/9/10 " mpolacek at gcc dot gnu.org
@ 2021-04-09 22:36 ` cvs-commit at gcc dot gnu.org
  2021-04-09 22:37 ` mpolacek at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-04-09 22:36 UTC (permalink / raw)
  To: gcc-bugs

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

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

https://gcc.gnu.org/g:6fcf6e5977541b2383760cb4e15ff0403055b13a

commit r10-9685-g6fcf6e5977541b2383760cb4e15ff0403055b13a
Author: Marek Polacek <polacek@redhat.com>
Date:   Thu Mar 4 14:25:01 2021 -0500

    c++: Pointer-to-member fn conversion with noexcept [PR99374]

    The issue in this PR is that we wrongly reject converting pointers to
    member function of incomplete types, one of which has noexcept.  Recall
    that pointers (including pointers to member functions) to non-throwing
    functions can be implicitly converted to potentially-throwing functions
    (but not vice versa).

    We reject the conversion when called from can_convert_arg_bad because
    standard_conversion can't create such a conversion.  It comes down to
    the DERIVED_FROM_P check in the TYPE_PTRMEMFUNC_P block.  It considers
    every class derived from itself, but not when the class is incomplete.
    But surely we want to reach fnptr_conv_p when tbase is fbase (one of
    them could be an alias to the other so use same_type_p instead of ==).

    Another approach would be to not perform DERIVED_FROM_P at all when
    either tbase or fbase are incomplete (so perhaps something like at the
    end of ptr_reasonably_similar).

    gcc/cp/ChangeLog:

            PR c++/99374
            * call.c (standard_conversion): When converting pointers to
            member, don't return NULL when the bases are equivalent but
            incomplete.

    gcc/testsuite/ChangeLog:

            PR c++/99374
            * g++.dg/cpp1z/noexcept-type23.C: New test.

    (cherry picked from commit 02a3554879001e8f1405d17e096ed68fc3f76975)

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

* [Bug c++/99374] [8/9/10 Regression] C++17/20 mode fails to recognise pointer-to-member functions of incomplete types in conditional expression
  2021-03-03 23:57 [Bug c++/99374] New: C++17/20 mode fails to recognise pointer-to-member functions of incomplete types in conditional expression cjdb.ns at gmail dot com
                   ` (7 preceding siblings ...)
  2021-04-09 22:36 ` cvs-commit at gcc dot gnu.org
@ 2021-04-09 22:37 ` mpolacek at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2021-04-09 22:37 UTC (permalink / raw)
  To: gcc-bugs

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

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

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

--- Comment #8 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Fixed in GCC 10.4 too.

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

end of thread, other threads:[~2021-04-09 22:37 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-03 23:57 [Bug c++/99374] New: C++17/20 mode fails to recognise pointer-to-member functions of incomplete types in conditional expression cjdb.ns at gmail dot com
2021-03-04 10:38 ` [Bug c++/99374] " redi at gcc dot gnu.org
2021-03-04 10:41 ` redi at gcc dot gnu.org
2021-03-04 10:44 ` redi at gcc dot gnu.org
2021-03-04 18:42 ` [Bug c++/99374] [8/9/10/11 Regression] " mpolacek at gcc dot gnu.org
2021-03-04 18:43 ` mpolacek at gcc dot gnu.org
2021-03-05 23:08 ` cvs-commit at gcc dot gnu.org
2021-03-05 23:09 ` [Bug c++/99374] [8/9/10 " mpolacek at gcc dot gnu.org
2021-04-09 22:36 ` cvs-commit at gcc dot gnu.org
2021-04-09 22:37 ` mpolacek 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).