public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/98990] New: Internal compiler error when two overloaded functions return `auto &&` and one accepts an `auto` parameter
@ 2021-02-07 22:35 david at doublewise dot net
  2021-02-07 22:37 ` [Bug c++/98990] " david at doublewise dot net
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: david at doublewise dot net @ 2021-02-07 22:35 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 98990
           Summary: Internal compiler error when two overloaded functions
                    return `auto &&` and one accepts an `auto` parameter
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: david at doublewise dot net
  Target Milestone: ---

The following valid translation unit

```
constexpr int x = 0;

constexpr auto && f() {
        return x;
}
constexpr auto && f(auto) {
        return x;
}
```

causes gcc to crash with

```
<source>:6:25: internal compiler error: same canonical type node for different
types 'auto&&' and 'auto&&'
    6 | constexpr auto && f(auto) {
      |                         ^
0x1ce6f09 internal_error(char const*, ...)
        ???:0
0x9c60ce comptypes(tree_node*, tree_node*, int)
        ???:0
0x78ef77 decls_match(tree_node*, tree_node*, bool)
        ???:0
0x7c003c cplus_decl_attributes(tree_node**, tree_node*, int)
        ???:0
0x79f277 grokdeclarator(cp_declarator const*, cp_decl_specifier_seq*,
decl_context, int, tree_node**)
        ???:0
0x7a3916 start_function(cp_decl_specifier_seq*, cp_declarator const*,
tree_node*)
        ???:0
0x8de23d c_parse_file()
        ???:0
0xa5b7c2 c_common_parse_file()
        ???:0
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.
Compiler returned: 1
```

See it live: https://godbolt.org/z/bnszYo

This code was accepted in gcc 10.2, but it is rejected by the upcoming 11.0.

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

* [Bug c++/98990] Internal compiler error when two overloaded functions return `auto &&` and one accepts an `auto` parameter
  2021-02-07 22:35 [Bug c++/98990] New: Internal compiler error when two overloaded functions return `auto &&` and one accepts an `auto` parameter david at doublewise dot net
@ 2021-02-07 22:37 ` david at doublewise dot net
  2021-02-08  9:04 ` [Bug c++/98990] [10/11 Regression] ICE when two overloaded functions return `auto &&` and one accepts an `auto` parameter since r10-6571-ga6ee556c7659877b marxin at gcc dot gnu.org
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: david at doublewise dot net @ 2021-02-07 22:37 UTC (permalink / raw)
  To: gcc-bugs

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

David Stone <david at doublewise dot net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |david at doublewise dot net

--- Comment #1 from David Stone <david at doublewise dot net> ---
To trigger this bug, the return type can be declared `auto &&`, `auto const &`,
or `auto &`. If it is `auto` or `decltype(auto)`, the bug is not triggered.
Whichever form is used, the same form must be used for both declarations.

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

* [Bug c++/98990] [10/11 Regression] ICE when two overloaded functions return `auto &&` and one accepts an `auto` parameter since r10-6571-ga6ee556c7659877b
  2021-02-07 22:35 [Bug c++/98990] New: Internal compiler error when two overloaded functions return `auto &&` and one accepts an `auto` parameter david at doublewise dot net
  2021-02-07 22:37 ` [Bug c++/98990] " david at doublewise dot net
@ 2021-02-08  9:04 ` marxin at gcc dot gnu.org
  2021-02-08  9:22 ` rguenth at gcc dot gnu.org
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: marxin at gcc dot gnu.org @ 2021-02-08  9:04 UTC (permalink / raw)
  To: gcc-bugs

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

Martin Liška <marxin at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|Internal compiler error     |[10/11 Regression] ICE when
                   |when two overloaded         |two overloaded functions
                   |functions return `auto &&`  |return `auto &&` and one
                   |and one accepts an `auto`   |accepts an `auto` parameter
                   |parameter                   |since
                   |                            |r10-6571-ga6ee556c7659877b
   Last reconfirmed|                            |2021-02-08
     Ever confirmed|0                           |1
                 CC|                            |marxin at gcc dot gnu.org,
                   |                            |ppalka at gcc dot gnu.org
             Status|UNCONFIRMED                 |NEW

--- Comment #2 from Martin Liška <marxin at gcc dot gnu.org> ---
With -fchecking, it started with a6ee556c7659877b.

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

* [Bug c++/98990] [10/11 Regression] ICE when two overloaded functions return `auto &&` and one accepts an `auto` parameter since r10-6571-ga6ee556c7659877b
  2021-02-07 22:35 [Bug c++/98990] New: Internal compiler error when two overloaded functions return `auto &&` and one accepts an `auto` parameter david at doublewise dot net
  2021-02-07 22:37 ` [Bug c++/98990] " david at doublewise dot net
  2021-02-08  9:04 ` [Bug c++/98990] [10/11 Regression] ICE when two overloaded functions return `auto &&` and one accepts an `auto` parameter since r10-6571-ga6ee556c7659877b marxin at gcc dot gnu.org
@ 2021-02-08  9:22 ` rguenth at gcc dot gnu.org
  2021-02-08 21:00 ` jason at gcc dot gnu.org
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-02-08  9:22 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |ice-checking,
                   |                            |ice-on-valid-code
           Priority|P3                          |P2
   Target Milestone|---                         |10.3

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

* [Bug c++/98990] [10/11 Regression] ICE when two overloaded functions return `auto &&` and one accepts an `auto` parameter since r10-6571-ga6ee556c7659877b
  2021-02-07 22:35 [Bug c++/98990] New: Internal compiler error when two overloaded functions return `auto &&` and one accepts an `auto` parameter david at doublewise dot net
                   ` (2 preceding siblings ...)
  2021-02-08  9:22 ` rguenth at gcc dot gnu.org
@ 2021-02-08 21:00 ` jason at gcc dot gnu.org
  2021-02-08 21:11 ` jason at gcc dot gnu.org
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: jason at gcc dot gnu.org @ 2021-02-08 21:00 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

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

* [Bug c++/98990] [10/11 Regression] ICE when two overloaded functions return `auto &&` and one accepts an `auto` parameter since r10-6571-ga6ee556c7659877b
  2021-02-07 22:35 [Bug c++/98990] New: Internal compiler error when two overloaded functions return `auto &&` and one accepts an `auto` parameter david at doublewise dot net
                   ` (3 preceding siblings ...)
  2021-02-08 21:00 ` jason at gcc dot gnu.org
@ 2021-02-08 21:11 ` jason at gcc dot gnu.org
  2021-02-08 21:22 ` ppalka at gcc dot gnu.org
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: jason at gcc dot gnu.org @ 2021-02-08 21:11 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

--- Comment #3 from Jason Merrill <jason at gcc dot gnu.org> ---
(In reply to Martin Liška from comment #2)
> With -fchecking, it started with a6ee556c7659877b.

i.e. r10-6571

The problem is that splice_late_return_type is changing the TREE_TYPE of a
REFERENCE_TYPE without also updating its TYPE_CANONICAL, which breaks; we need
to rebuild the type instead.  I expect that tsubst would do the trick, as in
do_auto_deduction.  Want to take this, Patrick?

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

* [Bug c++/98990] [10/11 Regression] ICE when two overloaded functions return `auto &&` and one accepts an `auto` parameter since r10-6571-ga6ee556c7659877b
  2021-02-07 22:35 [Bug c++/98990] New: Internal compiler error when two overloaded functions return `auto &&` and one accepts an `auto` parameter david at doublewise dot net
                   ` (4 preceding siblings ...)
  2021-02-08 21:11 ` jason at gcc dot gnu.org
@ 2021-02-08 21:22 ` ppalka at gcc dot gnu.org
  2021-02-26  0:57 ` cvs-commit at gcc dot gnu.org
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: ppalka at gcc dot gnu.org @ 2021-02-08 21:22 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

--- Comment #4 from Patrick Palka <ppalka at gcc dot gnu.org> ---
(In reply to Jason Merrill from comment #3)
> (In reply to Martin Liška from comment #2)
> > With -fchecking, it started with a6ee556c7659877b.
> 
> i.e. r10-6571
> 
> The problem is that splice_late_return_type is changing the TREE_TYPE of a
> REFERENCE_TYPE without also updating its TYPE_CANONICAL, which breaks; we
> need to rebuild the type instead.  I expect that tsubst would do the trick,
> as in do_auto_deduction.  Want to take this, Patrick?

Ah, that makes sense.  Yes, I'll take it :)

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

* [Bug c++/98990] [10/11 Regression] ICE when two overloaded functions return `auto &&` and one accepts an `auto` parameter since r10-6571-ga6ee556c7659877b
  2021-02-07 22:35 [Bug c++/98990] New: Internal compiler error when two overloaded functions return `auto &&` and one accepts an `auto` parameter david at doublewise dot net
                   ` (5 preceding siblings ...)
  2021-02-08 21:22 ` ppalka at gcc dot gnu.org
@ 2021-02-26  0:57 ` cvs-commit at gcc dot gnu.org
  2021-02-26  0:58 ` [Bug c++/98990] [10 " ppalka at gcc dot gnu.org
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-02-26  0:57 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

commit r11-7409-g6bd409cfc83683a9be5c6b3b8f9a3ec8959f9356
Author: Patrick Palka <ppalka@redhat.com>
Date:   Thu Feb 25 19:55:43 2021 -0500

    c++: abbreviated function template return type rewriting [PR98990]

    When an abbreviated function template has a complex placeholder return
    type such auto& or auto**, the level adjustment performed by
    splice_late_return_type directly replaces the 'auto' inside the original
    return type with the level-adjusted 'auto', but that breaks
    TYPE_CANONICAL caching.  Instead, we should rebuild the entire return
    type using the adjusted 'auto'.

    This patch makes this happen by tsubsting the original return type with
    an argument vector that maps the original 'auto' to the adjusted 'auto'.
    In passing, this patch also reverts the misguided changes to
    find_type_usage in r10-6571 that made find_type_usage return a tree*
    instead of a tree so as to discourage this kind of in-place type
    modification.

    It occurred to me that the constraint also needs to be rebuilt so that
    it refers to the adjusted 'auto', but this oversight doesn't seem to
    cause any issues at the moment due to how do_auto_deduction "manually"
    substitutes the 'auto' inside the constraint before performing
    satisfaction.  So this'll be fixed later as part of a rework of
    placeholder type constraint checking.

    gcc/cp/ChangeLog:

            PR c++/98990
            * pt.c (splice_late_return_type): Rebuild the entire return type
            if we have to adjust the level of an auto within.
            (type_uses_auto): Adjust call to find_type_usage.
            * type-utils.h (find_type_usage): Revert r10-6571 change that
            made this function return a pointer to the auto node.

    gcc/testsuite/ChangeLog:

            PR c++/98990
            * g++.dg/concepts/abbrev8.C: New test.

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

* [Bug c++/98990] [10 Regression] ICE when two overloaded functions return `auto &&` and one accepts an `auto` parameter since r10-6571-ga6ee556c7659877b
  2021-02-07 22:35 [Bug c++/98990] New: Internal compiler error when two overloaded functions return `auto &&` and one accepts an `auto` parameter david at doublewise dot net
                   ` (6 preceding siblings ...)
  2021-02-26  0:57 ` cvs-commit at gcc dot gnu.org
@ 2021-02-26  0:58 ` ppalka at gcc dot gnu.org
  2021-03-31 12:33 ` cvs-commit at gcc dot gnu.org
  2021-03-31 12:34 ` ppalka at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: ppalka at gcc dot gnu.org @ 2021-02-26  0:58 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|[10/11 Regression] ICE when |[10 Regression] ICE when
                   |two overloaded functions    |two overloaded functions
                   |return `auto &&` and one    |return `auto &&` and one
                   |accepts an `auto` parameter |accepts an `auto` parameter
                   |since                       |since
                   |r10-6571-ga6ee556c7659877b  |r10-6571-ga6ee556c7659877b

--- Comment #6 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Fixed for GCC 11 so far.

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

* [Bug c++/98990] [10 Regression] ICE when two overloaded functions return `auto &&` and one accepts an `auto` parameter since r10-6571-ga6ee556c7659877b
  2021-02-07 22:35 [Bug c++/98990] New: Internal compiler error when two overloaded functions return `auto &&` and one accepts an `auto` parameter david at doublewise dot net
                   ` (7 preceding siblings ...)
  2021-02-26  0:58 ` [Bug c++/98990] [10 " ppalka at gcc dot gnu.org
@ 2021-03-31 12:33 ` cvs-commit at gcc dot gnu.org
  2021-03-31 12:34 ` ppalka at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-03-31 12:33 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

commit r10-9637-gc76d503527394839f9192ee27abbc0626b4e40d8
Author: Patrick Palka <ppalka@redhat.com>
Date:   Thu Feb 25 19:55:43 2021 -0500

    c++: abbreviated function template return type rewriting [PR98990]

    When an abbreviated function template has a complex placeholder return
    type such auto& or auto**, the level adjustment performed by
    splice_late_return_type directly replaces the 'auto' inside the original
    return type with the level-adjusted 'auto', but that breaks
    TYPE_CANONICAL caching.  Instead, we should rebuild the entire return
    type using the adjusted 'auto'.

    This patch makes this happen by tsubsting the original return type with
    an argument vector that maps the original 'auto' to the adjusted 'auto'.
    In passing, this patch also reverts the misguided changes to
    find_type_usage in r10-6571 that made find_type_usage return a tree*
    instead of a tree so as to discourage this kind of in-place type
    modification.

    It occurred to me that the constraint also needs to be rebuilt so that
    it refers to the adjusted 'auto', but this oversight doesn't seem to
    cause any issues at the moment due to how do_auto_deduction "manually"
    substitutes the 'auto' inside the constraint before performing
    satisfaction.  So this'll be fixed later as part of a rework of
    placeholder type constraint checking.

    gcc/cp/ChangeLog:

            PR c++/98990
            * pt.c (splice_late_return_type): Rebuild the entire return type
            if we have to adjust the level of an auto within.
            (type_uses_auto): Adjust call to find_type_usage.
            * type-utils.h (find_type_usage): Revert r10-6571 change that
            made this function return a pointer to the auto node.

    gcc/testsuite/ChangeLog:

            PR c++/98990
            * g++.dg/concepts/abbrev8.C: New test.

    (cherry picked from commit 6bd409cfc83683a9be5c6b3b8f9a3ec8959f9356)

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

* [Bug c++/98990] [10 Regression] ICE when two overloaded functions return `auto &&` and one accepts an `auto` parameter since r10-6571-ga6ee556c7659877b
  2021-02-07 22:35 [Bug c++/98990] New: Internal compiler error when two overloaded functions return `auto &&` and one accepts an `auto` parameter david at doublewise dot net
                   ` (8 preceding siblings ...)
  2021-03-31 12:33 ` cvs-commit at gcc dot gnu.org
@ 2021-03-31 12:34 ` ppalka at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: ppalka at gcc dot gnu.org @ 2021-03-31 12:34 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

--- Comment #8 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Fixed.

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

end of thread, other threads:[~2021-03-31 12:34 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-07 22:35 [Bug c++/98990] New: Internal compiler error when two overloaded functions return `auto &&` and one accepts an `auto` parameter david at doublewise dot net
2021-02-07 22:37 ` [Bug c++/98990] " david at doublewise dot net
2021-02-08  9:04 ` [Bug c++/98990] [10/11 Regression] ICE when two overloaded functions return `auto &&` and one accepts an `auto` parameter since r10-6571-ga6ee556c7659877b marxin at gcc dot gnu.org
2021-02-08  9:22 ` rguenth at gcc dot gnu.org
2021-02-08 21:00 ` jason at gcc dot gnu.org
2021-02-08 21:11 ` jason at gcc dot gnu.org
2021-02-08 21:22 ` ppalka at gcc dot gnu.org
2021-02-26  0:57 ` cvs-commit at gcc dot gnu.org
2021-02-26  0:58 ` [Bug c++/98990] [10 " ppalka at gcc dot gnu.org
2021-03-31 12:33 ` cvs-commit at gcc dot gnu.org
2021-03-31 12:34 ` 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).