Bug 89580 - template conversion operator not considered for operator == of pointers
Summary: template conversion operator not considered for operator == of pointers
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 9.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2019-03-04 15:20 UTC by Eric Fiselier
Modified: 2023-12-17 18:52 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2021-08-27 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Eric Fiselier 2019-03-04 15:20:28 UTC
I believe the following code is valid and should be accepted.

// g++ -std=c++11
struct Foo {
  template <class T> operator T() const;
};
// error: no match for 'operator==' (operand types are 'Foo' and 'void*')
bool R = (Foo{} == static_cast<void*>(nullptr));


Note that when Foo's conversion operator is declared as `operator T*()`, the code is accepted.

See https://godbolt.org/z/nc43wx
Comment 1 Andrew Pinski 2021-08-27 22:12:03 UTC
Confirmed here is a C++98 version which shows this has always been an issue:
struct Foo {
  template <class T> operator T() const;
};
Foo *a;
Foo t;
bool R = (t == a);