[Bug libstdc++/96269] New: optional comparison with nullopt fails
sshannin at gmail dot com
gcc-bugzilla@gcc.gnu.org
Tue Jul 21 14:44:47 GMT 2020
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96269
Bug ID: 96269
Summary: optional comparison with nullopt fails
Product: gcc
Version: 10.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libstdc++
Assignee: unassigned at gcc dot gnu.org
Reporter: sshannin at gmail dot com
Target Milestone: ---
Consider the following:
seth@dev6:~/tmp$ cat opt.cpp
#include <optional>
struct X {
template <typename T>
bool operator==(const T&) {
return false;
}
};
bool foo() {
std::optional<X> x;
#ifndef FLIP
return x == std::nullopt;
#else
return std::nullopt == x;
#endif
}
With gcc 9.1.0, this compiles regardless of whether or not FLIP is defined.
With gcc 10.1.0 however, the FLIP variant does not compile.
seth@dev6:~/tmp$ /toolchain15/bin/g++ -c -o opt.o opt.cpp --std=c++20
seth@dev6:~/tmp$ /toolchain15/bin/g++ -c -o opt.o opt.cpp --std=c++20 -DFLIP
In file included from opt.cpp:1:
/toolchain15/include/c++/10.1.0/optional: In instantiation of ‘constexpr
std::__optional_relop_t<decltype ((declval<_Up>() == declval<_Tp>()))>
std::operator==(const _Up&, const std::optional<_Tp>&) [with _Tp = X; _Up =
std::nullopt_t; std::__optional_relop_t<decltype ((declval<_Up>() ==
declval<_Tp>()))> = bool; decltype ((declval<_Up>() == declval<_Tp>())) =
bool]’
...etc...
It's a tad hard for me to keep track of which overloads are supposed to
exist/how they're supposed to resolve and I think introduction of <=> was
expected to change behavior here a bit, so I'm not actually sure if this is
supposed to compile still.
seth@dev6:~/tmp$ /toolchain15/bin/g++ -v
Using built-in specs.
COLLECT_GCC=/toolchain15/bin/g++
COLLECT_LTO_WRAPPER=/toolchain15/bin/../libexec/gcc/x86_64-pc-linux-gnu/10.1.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../gcc_10_1_0/configure --prefix=/toolchain15
--enable-languages=c,c++,fortran --enable-lto --disable-plugin
--program-suffix=-10.1.0 --disable-multilib
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 10.1.0 (GCC)
More information about the Gcc-bugs
mailing list