public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
* [Bug c++/113219] New: Overloaded ref-qualified conversion operator triggers bogus -Wconversion @ 2024-01-03 16:38 m.cencora at gmail dot com 2024-01-03 21:58 ` [Bug c++/113219] " pinskia at gcc dot gnu.org 2024-01-04 8:17 ` m.cencora at gmail dot com 0 siblings, 2 replies; 3+ messages in thread From: m.cencora at gmail dot com @ 2024-01-03 16:38 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113219 Bug ID: 113219 Summary: Overloaded ref-qualified conversion operator triggers bogus -Wconversion Product: gcc Version: 13.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: m.cencora at gmail dot com Target Milestone: --- Following code when compiled on any gcc version (checked all available on godbolt since gcc-7) triggers conversion warnings. I consider it bogus because it tells user that it has chosen a better overload (which is good thing, right?). Clang doesn't print any related warning even with -Weverything g++ -std=c++17 -Wconversion template <typename T> struct wrapper { operator T() const&; operator T&&() &&; }; wrapper<int> createInt(); int test() { return createInt(); } Output is: <source>:13:21: warning: choosing 'wrapper<T>::operator T&&() && [with T = int]' over 'wrapper<T>::operator T() const & [with T = int]' [-Wconversion] 13 | return createInt(); | ~~~~~~~~~^~ <source>:13:21: warning: for conversion from 'wrapper<int>' to 'int' [-Wconversion] <source>:13:21: note: because conversion sequence for the argument is better ^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c++/113219] Overloaded ref-qualified conversion operator triggers bogus -Wconversion 2024-01-03 16:38 [Bug c++/113219] New: Overloaded ref-qualified conversion operator triggers bogus -Wconversion m.cencora at gmail dot com @ 2024-01-03 21:58 ` pinskia at gcc dot gnu.org 2024-01-04 8:17 ` m.cencora at gmail dot com 1 sibling, 0 replies; 3+ messages in thread From: pinskia at gcc dot gnu.org @ 2024-01-03 21:58 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113219 Andrew Pinski <pinskia at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |RESOLVED Resolution|--- |INVALID --- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> --- This is documented this way too: https://gcc.gnu.org/onlinedocs/gcc-13.2.0/gcc/Warning-Options.html#index-Wconversion ``` For C++, also warn for confusing overload resolution for user-defined conversions; and conversions that never use a type conversion operator: conversions to void, the same type, a base class or a reference to them. Warnings about conversions between signed and unsigned integers are disabled by default in C++ unless -Wsign-conversion is explicitly enabled. ``` Don't use -Wconversion if you don't wan this warning ... Note this warning was originally not part of -Wconversion but always on (in GCC 2.95.3) and then in GCC 3.4.0 was moved to part of -Wconversion; this was PR 10784 was about even. ^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c++/113219] Overloaded ref-qualified conversion operator triggers bogus -Wconversion 2024-01-03 16:38 [Bug c++/113219] New: Overloaded ref-qualified conversion operator triggers bogus -Wconversion m.cencora at gmail dot com 2024-01-03 21:58 ` [Bug c++/113219] " pinskia at gcc dot gnu.org @ 2024-01-04 8:17 ` m.cencora at gmail dot com 1 sibling, 0 replies; 3+ messages in thread From: m.cencora at gmail dot com @ 2024-01-04 8:17 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113219 --- Comment #2 from m.cencora at gmail dot com --- So I guess this falls into the "confusing overload resolution for user-defined conversion" but I fail to see what can be confusing here. createInt() returns prvalue, so later it binds to xvalue for the purpose of implicit conversion operator invocation. That means that r-value qualified conversion operator is chosen. If your advice is to avoid using "-Wconversion" that it is rather unfortunate because user looses good warnings (e.g. about conversions that may alter the value). Also there is no way to silence the warning for such a code, since gcc warns on each call-site, not on definition-site of the overloads. So it either unfeasible or even impossible if the definitions are in library code, but warnings are enabled in user code. Please consider removing the warning generation in such scenarios. ^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-01-04 8:17 UTC | newest] Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2024-01-03 16:38 [Bug c++/113219] New: Overloaded ref-qualified conversion operator triggers bogus -Wconversion m.cencora at gmail dot com 2024-01-03 21:58 ` [Bug c++/113219] " pinskia at gcc dot gnu.org 2024-01-04 8:17 ` m.cencora at gmail dot com
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).