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 31,757 of 33,346   
   =?UTF-8?B?RGFuaWVsIEtyw7xnbGVy?= to All   
   Re: Are reference types CopyAssignable   
   20 Dec 11 13:33:05   
   
   8ddacab9   
   From: daniel.kruegler@googlemail.com   
      
   Am 20.12.2011 21:06, schrieb Andrzej Krzemieński:   
   > This question seems rather simple, but I am unable to find a clear   
   > answer in the Standard. In fact, I have two similar questions.   
   > Does type int&  ('int' is just for an example - I ask about any   
   > reference) meet the requirements of CopyAssignable?   
      
   This solely depends referenced object type. You have to satisfy both   
      
   t = rv   
   t = v   
      
   to be well-formed. This can only be well-formed, if   
      
   a) T is no reference to const   
   b) T is no reference to function (you cannot assign to a function reference,   
   because that would mean that you would attempt to modify the referenced   
   function)   
   b) T is a reference to object and this object type satisfies CopyAssignable   
   requirements.   
      
   While this is a mechanic application of rules, there is a much simpler way to   
   describe the same thing: In regard to expression-based requirements, the   
   well-formedness of an assignment expression is always determined by the   
   referenced type. This becomes    
   clear, once you recognize that these requirements are determined by *values*   
   not by types [If you look at above list will see that every required property   
   is always a property of the referenced type, never a property of the reference   
   itself].   
      
   For initialization situations (like CopyConstructible) this is different,   
   because now reference initialization rules are relevant. But there do not   
   exist assignment rules for references: Any (assignment) expression involving   
   references is just an    
   expression of values of some non-reference types.   
      
   > And a similar question, if type R is a reference type, does this   
   > expression return true or false?   
   > std::is_copy_assignable::value   
   > The Standard requires that R in the above expression shall be a   
   > complete type. Is a reference a complete type?   
      
   I start with your last question: Yes, every reference type is a complete type.   
   According to 3.9 p5:   
      
   "A class that has been declared but not defined, or an array of unknown size   
   or of incomplete element type, is an incompletely-defined object type.43   
   Incompletely-defined object types and the void types are incomplete types   
   (3.9.1)."   
      
   The first question again should lead to the same results as above expression   
   analysis in the beginning. Here we nicely recognize that in regard to   
   std::is_copy_assignable any rvalue reference is automatically transformed (via   
   reference collapsing) into    
   an lvalue reference (both source and destination), so we just look at the   
   assignment from an lvalue (to const) to another lvalue. For the more general   
   std::is_assignable trait this is slightly different, because we depending on   
   the provided reference    
   type (rvalue reference or lvalue reference) we control the value category:   
   Either side can be described as an rvalue or as an lvalue.   
      
   A final comment: The current preconditions of the expression-based traits are   
   defective (The next LWG issue list will contain a corresponding new one): They   
   allow too many situations which should actually lead to an ill-formed   
   instantiation or to    
   undefined behaviour, depending on the subtlety of the concrete case. One   
   example is an assignment test of the following form:   
      
   #include    
      
   struct U;   
      
   static_assert(!std::is_copy_assignable::value, "Error"); // ??   
      
   struct U {};   
      
   static_assert(std::is_copy_assignable::value, "Error");   
      
   Now assume that the second test would happen in another translation unit: We   
   would end up in a silent ODR violation.   
      
   HTH & Greetings from Bremen,   
      
   Daniel Krügler   
      
      
      
   --   
         [ 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