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

icc (ICC) 17.0.1 20161005 miscompiles C++11 code (related to move constructor ?)

a_d_
Beginner
500 Views

Given test.cpp

#include <string>
#include <cassert>

class CPLString : public std::string
{
public:
    CPLString( const std::string &oStr ) : std::string( oStr ) {}
};

int main()
{
    CPLString osTest("test");
    CPLString osTest2( 0 ? std::string() + osTest : osTest );
    assert( !osTest.empty() );
}

$ icc -g -Wall -Wextra -std=c++11 test.cpp -o test && ./test
test: test.cpp:14: int main(): Assertion `!osTest.empty()' failed.

Whereas without -std=c++11 it doesn't assert.

On Ubuntu 16.04 64 bit. The same compiled with gcc 5.4 or clang 3.8 in C++11 doesn't assert.

0 Kudos
2 Replies
Viet_H_Intel
Moderator
500 Views

Hi there,

I didn't see the assertion with your test case.

Thanks,

Viet

[vahoang@orcsle127 tmp]$ cat test.cpp
#include <string>
#include <cassert>
class CPLString : public std::string
{
public:
    CPLString( const std::string &oStr ) : std::string( oStr ) {}
};
int main()
{
    CPLString osTest("test");
    CPLString osTest2( 0 ? std::string() + osTest : osTest );
    assert( !osTest.empty() );
}
[vahoang@orcsle127 tmp]$  icc -g -Wall -Wextra -std=c++11 test.cpp -o test && ./test
[vahoang@orcsle127 tmp]$ icc -V
Intel(R) C Intel(R) 64 Compiler for applications running on Intel(R) 64, Version 17.0.1.132 Build 20161005

 

0 Kudos
Judith_W_Intel
Employee
500 Views

 

Viet, are you using the a 6.0 version of the GNU header files? I can reproduce it with the latest compiler if I use them.

I've reduced it to the following which outputs "FAILED" with the Intel compiler but not with GNU or clang.

extern "C" int printf(const char*,...);

struct string
{
   string() {}
   string(const string& __str) {}
   string(const char* __s) {}
   string(string&& __str) noexcept { printf("FAILED\n"); }
};


struct CPLString : public string
{
    CPLString( const string &oStr ) : string( oStr ) {}
};

int main()
{
    CPLString osTest("test");
    CPLString osTest2( 0 ? string() : osTest );
    return 0;
}

I submitted a bug report in our bugs database as DPD200416593.

Thanks for reporting it.

A workaround would be to do the following under #ifdef OK:

#ifdef OK
    CPLString osTest2( 0 ? CPLString(std::string() + osTest) : osTest );
#else
    CPLString osTest2( 0 ? std::string() + osTest : osTest );
#endif
 

Judy

 

0 Kudos
Reply