https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97584
Bug ID: 97584 Summary: ADL inconsistency when calling the stream operator with x << y or with operator<<(x,y) Product: gcc Version: 10.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: andrea_iob at hotmail dot com Target Milestone: --- Created attachment 49442 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=49442&action=edit Example code that shows the problem. This started as a possible bug in clang, but it seems it may be a bug in gcc instead. In the attached example I'm declaring a template stream (<<) operator, then I'm declaring a non-template operator in a different namespace. Depending on how I call the stream operator, x << y vs operator<<(x, y), I get two different behaviours: in the first case the non-template operator is called whereas in the latter the template operator is called. # g++ -o test test.cpp # ./test Using x << y syntax: > NON-TEMPLATE STREAM OPERATOR FOR CLASS data::Data Using operator<<(x, y) syntax: > TEMPLATE STREAM OPERATOR (I've tried gcc 10.2.1, gcc 7.5.0, and gcc 4.8.5.) Running the same example with clang I get a consistent behaviour: the template stream operator is selected. # clang++ -o test test.cpp # ./test Using x << y syntax: > TEMPLATE STREAM OPERATOR Using operator<<(x, y) syntax: > TEMPLATE STREAM OPERATOR This is the clang bugzilla entry: https://bugs.llvm.org/show_bug.cgi?id=47967 Let me know if further details are required. Thanks.