Bug 98500 - ICE template template parameter with default parameter lambda
Summary: ICE template template parameter with default parameter lambda
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 10.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: c++-lambda, ice-on-valid-code, rejects-valid
Depends on:
Blocks: c++-ttp lambdas
  Show dependency treegraph
 
Reported: 2021-01-02 14:41 UTC by bastien penavayre
Modified: 2024-09-09 15:25 UTC (History)
6 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2024-04-15 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description bastien penavayre 2021-01-02 14:41:27 UTC
The following causes an ICE:

template<auto> struct X {};

template<template<auto=[]{}> class H = X, class = H<>>
struct A
{
};

static_assert(sizeof(A<>));


Message:
<source>:5:24: internal compiler error: in tsubst, at cp/pt.c:15258
    5 | template<template<auto=[]{}> class H = X, class = H<>>
      |                        ^~~~
Please submit a full bug report,
with preprocessed source if appropriate.
See <https://gcc.gnu.org/bugs/> for instructions.

Occurs from GCC 9.1 to trunk, tested through compiler explorer:
gcc 9.1: https://godbolt.org/z/ad7Gox
gcc trunk: https://godbolt.org/z/K367rj

Is probably related to the following tickets:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97610
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96908
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93595
Comment 1 Martin Liška 2021-01-04 12:31:09 UTC
Started to ICE with r9-6733-g03bed1538f8c71f0, it was rejected before that:

pr98500.C:3:52: error: could not convert ‘<lambda closure object><lambda()>{}’ from ‘<lambda()>’ to ‘<lambda()>’
    3 | template<template<auto=[]{}> class H = X, class = H<>>
      |                                                    ^
pr98500.C:9:24: error: template argument 2 is invalid
    9 | static_assert(sizeof(A<>));
      |                        ^
Comment 2 Andrew Pinski 2021-12-22 03:52:06 UTC
Confirmed.
Comment 3 friedkeenan 2022-02-23 08:14:30 UTC
I've triggered this without a template template parameter:

#include <type_traits>

template<auto unique = [] {}>
struct unique_empty_type { };

template<bool IsPresent, typename T>
using maybe_present = std::conditional_t<IsPresent, T, unique_empty_type<>>;

using empty = maybe_present<false, int>;

Godbolt link: https://godbolt.org/z/hf9csv8ne

Upon instantiating `empty`, an ICE is thrown. To me this seems like the same bug.
Comment 4 Andrew Pinski 2023-05-26 06:56:05 UTC
*** Bug 109978 has been marked as a duplicate of this bug. ***
Comment 5 Andrew Pinski 2024-04-15 22:21:11 UTC
(In reply to friedkeenan from comment #3)
> I've triggered this without a template template parameter:

Note the testcase in comment #0 still ICEs while the testcase in comment #3 was fixed for GCC 14 by the recent lambda template patches.
Comment 6 Marek Polacek 2024-09-09 15:25:26 UTC
Now even comment #0 compiles fine.  Fixed by bug 116567 I think.