Thread overview
[Issue 22737] Segmentation fault in CppMangleVisitor.getTiNamespace
[Issue 22737] Segnementation fault in CppMangleVisitor.getTiNamespace
Feb 04, 2022
Tim
Feb 04, 2022
Tim
Feb 10, 2022
Mathias LANG
Feb 10, 2022
Tim
Feb 10, 2022
Tim
Dec 27, 2022
Iain Buclaw
Dec 27, 2022
Tim
February 04, 2022
https://issues.dlang.org/show_bug.cgi?id=22737

Tim <tim.dlang@t-online.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |C++, rejects-valid

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

Tim <tim.dlang@t-online.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|Segnementation fault in     |Segmentation fault in
                   |CppMangleVisitor.getTiNames |CppMangleVisitor.getTiNames
                   |pace                        |pace

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

moonlightsentinel@disroot.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |moonlightsentinel@disroot.o
                   |                            |rg
           Severity|normal                      |regression

--- Comment #1 from moonlightsentinel@disroot.org ---
Slightly reduced / modified:

==================================================
template Identity(T)
{
        alias T Identity;
}

extern(C++) Identity!T identity(T)()
{
    return Identity!T.init;
}
void main()
{
    identity!int();
}
==================================================

Up to      2.063  : Success and no output
2.064   to 2.066.0: Segfault and no output
2.067.1 to 2.083.1: Success and no output
Since      2.084.1: Segfault and no output

--
February 10, 2022
https://issues.dlang.org/show_bug.cgi?id=22737

Mathias LANG <pro.mathias.lang@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |pro.mathias.lang@gmail.com

--- Comment #2 from Mathias LANG <pro.mathias.lang@gmail.com> ---
I see where the issue is. I'm wondering whether this should be rejected by the frontend or not. Essentially we just "see through" the `Identity` template. However, I don't think that's possible in C++. There might also be some other expectations (what if `Identity` has an `extern(C++)` and namespace declaration?).

Note:
We hit `headOfType`:
https://github.com/dlang/dmd/blob/cefa9ff9d0d68ca21049ffc2d6f08dd1d8c7843c/src/dmd/cppmangle.d#L1376-L1395
with our `res` as `int`, and a few places don't account for types not having
Dsymbol.

--
February 10, 2022
https://issues.dlang.org/show_bug.cgi?id=22737

Tim <tim.dlang@t-online.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://issues.dlang.org/sh
                   |                            |ow_bug.cgi?id=22760

--
February 10, 2022
https://issues.dlang.org/show_bug.cgi?id=22737

Tim <tim.dlang@t-online.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://issues.dlang.org/sh
                   |                            |ow_bug.cgi?id=22739

--
December 27, 2022
https://issues.dlang.org/show_bug.cgi?id=22737

--- Comment #3 from Iain Buclaw <ibuclaw@gdcproject.org> ---
This issue has the tag "rejects-valid" - but where's the valid C++ code?

If this template has no C++ equivalent, then it should be accepts-invalid, and we issue an error at semantic-time as Matthias has already mentioned.

--
December 27, 2022
https://issues.dlang.org/show_bug.cgi?id=22737

--- Comment #4 from Tim <tim.dlang@t-online.de> ---
In my original code this happened for a utility function, which did not come from C++. I used extern(C++): for the whole file, so the utility function also got it, but I have solve it by making this function extern(D).

The following code should be equivalent C++:

==================================================
template <class T>
using Identity = T;

template <class T>
Identity<T> identity(T val)
{
    return Identity<T>(val);
}

int main()
{
    int x = identity(5);
    return 0;
}
==================================================

Making this issue accepts-invalid would also work for me, because templates with alias can probably just be marked as extern(D).

--