<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 - std::min and std::max cannot be used in __host__ __device__ functions under C++14"
   href="https://bugs.llvm.org/show_bug.cgi?id=37753">37753</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>std::min and std::max cannot be used in __host__ __device__ functions under C++14
          </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>release blocker
          </td>
        </tr>

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

        <tr>
          <th>Component</th>
          <td>CUDA
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>j.l.k@gmx.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>The following commit does not do the right thing because it makes it impossible
to use the std::min and std::max functions in __host__ __device__ functions
under C++14.

<a href="https://github.com/llvm-mirror/clang/commit/">https://github.com/llvm-mirror/clang/commit/</a>                                 
2528a79005f7195f1ede353e21688e5223ac2460#diff-0df73228daf7d086a1a4baf1dc1b092e

Simple repro case:

////////////////////

#include <algorithm>
#include <cstdio>

__host__ __device__
void print_min(int a, int b)
{
    printf("min(%d, %d) = %d\n", a, b, std::min(a, b));
}

int main()
{
    print_min(1, 2);
    return 0;
}

////////////////////

Compilation with nvcc from CUDA 9.2 succeeds: `nvcc -std=c++14
--expt-relaxed-constexpr std_min.cu -o std_min`

clang 7.0.0 (trunk 334304) fails: `clang++ -std=c++14 --cuda-gpu-arch=sm_61
std_min.cu -o std_min`

Actual error message:

std_min.cu:13:45: error: reference to __device__ function 'min<int>' in
__host__             __device__
      function
    printf("min(%d, %d) = %d\n", a, b, std::min(a, b));
                                            ^
/usr/lib/clang/7.0.0/include/cuda_wrappers/algorithm:94:1: note: 'min<int>'
declared here//      min(const __T &__a, const __T &__b) {
^
1 error generated when compiling for host.</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>