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

possibly non standard behavour

sumitv
Beginner
349 Views

The following code does not compile with icl(Intel C++ compiler), however the same compiles and runs as expected with following compilers

1> cl.exe( MSVC compiler, VS 2008)

Microsoft 32-bit C/C++ Optimizing Compiler Version 15.00.30729.01 for 80x86

Copyright (C) Microsoft Corporation. All rights reserved.

2> g++ ( GCC 4.5)

Target: mingw32

Configured with: ../gcc-4.5.2/configure --enable-languages=c,c++,ada,fortran,objc,obj-c++ --disable-sjlj-exceptions --with-dwarf2 --enable-shared --enable-libgomp --disable-win32-registry --enable-libstdcxx-debug --enable-version-specific-runtime-libs --disable-werror --build=mingw32 --prefix=/mingw

Thread model: win32

gcc version 4.5.2 (GCC)

I suspect some non-standard behavior from icl, I may be wrong, please correct me. If this is correct then please let me know what is missing.

Sample output is shwon below :

D:\\Dev> typeConv.exe
In operator Array
In operator T&()

[cpp] 
#include

template
class Array  {
public:
	Array() {}
};

class Parameter
{
	char* ptr;

public:
	Parameter() : ptr(0) { ptr = new char[sizeof(int)]; }

	template 
	operator T&()
	{
		std::cout << "In operator T&()" << std::endl;
		return *reinterpret_cast( ptr);
	}
	
	operator Array() 
	{ 
		std::cout << "In operator Array" << std::endl;
		return Array(); 
	}
	operator Array() 
	{ 
		std::cout << "In operator Array" << std::endl;
		return Array(); 
	}
};


int main()
{
	Parameter p;
	Array arr = p;	
	int a = p;
}
 
[/cpp]

0 Kudos
5 Replies
Alexander_W_Intel
349 Views
Hi,
thanks a lot for bringing this up with a nice test case. I can confirm the issue for Windows. On Linux your code works fine.
I will send this to engineering.
Thanks,
Alex
0 Kudos
Judith_W_Intel
Employee
349 Views

A possible workaround is to turn off our emulation of Microsoft bugs by using the /Qms0 switch.
0 Kudos
sumitv
Beginner
349 Views
@Alexander: Thanks a lot for confirming the issue.
Is there a way for me to follow the proceeds of the request that you have raised with the your engineering team.
@Judith: Thanks for the /Qms0 suggestion. It worked( compiled), but the output was not as expected.

I modified the 'main' method slightly to confirm the behaviour,but the output was not as expected.
I added these lines in the main
Array arr2;
arr2 = static_cast< Array >( p);

I was expecting this static_cast call to resolve to operator Array().
However it was resolved to operator T&().

Below is the output from MSVC generated executable
In operator Array
In operator Array
In operator T&()


and the output from Intel compiler generated executable
In operator Array
In operator T&()
In operator T&()

As per my understanding output from msvc looks correct.
Is there an explanation for Intel compiler's behaviour, which I am unable to think or can it be an issue with Intel compiler?
As per C++ standard which of the above two behaviours are correct? For this case even gcc behaves similar to Intel compiler.

[cpp]#include

template
class Array  {
public:
	Array() {}
	Array(const Array& arr){}
};

class Parameter
{
	char* ptr;

public:
	Parameter() : ptr(0) { ptr = new char[sizeof(int)]; }

	template 
	operator T&()
	{
		std::cout << "In operator T&()" << std::endl;
		return *reinterpret_cast( ptr);
	}
	
	operator Array() 
	{ 
		std::cout << "In operator Array" << std::endl;
		return Array(); 
	}
	
	operator Array() 
	{ 
		std::cout << "In operator Array" << std::endl;
		return Array(); 
	}
};


int main()
{
	Parameter p;
	Array arr = p;
	
	Array arr2;
	arr2 = static_cast< Array >( p);
	
	int a = p;
}

[/cpp]

0 Kudos
SergeyKostrov
Valued Contributor II
349 Views

>>...I suspect some non-standard behavior from icl...

It looks like Yes.

>>Sample output is shwon below :
>>
>>D:\Dev> typeConv.exe
>>In operator Array
>>In operator T&()

I've just completed a cross-compiler verifications with a modified code in the 'main' function ( I kept your logic in all the restparts of the Test-Case):

...
int main()
{
Parameter p;

Array< int > arrI = p;
int aI = p;

Array< float > arrF = p;
float aF = p;
}
...

Results of compilation:

- MS C/C++ compiler ( VS 2005 \ VS 2008 \ VS 2010 ) - Pass
- MinGW v3.4.2 compiler - Pass
- Borland C/C++ v5.1 compiler - Pass
- Turbo C/C++ v3.1 compiler - Failed ( doesn't support 'template < typename T >' declaration)

Result of execution:

In operator Array< int >
In operator T &()
In operator Array< float >
In operator T &()

0 Kudos
Alexander_W_Intel
349 Views
Hi Sumitv,
the issue is fixed in theIntel C++ Composer XE for Windows* Update 9. You can download it from the Registration center.
Thanks for raising this issue!
Alex
0 Kudos
Reply