[Issue 22192] New: [The D Bug Tracker]

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Aug 8 13:45:48 UTC 2021


https://issues.dlang.org/show_bug.cgi?id=22192

          Issue ID: 22192
           Summary: [The D Bug Tracker]
           Product: D
           Version: D2
          Hardware: All
               URL: http://dlang.org/
                OS: All
            Status: NEW
          Severity: major
          Priority: P3
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: eyal at weka.io

This program exhibits at least 2 different issues:

struct S() {
align(1):
    bool x;
    public int* i;

    public void initialize(int* i) {
        this.i = i;
    }
}

S!() r1;

// pragma(msg, "r1.initialize:", typeof(r1.initialize));  // <-- magical line

pragma(msg, "S!().initialize:", typeof(S!().initialize));


Now this program compiles and the pragma msg emits:
"S!().initialize:void(int* i)"

Issue A) this is wrong, because inside a template, it should infer the method
to be pure nothrow @nogc, but it doesn't.

Issue B) if you uncomment the magical line, the pragma msgs now emit:
"r1.initialize:pure nothrow @nogc @safe void(int* i)
S!().initialize:pure nothrow @nogc @safe void(int* i)"

so the first pragma(msg) changes the inferred type of initialize to correctly
include "pure nothrow @nogc" but *incorrectly* include "@safe" (it isn't @safe
because it assigns a misaligned pointer!)

-----------------

A) So a typeof() computation on a type has side-effects.
B) The attribute inference is too narrow without it
C) The attribute inference is too wide with it

-----------------

I've minimized to this example when debugging linker errors - where different
compilation contexts inferred "@safe pure" differently on an expression.

--


More information about the Digitalmars-d-bugs mailing list