public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/99902] New: Deduced return type of lambda in default template argument takes return type from variable template
@ 2021-04-04  2:15 jason.e.cobb at gmail dot com
  2022-01-29 10:39 ` [Bug c++/99902] " pinskia at gcc dot gnu.org
  2024-04-15 22:30 ` ppalka at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: jason.e.cobb at gmail dot com @ 2021-04-04  2:15 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 99902
           Summary: Deduced return type of lambda in default template
                    argument takes return type from variable template
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jason.e.cobb at gmail dot com
  Target Milestone: ---

In the following code:

[BEGIN EXAMPLE]

template<void(*)() = []{ return; }>
struct foo {};

template<typename T>
inline constexpr auto foo_v = foo<>{};

auto x = foo_v<long>;

[END EXAMPLE]

On Compiler Explorer: https://godbolt.org/z/nor57d4Ke

GCC believes the return type of the lambda to be long, even though the return
type should be deduced as void. This is apparent from the error message that
GCC rejects with:

[BEGIN ERROR]

<source>: In instantiation of 'constexpr const auto foo_v<long int>':
<source>:7:10:   required from here
<source>:1:26: error: return-statement with no value, in function returning
'long int' [-fpermissive]
    1 | template<void(*)() = []{ return; }>
      |                          ^~~~~~
<source>:5:23: error: conversion from 'long int (*)()' to 'void (*)()' in a
converted constant expression
    5 | inline constexpr auto foo_v = foo<>{};
      |                       ^~~~~
<source>:5:23: error: could not convert '<lambda closure object><lambda()>{}'
from '<lambda()>' to 'void (*)()'
Compiler returned: 1

[END ERROR]

GCC rejects with a similar error message in the following case with an alias
template instead of a variable template:

[BEGIN EXAMPLE]

template<void(*)() = []{ return; }>
struct foo {};

template<typename T>
using foo_t = foo<>;

using some_foo = foo_t<long>;

[END EXAMPLE]

In the case where foo_t or foo_v has multiple template arguments, the first is
taken to be the return type.

In the case where the first template parameter foo_t or foo_v is a non-type
template parameter, GCC ICEs:

[BEGIN EXAMPLE]

template<void(*)() = []{ return; }>
struct foo {};

template<int>
using foo_t = foo<>;

using some_foo = foo_t<12>;

[END EXAMPLE]

On Compiler Explorer: https://godbolt.org/z/MoPEGzYP7

This results in the following error:

[BEGIN ERROR]

<source>: In substitution of 'template<int <anonymous> > using foo_t = foo<>
[with int <anonymous> = 12]':
<source>:7:26:   required from here
<source>:1:22: internal compiler error: in tsubst, at cp/pt.c:15578
    1 | template<void(*)() = []{ return; }>
      |                      ^~~~~~~~~~~~~
0x1cfd119 internal_error(char const*, ...)
        ???:0
0x6baa1b fancy_abort(char const*, int, char const*)
        ???:0
0x9182c1 tsubst(tree_node*, tree_node*, int, tree_node*)
        ???:0
0x916211 tsubst(tree_node*, tree_node*, int, tree_node*)
        ???:0
0x949897 tsubst_lambda_expr(tree_node*, tree_node*, int, tree_node*)
        ???:0
0x941fc6 tsubst_template_args(tree_node*, tree_node*, int, tree_node*)
        ???:0
0x91658d tsubst(tree_node*, tree_node*, int, tree_node*)
        ???:0
0x916637 tsubst(tree_node*, tree_node*, int, tree_node*)
        ???:0
0x94ce32 instantiate_template(tree_node*, tree_node*, int)
        ???:0
0x916b31 tsubst(tree_node*, tree_node*, int, tree_node*)
        ???:0
0x92a38e lookup_template_class(tree_node*, tree_node*, tree_node*, tree_node*,
int, int)
        ???:0
0x97ff1d finish_template_type(tree_node*, tree_node*, int)
        ???:0
0x8e140d c_parse_file()
        ???:0
0xa606f2 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.

[END ERROR]

On Compiler Explorer: https://godbolt.org/z/713js5aq7

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

* [Bug c++/99902] Deduced return type of lambda in default template argument takes return type from variable template
  2021-04-04  2:15 [Bug c++/99902] New: Deduced return type of lambda in default template argument takes return type from variable template jason.e.cobb at gmail dot com
@ 2022-01-29 10:39 ` pinskia at gcc dot gnu.org
  2024-04-15 22:30 ` ppalka at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-01-29 10:39 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |fchelnokov at gmail dot com

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
*** Bug 103929 has been marked as a duplicate of this bug. ***

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

* [Bug c++/99902] Deduced return type of lambda in default template argument takes return type from variable template
  2021-04-04  2:15 [Bug c++/99902] New: Deduced return type of lambda in default template argument takes return type from variable template jason.e.cobb at gmail dot com
  2022-01-29 10:39 ` [Bug c++/99902] " pinskia at gcc dot gnu.org
@ 2024-04-15 22:30 ` ppalka at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: ppalka at gcc dot gnu.org @ 2024-04-15 22:30 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
                 CC|                            |ppalka at gcc dot gnu.org
   Target Milestone|---                         |14.0
             Status|UNCONFIRMED                 |RESOLVED

--- Comment #2 from Patrick Palka <ppalka at gcc dot gnu.org> ---
This seems fixed for GCC 14 after r14-9943-gd74fe10b13336b.

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

end of thread, other threads:[~2024-04-15 22:30 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-04  2:15 [Bug c++/99902] New: Deduced return type of lambda in default template argument takes return type from variable template jason.e.cobb at gmail dot com
2022-01-29 10:39 ` [Bug c++/99902] " pinskia at gcc dot gnu.org
2024-04-15 22:30 ` 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).