c++ - Does an lvalue argument prefer an lvalue reference parameter over a universal reference? -


while playing universal references, came across instance clang , gcc disagree on overload resolution.

#include <iostream>  struct foo {};  template<typename t> void bar(t&) { std::cout << "void bar(t&)\n"; }  template<typename t> void bar(t&&) { std::cout << "void bar(t&&)\n"; }  int main() {     foo f;     bar(f);  // ambiguous on gcc, ok on clang } 

gcc reports call above ambiguous. however, clang selects t& overload , compiles successfully.

which compiler wrong, , why?

edit:
tested same code on vs2013 preview, , agrees clang; except intellisense, on gcc's side :-)

the "universal reference" deduces parameter foo&. first template deduces parameter foo&.

c++ has partial ordering rule function templates makes t& more specialized t&&. hence first template must chosen in example code.


Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

VBA function to include CDATA -