boostorg / boostorg/utility

boost::equality_comparable2 operator== can compile into infinite loop with clang10 and -std=c++2a

Open
#65 37 comments 4 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
51
Forks
71
PR merge metrics
No merged PRs in 30d

Description

```
#include

struct my_type : boost::equality_comparable2 {
explicit my_type(double mem) : mem_{mem}{}
double mem_{0};
operator double() {
return mem_;
}
bool operator==(my_type l) {
return l.mem_ == mem_;
}
};

int main() {
my_type x{0};
return x == double{0};
}
```
https://godbolt.org/z/zy9L4C

expected: return 1

actual: infinite loop

this minimum example is based on the implementation of BOOST_STRONG_TYPEDEF in the boost serialization library. I originally opened an issue in the serialization library https://github.com/boostorg/serialization/issues/201 although it seems that the problem can be further narrowed down to `equality_comparable2`

the issue only seems to happen on clang10, clang trunk, and gcc trunk with std=c++2a or std=c++20 flag. clang10 and company produce the expected result when passed the std=c++17 flag instead of 2a. other versions (gcc9 and clang9) produce the expected result even with the std=c++2a flag. I tried with boost 1.72 and 1.73 and they both produce the same behavior. as an additional note, the optimization level does seem to affect the behavior.

let me know if any additional info is required. thank you!

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.