[Issue 24344] New: The getUDAs and stringof generate different result with different compiler

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Jan 18 02:26:55 UTC 2024


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

          Issue ID: 24344
           Summary: The getUDAs and stringof generate different result
                    with different compiler
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: critical
          Priority: P1
         Component: phobos
          Assignee: nobody at puremagic.com
          Reporter: bitworld at qq.com

Here is the test code

```d
import std.stdio;
import std.traits;

void main() {
        const s1 = getUDAs!(__traits(getMember, User, "age"), Max)[0].stringof;
        const s2 = (getUDAs!(__traits(getMember, User, "age"),
Max)[0]).stringof;

        writefln("s1=%s", s1);
        writefln("s2=%s", s2);
}

class User {
        @Max()
         // @Max
        int age;
}

struct Max {
        long value;
        string message = "must be less than or equal to {{value}}";
}

```


The output from DMD 2.106.1 is 

```txt
s1=Max(0L, "must be less than or equal to {{value}}")
s2=arg
```

The output from DMD 2.095.1 is 
```txt
s1=Max(0L, "must be less than or equal to {{value}}")
s2=Max(0L, "must be less than or equal to {{value}}")
```

The problem is that the s2 for DMD 2.106.1 got a wrong result.

--


More information about the Digitalmars-d-bugs mailing list