<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Cannot initialize parameter of different address space if class / function is templated"
   href="https://bugs.llvm.org/show_bug.cgi?id=42390">42390</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Cannot initialize parameter of different address space if class / function is templated
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>OpenCL
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>drohr@jwdt.org
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>anastasia.stulova@arm.com, llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>This might be related to bugs 42033 or 42385.
The following code (compiled with -cl-std=c++)

template <class T>
struct x {
  x<T>& operator=(const x<T>& xx) {
    y = xx.y;
    return *this;
  }

  int y;
};

template <class T>
struct x2 {
  void foo(x<T>* xx) {
    m[0] = *xx;
  }
  x<T> m[2];
};

void bar(__global x<int>* xx, __global x2<int>* bar)
{
  bar->foo(xx);
}


fails with

test.cl:21:12: error: cannot initialize a parameter of type 'x<int> *' with an
lvalue of type '__global x<int> *'
  bar->foo(xx);
           ^~
test.cl:13:18: note: passing argument to parameter 'xx' here
  void foo(x<T>* xx) {
                 ^
test.cl:5:12: error: binding value of type '__generic x<...>' to reference to
type 'x<...>' drops <<ERROR>> qualifiers
    return *this;
           ^~~~~
test.cl:14:10: note: in instantiation of member function 'x<int>::operator='
requested here
    m[0] = *xx;
         ^
test.cl:21:8: note: in instantiation of member function 'x2<int>::foo'
requested here
  bar->foo(xx);


If I remove all the templates (which actually don't do anything), it compiles
correctly.</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>