https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64377 --- Comment #17 from Martin LiÅ¡ka --- Author: marxin Date: Thu Jan 15 09:53:55 2015 New Revision: 219636 URL: https://gcc.gnu.org/viewcvs?rev=219636&root=gcc&view=rev Log: Target optimization nodes: add support for arrays. PR target/64377 * optc-save-gen.awk: Add support for array types. Modified: trunk/gcc/ChangeLog trunk/gcc/optc-save-gen.awk >From gcc-bugs-return-473311-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Thu Jan 15 09:55:28 2015 Return-Path: Delivered-To: listarch-gcc-bugs@gcc.gnu.org Received: (qmail 17580 invoked by alias); 15 Jan 2015 09:55:27 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Delivered-To: mailing list gcc-bugs@gcc.gnu.org Received: (qmail 17545 invoked by uid 48); 15 Jan 2015 09:55:22 -0000 From: "jvoosten at bankai dot nl" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/64611] New: Using a << operator inside an overloaded << operator gives compile error Date: Thu, 15 Jan 2015 09:55:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 4.8.2 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: jvoosten at bankai dot nl X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter attachments.created Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2015-01/txt/msg01305.txt.bz2 Content-length: 2593 https://gcc.gnu.org/bugzilla/show_bug.cgi?idd611 Bug ID: 64611 Summary: Using a << operator inside an overloaded << operator gives compile error Product: gcc Version: 4.8.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: jvoosten at bankai dot nl Created attachment 34453 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id4453&actioníit Preprocessed file The following code gives a compile error on the indicated line: #include class SmartStream { public: template friend F &operator << (F &in, float f) { in.type ("f"); in.m_buf << f; // This causes a 'recursive' compile call return in; } protected: std::ostringstream m_buf; void type(const std::string &_type) {}; }; int main(int argc, char *argv[]) { SmartStream ss; ss << 123.456; } Compile output: $ g++ -save-temps -c rec_stream.cpp -o rec_stream.o rec_stream.cpp: In instantiation of 'F& operator<<(F&, float) [with F std::basic_ostringstream]': rec_stream.cpp:10:18: required from 'F& operator<<(F&, float) [with F SmartStream]' rec_stream.cpp:24:11: required from here rec_stream.cpp:9:9: error: 'class std::basic_ostringstream' has no member named 'type' in.type ("f"); ^ rec_stream.cpp:10:18: error: 'class std::basic_ostringstream' has no member named 'm_buf' in.m_buf << f; // This causes a 'recursive' compile call ^ Basically, it's applying the friend operator << function on the internal std::ostringstream object, while I would expect the compiler to pick 'std::ostringstream::operator <<()'. Furthermore, casting, using :: resolution operators, using the 'using' word all does not work. In fact, even the following still triggers the error: template std::string xyz(std::ostringstream &buf, G _param) { buf.str(""); buf << _param; return buf.str(); } ..and replacing the offending line with xyz(m_buf, f); Only if I move the code completely outside of SmartStream in a separate function it will compile. I also posted this on StackOverflow (http://stackoverflow.com/questions/27952591/using-a-operator-inside-an-overloaded-operator) and apparently this compiles on clang++. Perhaps there's an ambiguity towards which 'operator <<' must be applied, but then I'd expect to be able to specify which one.