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

    <tr>
        <th>Summary</th>
        <td>
            [HLSL] No matching constructor for struct initialization from a constant buffer struct
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            bug,
            HLSL
      </td>
    </tr>

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

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

<pre>
    There is no matching constructor when initializing a local variable struct with a struct read from a constant buffer.

https://godbolt.org/z/e1n1xnj6r

```hlsl
// compile args: -T cs_6_7 -E CSMain -enable-16bit-types
RWStructuredBuffer<uint> output : register(u0);
struct MyStruct {
    int i;
};
cbuffer MyBuffer : register(b0) {
  MyStruct myS;
};
[numthreads(1, 1, 1)]
void CSMain() {
 MyStruct s = myS;
  output[0] = s.i;
}
```

```
<source>:10:12: error: no matching constructor for initialization of 'MyStruct'
   10 |   MyStruct s = myS;
      |            ^   ~~~
<source>:2:8: note: candidate constructor (the implicit copy constructor) not viable: cannot bind reference in address space 'hlsl_constant' to object in generic address space in 1st argument
    2 | struct MyStruct {
      |        ^~~~~~~~
<source>:2:8: note: candidate constructor (the implicit move constructor) not viable: cannot bind reference in address space 'hlsl_constant' to object in generic address space in 1st argument
    2 | struct MyStruct {
      | ^~~~~~~~
<source>:2:8: note: candidate constructor (the implicit default constructor) not viable: requires 0 arguments, but 1 was provided
1 error generated.
Compiler returned: 1
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzUVU9v47YT_TSjy8AGRUWWfdDB8R_8fsCmh2aBHgOKHFlcSKTLP069h3z2gpLjeN1uTu2hhCGR0vD5vaeZofBeHwxRDeUjlNtMxNBZV_9f2o6UsyZrrDrXXztyhNqjsTiIIDttDiit8cFFGazD144MaqODFr3-nt4K7K0UPZ6E06LpCadYfNWhQ_G-ciQUts4OKCY8YQI2sW3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