Jump to page: 1 2
Thread overview
[Issue 15712] extern(C) attribute inside extern(C) unittest is incorrectly ignored
[Issue 15712] nested functions in unittests extern(C) not applied
Jan 16, 2022
Basile-z
Nov 03, 2022
RazvanN
Nov 03, 2022
John Colvin
Nov 03, 2022
RazvanN
[Issue 15712] extern(C) cancelling itself out
Nov 04, 2022
John Colvin
Nov 04, 2022
RazvanN
Nov 04, 2022
Dennis
Nov 04, 2022
RazvanN
Nov 04, 2022
Dennis
Nov 04, 2022
Dlang Bot
Nov 05, 2022
Dlang Bot
January 16, 2022
https://issues.dlang.org/show_bug.cgi?id=15712

Basile-z <b2.temp@gmx.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |b2.temp@gmx.com
           See Also|                            |https://issues.dlang.org/sh
                   |                            |ow_bug.cgi?id=6132

--
November 03, 2022
https://issues.dlang.org/show_bug.cgi?id=15712

RazvanN <razvan.nitu1305@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |razvan.nitu1305@gmail.com
         Resolution|---                         |WORKSFORME

--- Comment #1 from RazvanN <razvan.nitu1305@gmail.com> ---
If you meant that `extern(C)` is missing from the output of the pragma, then I cannot reproduce this. I get:

pure nothrow @nogc @safe extern (C) void()
extern (C) void function() pure nothrow @nogc @safe

Closing as WORKSFORME.

--
November 03, 2022
https://issues.dlang.org/show_bug.cgi?id=15712

John Colvin <john.loughran.colvin@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|WORKSFORME                  |---

--- Comment #2 from John Colvin <john.loughran.colvin@gmail.com> ---
I don't think it's fixed, see output below:

$ dmd --version
DMD64 D Compiler v2.100.2
Copyright (C) 1999-2022 by The D Language Foundation, All Rights Reserved
written by Walter Bright

$ cat test.d
unittest
{
        extern(C) static void foo(){}
        pragma(msg, typeof(foo));
        pragma(msg, typeof(&foo));
}

extern(C):

unittest
{
        static void bar(){}
        pragma(msg, typeof(bar));
        pragma(msg, typeof(&bar));
}

unittest
{
        extern(C) static void baz(){}
        pragma(msg, typeof(baz));
        pragma(msg, typeof(&baz));
}

$ dmd -unittest -o- test.d
pure nothrow @nogc @safe extern (C) void()
extern (C) void function() pure nothrow @nogc @safe
pure nothrow @nogc @safe void()
void function() pure nothrow @nogc @safe
pure nothrow @nogc @safe void()
void function() pure nothrow @nogc @safe

--
November 03, 2022
https://issues.dlang.org/show_bug.cgi?id=15712

--- Comment #3 from RazvanN <razvan.nitu1305@gmail.com> ---
Why do you expect that extern(C) should apply deeply for nested functions? As far as I know it only applies to the first level of declarations. That was the case for attributes also before nested functions got their attributes inferred.

Also, why would you want it to have extern(C) linkage? Technically it's callable from inside the unittest/function (which is actually D code, even if the function is callable from C), which means it technically cannot be called from C code (except if you escape it somehow, but I assume those cases to be rare). Either way, I think that this bug is not valid. Do you have a compelling use case for this?

--
November 04, 2022
https://issues.dlang.org/show_bug.cgi?id=15712

John Colvin <john.loughran.colvin@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|nested functions in         |extern(C) cancelling itself
                   |unittests extern(C) not     |out
                   |applied                     |

--- Comment #4 from John Colvin <john.loughran.colvin@gmail.com> ---
Why would I want an extern(C) static function as a local? One simple use-case would be to pass to a C function to use as a callback.

But that is not the point of this bug report. The point of the bug report is
that typeof(foo) is extern(C) but typeof(baz) is not.

--
November 04, 2022
https://issues.dlang.org/show_bug.cgi?id=15712

--- Comment #5 from RazvanN <razvan.nitu1305@gmail.com> ---
(In reply to John Colvin from comment #4)
> Why would I want an extern(C) static function as a local? One simple use-case would be to pass to a C function to use as a callback.
> 
> But that is not the point of this bug report. The point of the bug report is
> that typeof(foo) is extern(C) but typeof(baz) is not.

What I meant was: why would you want static/non-static nested functions to inherit the upper level linkage attribute? I would argue that in most situations nested functions are not made to be escaped (as callbacks) but if that situation arises the programmer can manually add extern(C).

--
November 04, 2022
https://issues.dlang.org/show_bug.cgi?id=15712

Dennis <dkorpel@live.nl> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dkorpel@live.nl
           Severity|enhancement                 |normal

--- Comment #6 from Dennis <dkorpel@live.nl> ---
(In reply to RazvanN from comment #5)
> but if that situation arises the programmer can manually add extern(C).

But extern(C) *is* manually added. This is the buggy part:
```
extern(C):
unittest
{
    extern(C) void baz() {}
    pragma(msg, "typeof(baz): ", typeof(baz));
}
```

`baz` is not `extern(C)` like this, but either *removing* `extern(C):` or
changing the unittest to a regular function will make `baz` `extern(C)`.

--
November 04, 2022
https://issues.dlang.org/show_bug.cgi?id=15712

--- Comment #7 from RazvanN <razvan.nitu1305@gmail.com> ---
(In reply to Dennis from comment #6)
> (In reply to RazvanN from comment #5)
> > but if that situation arises the programmer can manually add extern(C).
> 
> But extern(C) *is* manually added. This is the buggy part:
> ```
> extern(C):
> unittest
> {
>     extern(C) void baz() {}
>     pragma(msg, "typeof(baz): ", typeof(baz));
> }
> ```
> 
> `baz` is not `extern(C)` like this, but either *removing* `extern(C):` or
> changing the unittest to a regular function will make `baz` `extern(C)`.

Aaah, ok, sorry, I don't know what happened. When I tested last time it seemed the extern(C) was there in the above example and I misunderstood the bug report as being about extern(C) not propagating for nested functions. I might have miscompiled the example. Sorry for the noise. Yes, this is definitely a bug.

--
November 04, 2022
https://issues.dlang.org/show_bug.cgi?id=15712

Dennis <dkorpel@live.nl> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|extern(C) cancelling itself |extern(C) attribute inside
                   |out                         |extern(C) unittest is
                   |                            |incorrectly ignored

--- Comment #8 from Dennis <dkorpel@live.nl> ---
It turns out the parser doesn't generate an AttributeDeclaration for
extern(linkage) when it thinks it's redundant, but it's not aware that during
semantic analysis, unittests are set to extern(D).

--
November 04, 2022
https://issues.dlang.org/show_bug.cgi?id=15712

Dlang Bot <dlang-bot@dlang.rocks> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull

--- Comment #9 from Dlang Bot <dlang-bot@dlang.rocks> ---
@dkorpel created dlang/dmd pull request #14619 "Fix 15712 - extern(C) attribute
inside extern(C) unittest is incorrectly ignored" fixing this issue:

- Fix 15712 - extern(C) attribute inside extern(C) unittest is incorrectly
ignored

https://github.com/dlang/dmd/pull/14619

--
« First   ‹ Prev
1 2