Bug 92633 - [concepts] constrained lambda with placehoder syntax getting wrong substitution
Summary: [concepts] constrained lambda with placehoder syntax getting wrong substitution
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 10.0
: P3 normal
Target Milestone: 10.2
Assignee: Patrick Palka
URL:
Keywords: c++-lambda, rejects-valid
: 93152 93154 (view as bug list)
Depends on:
Blocks: concepts lambdas
  Show dependency treegraph
 
Reported: 2019-11-22 21:44 UTC by Eric Niebler
Modified: 2022-03-11 00:32 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2020-06-01 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Eric Niebler 2019-11-22 21:44:56 UTC
The following code fails to compile with trunk with -std=c++2a

template<class A, class B>
concept different_than = !__is_same_as(A, B);

template<class B>
auto diff(B) {
    return [](different_than<B> auto a) {};
}

int main() {
    diff(42)("");
}


By the time the compiler evaluates the constraint, it seems to have forgotten the context in which the constraint lives; that is, it no longer seems to know what type B is.

I think the code should compile, and it does with clang-concepts: https://godbolt.org/z/3QzhxS
Comment 1 Patrick Palka 2020-06-01 15:40:55 UTC
Reconfirmed with GCC master, looking into it.
Comment 2 GCC Commits 2020-06-02 01:38:27 UTC
The master branch has been updated by Patrick Palka <ppalka@gcc.gnu.org>:

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

commit r11-779-gc2449995ca36ea955e3c6d4ee7f0d401b512c897
Author: Patrick Palka <ppalka@redhat.com>
Date:   Mon Jun 1 21:37:04 2020 -0400

    c++: constrained lambda inside template [PR92633]
    
    When regenerating a constrained lambda during instantiation of an
    enclosing template, we are forgetting to substitute into the lambda's
    constraints.  Fix this by substituting through the constraints during
    tsubst_lambda_expr.
    
    gcc/cp/ChangeLog:
    
            PR c++/92633
            PR c++/92838
            * pt.c (tsubst_function_decl): Don't do set_constraints when
            regenerating a lambda.
            (tsubst_lambda_expr): Substitute into the lambda's constraints
            and do set_constraints here.
    
    gcc/testsuite/ChangeLog:
    
            PR c++/92633
            PR c++/92838
            * g++.dg/cpp2a/concepts-lambda11.C: New test.
            * g++.dg/cpp2a/concepts-lambda12.C: New test.
Comment 3 GCC Commits 2020-06-02 12:52:50 UTC
The releases/gcc-10 branch has been updated by Patrick Palka <ppalka@gcc.gnu.org>:

https://gcc.gnu.org/g:40912c25b57b4e21aae20a4896624387aa13f7ed

commit r10-8223-g40912c25b57b4e21aae20a4896624387aa13f7ed
Author: Patrick Palka <ppalka@redhat.com>
Date:   Mon Jun 1 21:37:04 2020 -0400

    c++: constrained lambda inside template [PR92633]
    
    When regenerating a constrained lambda during instantiation of an
    enclosing template, we are forgetting to substitute into the lambda's
    constraints.  Fix this by substituting through the constraints during
    tsubst_lambda_expr.
    
    gcc/cp/ChangeLog:
    
            PR c++/92633
            PR c++/92838
            * pt.c (tsubst_function_decl): Don't do set_constraints when
            regenerating a lambda.
            (tsubst_lambda_expr): Substitute into the lambda's constraints
            and do set_constraints here.
    
    gcc/testsuite/ChangeLog:
    
            PR c++/92633
            PR c++/92838
            * g++.dg/cpp2a/concepts-lambda11.C: New test.
            * g++.dg/cpp2a/concepts-lambda12.C: New test.
    
    (cherry picked from commit c2449995ca36ea955e3c6d4ee7f0d401b512c897)
Comment 4 Patrick Palka 2020-06-02 12:56:39 UTC
Fixed for GCC 10.2+.
Comment 5 Patrick Palka 2020-06-02 13:10:59 UTC
*** Bug 93152 has been marked as a duplicate of this bug. ***
Comment 6 Patrick Palka 2020-06-02 13:12:21 UTC
*** Bug 93154 has been marked as a duplicate of this bug. ***