title: Fixing overloads without breaking clients
body: <p>Here is a toy example of something I am currently working on </p>
  
  <pre><code>class Foo
  {
     private:
       std::string s;
       std::vector&lt;std::string&gt; v;
     public:
  
        // Foo constructors and other big 3
  
        std::string const&amp; strmember() const;
        std::vector&lt;std::string&gt; const&amp; vecmember() const;
        std::vector&lt;std::string&gt;&amp; vecmember();
  };
  </code></pre>
  
  <p>All good up till this point. The requirement comes such that I have to add overloads and change the guts of the <code>Foo</code> as below</p>
  
  <pre><code>class Foo
  {
     private:
       std::u16string ssname;
       std::vector&lt;std::u16string&gt; vvname;
     public:
  
        // Foo constructors and other big 3
  
        std::string const&amp; strmember() const;
        std::vector&lt;std::string&gt; const&amp; vecmember() const;
        std::vector&lt;std::string&gt;&amp; vecmember();
  
        std::u16string const&amp; strmember(int) const;
        std::vector&lt;std::u16string&gt; const&amp; vecmember(int) const;
        std::vector&lt;std::u16string&gt;&amp; vecmember(int);
  };
  </code></pre>
  
  <p>I have to keep older members and add overloads for the new so that older clients wont break. Appropriate character conversions are performed so that older constructors are delegated to new one and the members supplied are changed as per the new design.</p>
  
  <p>In implement these members as below</p>
  
  <pre><code>std::string const&amp; Foo::strmember() const
  {
      const auto&amp; name = char_convert(ssname);
      return name; 
  }
  std::vector&lt;std::string&gt;&amp; Foo::vecmember()
  {
      return vecmember();
  } 
  std::vector&lt;std::string&gt;&amp; Foo::vecmember()
  {
      std::vector&lt;std::string&gt; result;
      std::transform(vvname.begin(),vvname.end(),std::back_inserter(result),[] (const std:u16string&amp; in) -&gt; std::string
                                                              {
                                                                  return char_convert(in);
                                                              });
      return result;
  }
  
  std::u16string const&amp; Foo::strmember(int) const
  {
      return ssname;
  }
  
  std::vector&lt;std::u16string&gt; const&amp; Foo::vecmember(int) const
  {
      return vvname;
  }
  
  std::vector&lt;std::u16string&gt;&amp; Foo::vecmember(int)
  {
      return vvname;
  }
  </code></pre>
  
  <p>When I tried to compile the changed code, compiler gives me following warning cum error</p>
  
  <pre><code>error: reference to local variable ‘result’ returned [-Werror=return-local-addr]
       std::vector&lt;std::string&gt; result;
                                ^~~~~~
  foo.cpp: In member function ‘const string&amp; foo::strmember() const’:
  foo.cpp: error: function returns address of local variable [-Werror=return-local-addr]
       return name;
              ^~~~
  foo.cpp: note: declared here
       const auto&amp; name = char_convert(ssname);
                                                   ^
  cc1plus: all warnings being treated as errors
  </code></pre>
  
  <p>How do I solve this problem ? I can not change the interface as it might break unittests and clients. </p>
  
  <p>How do I provide the mutator and accessor version of <code>vecmember()</code> and <code>strmember()</code> functions ?</p>