zhangqd / chromiumembedded

Automatically exported from code.google.com/p/chromiumembedded
0 stars 1 forks source link

CefWindowInfo's copy constructor should not be explicit. #1219

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

1. Return a CefWindowInfo object from a function whose return type is 
CefWindowInfo (note: NOT reference or pointer to). Also declaring a parameter 
of the said type by value, and calling it.

Examples:

    CefWindowInfo func() {
        CefWindowInfo windowInfo;
        return windowInfo;
    }

and 

    void func(CefWindowInfo windowInfo);

    CefWindowInfo windowInfo;
    func(windowInfo);

The above two pieces of code cause compile errors in VS2013 (I'm sure this also 
applies to older compilers).

I'm using CEF 3 Build 1650.

See also: http://stackoverflow.com/q/4153527/1619294

Original issue reported on code.google.com by MarkWynn...@gmail.com on 24 Feb 2014 at 8:03

GoogleCodeExporter commented 9 years ago
You should pass CefWindowInfo by reference instead of by value. It's a non-POD 
type and the copy action is potentially expensive (string duplication, etc).

Original comment by magreenb...@gmail.com on 12 Mar 2014 at 3:01

GoogleCodeExporter commented 9 years ago
> You should pass CefWindowInfo by reference instead of by value.

I fully understand that, though the main issue here is that I cannot *return* a 
CefWindowInfo. For the function parameter case, we already have an almost 
universal idiom to pass potentially expensive to copy parameters by const 
reference, so I think this is a no-issue. For return values, we also have 
return value optimization, though I understand that it'll only work for certain 
scenarios.

Still, the issue of not being able to return a CefWindowInfo is quite absurd, 
considering the things mentioned above and especially that there is a provided 
copy constructor.

I won't insist though, and working it around is very easy.

BTW, in C++11 this won't be an issue at all with move semantics. :-)

Original comment by MarkWynn...@gmail.com on 14 Mar 2014 at 4:23