llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[Clang] Explicit conversion from a class implicitly convertible to `nullptr_t` to `bool`

Open frederick-vs-ja opened this issue 4 months ago • 5 comments

Currently, only Clang accepts the following example. Godbolt link.

struct CwNullptr {
  operator decltype(nullptr)() const { return {}; }
};
[[maybe_unused]] bool b(CwNullptr{});

I guess this example ill-formed per the question in CWG1781. However, Clang hasn't claim having implemented CWG1781 and there doesn't seem a test for this.

frederick-vs-ja avatar Jul 12 '26 07:07 frederick-vs-ja

@llvm/issue-subscribers-clang-frontend

Author: A. Jiang (frederick-vs-ja)

Currently, only Clang accepts the following example. [Godbolt link](https://godbolt.org/z/fTr49cK9x). ```C++ struct CwNullptr { operator decltype(nullptr)() const { return {}; } }; [[maybe_unused]] bool b(CwNullptr{}); ```

I guess this example ill-formed per the question in CWG1781. However, Clang hasn't claim having implemented CWG1781 and there doesn't seem a test for this.

Also CC @pinskia.

frederick-vs-ja avatar Jul 12 '26 07:07 frederick-vs-ja

@frederick-vs-ja I think you have pasted the wrong link for godbolt here

hardikxk avatar Jul 12 '26 10:07 hardikxk

@frederick-vs-ja I think you have pasted the wrong link for godbolt

Emmmm, those are test cases.

zhangweize9-cyber avatar Jul 12 '26 10:07 zhangweize9-cyber

@frederick-vs-ja I think you have pasted the wrong link for godbolt here

Thanks! Corrected now.

frederick-vs-ja avatar Jul 12 '26 12:07 frederick-vs-ja