Thread overview
[Issue 22192] [The D Bug Tracker]
Aug 08, 2021
Mike Parker
[Issue 22192] Inconsistent attribute inference for template member function
Aug 08, 2021
Paul Backus
Aug 08, 2021
Eyal
Aug 08, 2021
Ketmar Dark
Dec 17, 2022
Iain Buclaw
August 08, 2021
https://issues.dlang.org/show_bug.cgi?id=22192

Mike Parker <aldacron@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |industry
                 CC|                            |aldacron@gmail.com

--
August 08, 2021
https://issues.dlang.org/show_bug.cgi?id=22192

Paul Backus <snarwin+bugzilla@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |snarwin+bugzilla@gmail.com
            Summary|[The D Bug Tracker]         |Inconsistent attribute
                   |                            |inference for template
                   |                            |member function

--- Comment #1 from Paul Backus <snarwin+bugzilla@gmail.com> ---
More reduced version of the inconsistent attribute inference issue:

---
struct S() {
    public void initialize() {}
}

version(NotInferred)
    // void()
    pragma(msg, typeof(S!().initialize));
else
    // pure nothrow @nogc @safe void()
    pragma(msg, typeof(S!()().initialize));
---

More reduced version of the alignment issue:

---
struct S {
    align(1) int* p;
}

auto fun(int* p) {
    S s;
    s.p = p;
    return s;
}

// pure nothrow @nogc @safe S(int* p)
pragma(msg, typeof(fun));
---

I am not sure the second one is actually a bug. The language spec section on pointers [1] does not say anything about misaligned pointer variables potentially causing undefined behavior, and I have not been able to come up with an example that uses such a variable to cause undefined behavior in @safe code.

For now, I've edited the name of this bugzilla issue to refer to the attribute-inference issue in the first example, since that one's definitely a bug.

[1] https://dlang.org/spec/arrays.html#pointers

--
August 08, 2021
https://issues.dlang.org/show_bug.cgi?id=22192

--- Comment #2 from Eyal <eyal@weka.io> ---
If you change your second to:

struct S {
    ubyte x;
    align(1) int* p;
}

// @safe <-- will fail to build with this attribute, but it will infer as
@safe!
auto fun(int* p) {
    S s;
    s.p = p;
    return s;
}

// pure nothrow @nogc @safe S(int* p)
pragma(msg, typeof(fun));


i.e: make the ptr be at offset 1, misaligned - it will infer as @safe, but refuse to type-check with @safe

--
August 08, 2021
https://issues.dlang.org/show_bug.cgi?id=22192

Ketmar Dark <ketmar@ketmar.no-ip.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ketmar@ketmar.no-ip.org

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

Iain Buclaw <ibuclaw@gdcproject.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P3                          |P2

--