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

            Bug ID: 106821
           Summary: Incorrect behavior when using type alias template
                    containing unevaluated lambda expression in a template
                    context
           Product: gcc
           Version: 12.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: Dylan.Ferris at amd dot com
  Target Milestone: ---

I have prepared three different examples for when this fails:

https://godbolt.org/z/G8Eq5fo5G
https://godbolt.org/z/fajvnfo91
https://godbolt.org/z/e9s9Ws5o7

In the first one, `z.obj.a()` should be valid because `obj` is simply an
instantiation of the `A` template.

In the second one, `z.a()` should be valid because `bar` is inheriting from an
instantiation of the `A` template.

In the third one, `obj.a()` should be valid because `obj` is simply an
instantiation of the `A` template.


All three of these have the following in common:

1. `alias` contains an unevaluated lambda expression, ie. `decltype([]{})`
2. The instantiation of `alias` as the inherited type uses a template parameter


So, this means that the three examples correctly compile if we apply any of the
following workarounds:

1. "inline" the alias by replacing all instances of it with `A<decltype([]{})>`
(Requiring this workaround violates [temp.alias.2])
2. Remove the unevaluated lambda expression from `alias` (such as replacing it
with `int`)
3. Remove the template parameter of `alias`
4. Instantiate `alias` with a fixed type such as `int`.


The bug persists even under a variety of transformations. Such as:

1. Removing the template on `A` and instead making an expression such as:
    template<typename T>
    using alias = std::conditional_t<true, A, decltype([]{})>;
2. Providing `bar`'s template parameter a default value of `int` and
subsequently using it


I believe this is related to PR 92707, but here the type of the unevaluated
lambda is used as a template parameter in each case, and it holds true in what
seems to be all template contexts.

Reply via email to