[Issue 19935] New: hasUDA and getUDAs ignore UDA with a custom string type

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Jun 2 15:43:15 UTC 2019


          Issue ID: 19935
           Summary: hasUDA and getUDAs ignore UDA with a custom string
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Windows
            Status: NEW
          Severity: major
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: simon.vanbernem at yahoo.de

I observe very weird behaviour, when attaching a UDA to a variable. The type of
the UDA contains a member of a custom string type, which seems to cause the
issue. Both hasUDA and getUDA don't recognize the existence of said UDA. When
using a UDA of a type that does not contain my custom string type, but just the
builtin one, hasUDA and getUDA don't have a problem (see Attribute1 and
Attribute2 structs).

When attaching the problematic UDA to a variable without initializing the
member, hasUDA and getUDA find it. Below is the repro-program and the compiler


struct My_String{
        long size;
        char* data;

My_String make_my_string(string s){
        My_String my_string;
        my_string.data = cast(char*) s.ptr;
        my_string.size = s.length;
        return my_string;

struct Attribute1{
        My_String s;

struct Attribute2{
        string s;

import std.traits;

void main(){
        @Attribute1(make_my_string("foo")) int a;

        pragma(msg, "\n", __traits(getAttributes, a));
        pragma(msg, hasUDA!(a, Attribute1));
        pragma(msg, getUDAs!(a, Attribute1), "\n");

        @Attribute2("foo") int b;

        pragma(msg, __traits(getAttributes, b));
        pragma(msg, hasUDA!(b, Attribute2));
        pragma(msg, getUDAs!(b, Attribute2), "\n");

        @Attribute1() int c;

        pragma(msg, __traits(getAttributes, c));
        pragma(msg, hasUDA!(c, Attribute1));
        pragma(msg, getUDAs!(c, Attribute1), "\n");


tuple(Attribute1(My_String(3L, &"foo"[0])))


tuple(Attribute1(My_String(0L, null)))
tuple(Attribute1(My_String(0L, null)))


More information about the Digitalmars-d-bugs mailing list