<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/106358>106358</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Attribute `preferred_name` doesn't work if the target specialization isn't mentioned anywhere after the declaration
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          HolyBlackCat
      </td>
    </tr>
</table>

<pre>
    Consider this code:
```cpp
#include <cstdio>

template <typename T>
void foo()
{
 puts(__PRETTY_FUNCTION__);
}

template<typename T> struct my_basic_string;
using my_string = my_basic_string<char>;
template<typename T> struct __attribute__((__preferred_name__(my_string))) my_basic_string;

// using X = my_basic_string<char>;

int main()
{
 foo<my_string>();
    // foo<my_basic_string<char>>();
}
```
This incorrectly prints `my_basic_string<char>` instead of `my_string`.

Uncommenting `using X = my_basic_string<char>;` makes it print `my_string` correctly, for some reason.
Or, uncommenting `foo<my_basic_string<char>>()` makes BOTH calls print `my_string`.

After some testing, it seems you must mention `my_basic_string<char>` (rather than `my_string`) somewhere in the source file below the attribute, for it to kick in.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyMVF9v6jYU_zTm5egiY0MgD3kotOju5XaauNL2FDnOCfFw7Mg-acU-_eQQ6C5r1UpRIPbv-Pfn2FYxmqNDLNhqy1aPMzVQ60Px3dvz1ip92imaVb4-FzvvoqkxALUmgvY1MvnA-CPjDyzjl0f3_TQipHHaDjUCkzsdqTaeyadpcnwTdr1VNALo3KNTHcLhBnrxpobGeyY2TORT4Xp7-QP9QJGJTVn-_sfT4fBXuf_5Y3f47flHWSaw3F7xj-8x3hNCpDBogu5cVioaXUYKxh1vywzRuGOavYwDk4__x-50q0JSf636jK0sFVEw1UCYVG9GO33ABkPAukz4cfzGm5yNz4dCr9nvmdjDRfWfX1R7eRtH0Cnj3g89dUPu3vTIpwl3XQQAYGK_YT_iva9969V1M10-D2m3Gad9CKjJnqEPxlEElvGPV884GBcJVQ2-maATKOPz_zr-6bTvOnQ0NjbjX04t49CpE0YwdJF0TwM3yUzsoPEBou8QAqro3aThOaS54U7Dl7O7adg-H76DVtbG97X8YvmhIZzEEEYad9Yu2YiIXYSzH6AbIsGoyLtPk2ZiExS1482g3D112q-J67XFgGAcUIsQ_RA0QmMsQoXWv46jt_NwDcwQkIeT0Scwbj6rC1nnMlczLBZrsdzIPONi1hZcLhZZ3mCum2qFWa4WdZPLtebr9UaLOpuZQnCx5BuxWXCeLcU8XyxqKSq5qmVTaanYkmOnjJ1b-9LNfTjOTIwDFgueydVmZlWFNl5vyFAk1LdqOEa25NZEim91ZMhi8XB1ktL49UynxGqP0TGxJnj14QSmGe2TCkckiD1qo6z5R43pmwk5dQNrUO58CVONjUylNWqrwlgwG4ItWqI-put5PIxHQ-1QzbXvmNgnpdPPtz74v1ETE_vRbmRiPzl-KcS_AQAA___fcu3P">