- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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] #includetemplate 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]
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
A possible workaround is to turn off our emulation of Microsoft bugs by using the /Qms0 switch.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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 = static_cast< Array
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]#includetemplate 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]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
>>...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 &()
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page