home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.c++.moderated      Moderated discussion of C++ superhackery      33,346 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 32,517 of 33,346   
   Kaba to All   
   Re: Surpising constructor call   
   13 Aug 12 12:40:37   
   
   From: kaba@nowhere.com   
      
   13.8.2012 9:22, Daniel Krügler wrote:   
   > You are providing an lvalue of type (non-const) A to an   
   > direct-initialization context. The compiler sees   
   >   
   > A::A(const A&) // Copy constructor   
   > A::A(A&&) // Move constructor   
   >   
   > and additionally would deduce   
   >   
   > A::A(A&) // No copy constructor, albeit it has the   
   > // same effective signature than A::A(A&)   
   >   
   > from the template constructor based on the non-const lvalue of A.   
   > The last one is a better match than any of the first two, so the usual   
   > function-over-template rule cannot be applied here.   
   >   
   > Note that the last signature is no copy-constructor, because   
   > copy/move-constructors won't be instantiated from templates (see 12.8   
   > p2+3).   
   >   
   > Note also that the restriction rule 12.8 p6 does not apply here,   
   > because the instantiated signature is valid.   
      
   Thanks for the informative reply. I am specifically looking at the 12.8   
   p7, which says that "A member function template is never instantiated to   
   perform the copy of a class object to an object of its   
   class type.". How is this not in effect?   
      
   For simplification, the r-value references can be left out of discussion   
   since the same thing happens with l-value references:   
      
        template    
        A(That& that)   
        {   
            std::cout << "Wait... what?" << std::endl;   
        }   
      
   The 12.8 p2 says: "A non-template constructor for class X is a copy   
   constructor if its first parameter is of type X&, const X&,   
   volatile X& or const volatile X&, and either there are no other   
   parameters or else all other parameters   
   have default arguments."   
      
   So the _non-template_ part part will say that the template constructor   
   is not a copy-constructor by definition. So is it that the 12.8 p7 is   
   not in effect because the template constructor is not a   
   copy-constructor? In this case the 12.8 p7 is a bit like saying that a   
   bicycle is never used to bake a cake, i.e. it says nothing at all.   
      
   --   
   http://kaba.hilvi.org   
      
      
         [ See http://www.gotw.ca/resources/clcm.htm for info about ]   
         [ comp.lang.c++.moderated.    First time posters: Do this! ]   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca