[llvm-bugs] [Bug 47954] New: "Variable must be initialized by a constant expression" on std::min/max
via llvm-bugs
llvm-bugs at lists.llvm.org
Fri Oct 23 08:49:08 PDT 2020
https://bugs.llvm.org/show_bug.cgi?id=47954
Bug ID: 47954
Summary: "Variable must be initialized by a constant
expression" on std::min/max
Product: clang
Version: 11.0
Hardware: PC
OS: Windows NT
Status: NEW
Severity: normal
Priority: P
Component: C++17
Assignee: unassignedclangbugs at nondot.org
Reporter: dmitriy.ovdienko at gmail.com
CC: blitzrakete at gmail.com, erik.pilkington at gmail.com,
llvm-bugs at lists.llvm.org, richard-llvm at metafoo.co.uk
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 (https://www.msys2.org/)
clang version 10.0.1 (https://github.com/Alexpux/MINGW-packages.git
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 https://godbolt.org/
too.
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20201023/cbb19aa2/attachment.html>
More information about the llvm-bugs
mailing list