[Interest] MSVC 2013 Bug?
Thiago Macieira
thiago.macieira at intel.com
Thu Nov 12 21:38:06 CET 2015
On Thursday 12 November 2015 23:05:37 Igor Mironchik wrote:
> Hi folks,
>
> Is it a bug or feature?
First of all, allocating memory when throwing exceptions is bad practice.
Avoid it by redesigning your code.
> TextFileViewException::TextFileViewException( const QString & what )
> : std::runtime_error( what.toLocal8Bit() )
> , m_what( what )
> {
> }
> Look at this line:
>
> std::runtime_error( what.toLocal8Bit() )
>
> std::runtime_error() constructs from QByteArray... How it is possible?
Because toLocal8Bit() returns a QByteArray and QByteArray has an operator
const char*(). Why would it not be possible?
Do note that it compiles, but it's probably incorrect because
std::runtime_error will probably be carrying a dangling pointer.
Like I said, you should redesign so you don't allocate memory when throwing
exceptions.
--
Thiago Macieira - thiago.macieira (AT) intel.com
Software Architect - Intel Open Source Technology Center
More information about the Interest
mailing list