last day (15 days later) » 

21:03
3
A: clang/g++ difference with friend function

seheThe iffy thing is to declare an static (friend) operator in another class (that is unrelated). You could just create it in the surrounding scope, there's no difference semantically no reason to have it a friend (as Printer is not used any way) you can still make it a friend if you needed to...

Alternatively, associate the Print class namespace with your Object type so ADL still works: Live On Coliru
How does the #2 hack work?
@0x499602D2 ADL looks up unqualified free functions in all namespaces associated with the argument types. "Associated namespaces" includes those declaring the template argument types.
So the compiler looks at the associated namespaces of the template arguments? Woah, just learned something new!
@0x499602D2 To be fair, I learned this when troubleshooting this: Getting the address of template class object leads to full instatiation of template parameters (It includes the relevant standards quotes). I was pretty wowed back then.
21:03
In your answer to that question you reference a clause on ADL which says that "the sets of namespaces and classes is determined entirely by the types of the function arguments". Where exactly are function arguments being used in the OP's initial example. Are you referring to the implicit this parameter?
@0x499602D2 The second parameter to operator<< is Object. If Object associates the namespace of Print for function lookup, then operator<< will be happily found in that namespace. Note that overload resolution starts out with the concrete argument types at the call site. If you "reason it backwards" this may seem confounding (there's no way you can "get" to Object just from reading that operator<< overload).
Sorry, I was referring to this question you answered. Maybe I should've commented on your answer there. lol
@0x499602D2 Please do move the comments (I will too). The reasoning doesn't change, though
Anyways, we can also remove the irrelevant comments and just keep the discussion here :)
You want to delete the comments from that thread?
Ok done.
Just the ones you think don't pertain to the question there. (I think that might be most because you seem to be just querying about the exact jurisdiction of ADL in general?)
@0x499602D2 matched
21:06
In your answer here you said that ADL was the culprit, how so?
ADL has to do with function arguments, right? But where are function arguments being used in the OP's initial example?
21:30
Nevermind, I understand what's going on now!
@0x499602D2 Because invoking operator& on a UDT requires the compiler to scan all associated namespaces. This leads to shallow instantiations of classes that are in the list of associated namespaces
In this case the shallow instantiation of the template argument class lead to an instantiation failure.
The instantiation failure prevented his other code from compiling (effectively breaking SFINAE elsewhere in his code, because of the unanticipated ripple effect doing operator&.)
The solution was to use std::addressof<> so the compiler didn't go and search for any custom overloaded operator& with ADL
@0x499602D2 Ah. I deal with chat messages strictly chronologically (ironically I do this when I don't have much time o.O)

last day (15 days later) »