From: ThosRTanner on 21 May 2010 07:06 for instance class Except { public: template <class T> Except &operator<<(T const &); }; throw Except() << "went bang"; In our version of lint, this gets an error about initialising a non- const reference with a non-lvalue. Is this a valid error? Isn't the temporary object that gets created immediately copied by the throw, or does it indeed go out of scope before the throw is executed. -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
From: McNepp on 25 May 2010 01:36 I think the effect you're seeing has nothing to do with code being a "throw"-expression. You construct a temporary object and then invoke a non-const member function on the temporary. There is nothing wrong with this in current C++. My guess is that Lint is probably trained on looking for applications of the left-shift operator and assumes that the operator function is always declared as a free function, taking a non-const reference as its first argument, such as: template<typename T> Except& operator <<(Except&, const T&); In that case, Lint would be correct with its analysis. On 21 Mai, 23:06, ThosRTanner <ttann...(a)bloomberg.net> wrote: > for instance > > class Except { public: template <class T> Except &operator<<(T const > &); }; > > throw Except() << "went bang"; > > In our version of lint, this gets an error about initialising a non- > const reference with a non-lvalue. > > Is this a valid error? Isn't the temporary object that gets created > immediately copied by the throw, or does it indeed go out of scope > before the throw is executed. -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
|
Pages: 1 Prev: C++ STL vectors - pointer to Vectors: do we need them? Next: has_interface trait |