public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
* [Bug c++/102028] New: std::ostream& used as std::stringstream& @ 2021-08-23 18:20 lars.maier at tefax dot net 2021-08-23 19:48 ` [Bug c++/102028] " pinskia at gcc dot gnu.org ` (3 more replies) 0 siblings, 4 replies; 5+ messages in thread From: lars.maier at tefax dot net @ 2021-08-23 18:20 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102028 Bug ID: 102028 Summary: std::ostream& used as std::stringstream& Product: gcc Version: 11.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: lars.maier at tefax dot net Target Milestone: --- The following code compiles, although it shouldn't: ``` #include <sstream> #include <iostream> void foo(std::stringstream const&); struct A { friend auto operator<<(std::ostream& os, A const&) -> std::ostream&; }; int main() { foo(std::stringstream{} << A{}); return 0; } ``` Reason: the result of operator<< with std::stringstream and A const& is just an std::ostream& and you should not be able to call foo on such an reference. ^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/102028] std::ostream& used as std::stringstream& 2021-08-23 18:20 [Bug c++/102028] New: std::ostream& used as std::stringstream& lars.maier at tefax dot net @ 2021-08-23 19:48 ` pinskia at gcc dot gnu.org 2021-08-23 20:00 ` lars.maier at tefax dot net ` (2 subsequent siblings) 3 siblings, 0 replies; 5+ messages in thread From: pinskia at gcc dot gnu.org @ 2021-08-23 19:48 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102028 --- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> --- This is the template which gets matched: /** * @brief Generic inserter for rvalue stream * @param __os An input stream. * @param __x A reference to the object being inserted. * @return __os * * This is just a forwarding function to allow insertion to * rvalue streams since they won't bind to the inserter functions * that take an lvalue reference. */ template<typename _Ostream, typename _Tp> inline __rvalue_stream_insertion_t<_Ostream, _Tp> operator<<(_Ostream&& __os, const _Tp& __x) { __os << __x; return std::move(__os); } That is the code is same as: std::stringstream &&a = std::stringstream{}; std::ostream &b = a; b<<A{}; foo(std::move(a)); The original code is able to compile on GCC, clang (with libc++) and MSVC. ^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/102028] std::ostream& used as std::stringstream& 2021-08-23 18:20 [Bug c++/102028] New: std::ostream& used as std::stringstream& lars.maier at tefax dot net 2021-08-23 19:48 ` [Bug c++/102028] " pinskia at gcc dot gnu.org @ 2021-08-23 20:00 ` lars.maier at tefax dot net 2021-08-23 20:18 ` pinskia at gcc dot gnu.org 2021-08-24 11:02 ` redi at gcc dot gnu.org 3 siblings, 0 replies; 5+ messages in thread From: lars.maier at tefax dot net @ 2021-08-23 20:00 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102028 --- Comment #2 from Lars Maier <lars.maier at tefax dot net> --- You are right. Thank you. ^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/102028] std::ostream& used as std::stringstream& 2021-08-23 18:20 [Bug c++/102028] New: std::ostream& used as std::stringstream& lars.maier at tefax dot net 2021-08-23 19:48 ` [Bug c++/102028] " pinskia at gcc dot gnu.org 2021-08-23 20:00 ` lars.maier at tefax dot net @ 2021-08-23 20:18 ` pinskia at gcc dot gnu.org 2021-08-24 11:02 ` redi at gcc dot gnu.org 3 siblings, 0 replies; 5+ messages in thread From: pinskia at gcc dot gnu.org @ 2021-08-23 20:18 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102028 Andrew Pinski <pinskia at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |RESOLVED Resolution|--- |INVALID --- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> --- Not a bug. ^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/102028] std::ostream& used as std::stringstream& 2021-08-23 18:20 [Bug c++/102028] New: std::ostream& used as std::stringstream& lars.maier at tefax dot net ` (2 preceding siblings ...) 2021-08-23 20:18 ` pinskia at gcc dot gnu.org @ 2021-08-24 11:02 ` redi at gcc dot gnu.org 3 siblings, 0 replies; 5+ messages in thread From: redi at gcc dot gnu.org @ 2021-08-24 11:02 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102028 --- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> --- (In reply to Lars Maier from comment #0) > Reason: the result of operator<< with std::stringstream and A const& is just > an std::ostream& No it isn't, https://cplusplus.github.io/LWG/issue1203 changed that. ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2021-08-24 11:02 UTC | newest] Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2021-08-23 18:20 [Bug c++/102028] New: std::ostream& used as std::stringstream& lars.maier at tefax dot net 2021-08-23 19:48 ` [Bug c++/102028] " pinskia at gcc dot gnu.org 2021-08-23 20:00 ` lars.maier at tefax dot net 2021-08-23 20:18 ` pinskia at gcc dot gnu.org 2021-08-24 11:02 ` redi at gcc dot gnu.org
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).