invocation of next_permutation will not compile when using libc++
| Bugzilla Link | 52219 |
| Resolution | INVALID |
| Resolved on | Oct 19, 2021 09:27 |
| Version | 11.0 |
| OS | other |
| CC | @JoeLoser,@mclow |
Extended Description
The following program compiles with clang and the g++ headers, but will not compile using the libc++ headers. Visual Studio also cleanly compiles the program.
Perhaps the program is invalid, but other headers do allow it.
Here is a cut/paste from a cygwin session:
$ cat t.cpp
#include
int main(int, char *[]) { S a[10]; next_permutation(a, a + 1); }
VogelEd@XLB3502Q4E ~ $ clang++ t.cpp
VogelEd@XLB3502Q4E ~
$ clang++ -stdlib=libc++ t.cpp
In file included from t.cpp:3:
/usr/include/c++/v1/algorithm:716:71: error: invalid operands to binary
expression ('const S' and 'const S')
bool operator()(const _T1& __x, const _T1& __y) const {return __x < __y;}
~~~ ^ ~~~
/usr/include/c++/v1/algorithm:5612:13: note: in instantiation of member function
'std::__1::__less<S, S>::operator()' requested here
if (__comp(*--__i, *__ip1))
Not important, just thought I'd post it.
Thanks again for your time,
Ed Vogel
libc++ is correct I believe to fail to compile this program. The operator< needs to be marked const.
https://godbolt.org/z/cMGG4v51a is a working link showing that marking operator< as const successfully compiles the program.