Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.

C++ 2016 locale imbue inlining bug

Stuart_M
Beginner
332 Views

Here is a cut down demo for a bug I found with C++ 2016. The program dies at runtime at the stream.imbue call. If the E function is not marked inline it works fine.

// Intel C++ 2016 locale imbue bug demo
// Compiled with:
// icl /Qstd=c++11 /Wall /Od imbue.cc

#include <cstddef>
#include <iomanip>
#include <iostream>
#include <sstream>
#include <string>
inline // Works without inline
std::string
E( double const t, std::size_t w )
{
   std::cout << "E.1" << std::endl; ////////////
   static auto np( new std::num_put< char > );
   static std::locale const loc( std::locale(), np );
   std::ostringstream stream;
   std::cout << "E.2" << std::endl; ////////////
   stream.imbue( loc );
   std::cout << "E.3" << std::endl; ////////////
   stream << std::showpoint << std::setw( w ) << t;
   return stream.str();
}
int
main()
{
   std::cout << E( 0.01, 24ul ) << std::endl;
}

 

0 Kudos
4 Replies
Shenghong_G_Intel
332 Views

Hi Staurt,

Thank you for reporting the issue, I can reproduce the issue with VS2012 and VS2015 both (the issue is not related to VS version).

And it works with Intel compiler 2015 but failed with 2016 only.

I'll report the issue to dev team to fix.

By the way, I see a ticket with same issue submitted by you in premier support, I'll close the issue in this forum and update you future information in premier support.

Thanks,

Shenghong

0 Kudos
Stuart_M
Beginner
332 Views

Thanks. I posted here as well for other developers' benefit and I'll update this thread with new information.

Stuart

0 Kudos
Stuart_M
Beginner
332 Views

A work-around I found is to move the function-local static variables to namespace variables.

Another work-around is to make them non-static but that has a serious performance impact so it isn't practical for my purposes.

The actual E function is a template and in that case removing the inline doesn't help.

Stuart

0 Kudos
Shenghong_G_Intel
332 Views

Hi Stuart,

Thank you for the information, I'll also pass these feedback to dev team for reference.

Shenghong

0 Kudos
Reply