<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 - "Variable must be initialized by a constant expression" on std::min/max"
   href="https://bugs.llvm.org/show_bug.cgi?id=47954">47954</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>"Variable must be initialized by a constant expression" on std::min/max
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>11.0
          </td>
        </tr>

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

        <tr>
          <th>OS</th>
          <td>Windows NT
          </td>
        </tr>

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

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

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

        <tr>
          <th>Component</th>
          <td>C++17
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>dmitriy.ovdienko@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>blitzrakete@gmail.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>I cannot compile the following code:

```cpp
#include <algorithm>

static constexpr auto x = {1, 2, 3};
static constexpr auto y = std::min(x);
```

The error is:
=======================================================
bad.cpp:5:23: error: constexpr variable 'y' must be initialized by a constant
expression
static constexpr auto y = std::min(x);
                      ^   ~~~~~~~~~~~
C:\msys64\mingw64\include\c++\10.2.0\bits/predefined_ops.h:43:16: note: read of
temporary is not allowed in a constant expression outside the expression that
created the
      temporary
      { return *__it1 < *__it2; }
               ^
C:\msys64\mingw64\include\c++\10.2.0\bits/stl_algo.h:5636:6: note: in call to
'&__comp->operator()(&{1, 2, 3}[1], &{1, 2, 3}[0])'
        if (__comp(__first, __result))
            ^
C:\msys64\mingw64\include\c++\10.2.0\bits/stl_algo.h:5660:14: note: in call to
'__min_element(&{1, 2, 3}[1], &{1, 2, 3}[3], {})'
      return _GLIBCXX_STD_A::__min_element(__first, __last,
             ^
C:\msys64\mingw64\include\c++\10.2.0\x86_64-w64-mingw32\bits/c++config.h:400:25:
note: expanded from macro '_GLIBCXX_STD_A'
# define _GLIBCXX_STD_A std
                        ^
C:\msys64\mingw64\include\c++\10.2.0\bits/stl_algo.h:3469:15: note: in call to
'min_element(&{1, 2, 3}[0], &{1, 2, 3}[3])'
    { return *std::min_element(__l.begin(), __l.end()); }
              ^
bad.cpp:5:27: note: in call to 'min({&{1, 2, 3}[0], 3})'
static constexpr auto y = std::min(x);
                          ^
bad.cpp:3:27: note: temporary created here
static constexpr auto x = {1, 2, 3};

=======================================================

However following code does compile:

```cpp
#include <algorithm>
static constexpr auto y = std::min({1, 2, 3});
```

OS: Windows 10
Distribution: MSys2 (<a href="https://www.msys2.org/">https://www.msys2.org/</a>)
clang version 10.0.1 (<a href="https://github.com/Alexpux/MINGW-packages.git">https://github.com/Alexpux/MINGW-packages.git</a>
94b687508346d10cec7e8c769785f73da18b4e54)
Target: x86_64-w64-windows-gnu
Thread model: posix
InstalledDir: C:\msys64\mingw64\bin

The code above does not compile on clang 11 and trunk on <a href="https://godbolt.org/">https://godbolt.org/</a>
too.</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>