view gcc/testsuite/gdc.test/fail_compilation/diag12829.d @ 152:2b5abeee2509

update gcc11
author anatofuz
date Mon, 25 May 2020 07:50:57 +0900
parents 1830386684a0
children
line wrap: on
line source

/*
TEST_OUTPUT:
---
fail_compilation/diag12829.d(12): Error: function diag12829.test1 is @nogc yet allocates closures with the GC
fail_compilation/diag12829.d(15):        diag12829.test1.__lambda1 closes over variable x at fail_compilation/diag12829.d(14)
fail_compilation/diag12829.d(19):        diag12829.test1.bar closes over variable x at fail_compilation/diag12829.d(14)
fail_compilation/diag12829.d(26): Error: function diag12829.test2 is @nogc yet allocates closures with the GC
fail_compilation/diag12829.d(31):        diag12829.test2.S.foo closes over variable x at fail_compilation/diag12829.d(28)
---
*/

auto test1() @nogc
{
    int x;
    void delegate() @nogc foo = () {
        int y = x;
    };

    void bar()
    {
        int y = x;
    }
    auto dg = &bar;
}

auto test2() @nogc
{
    int x;
    struct S
    {
        void foo()
        {
            int y = x;
        }
    }
    return S();
}