<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Invalid type cast is compiled without error in Software Archive</title>
    <link>https://community.intel.com/t5/Software-Archive/Invalid-type-cast-is-compiled-without-error/m-p/744611#M1702</link>
    <description>&lt;DIV id="tiny_quote"&gt;&lt;DIV style="margin-left: 2px; margin-right: 2px;"&gt;Quoting &lt;A jquery1327559880329="56" rel="/en-us/services/profile/quick_profile.php?is_paid=&amp;amp;user_id=353541" href="https://community.intel.com/en-us/profile/353541/" class="basic"&gt;Sergey Kostrov&lt;/A&gt;&lt;/DIV&gt;&lt;DIV style="background-color: #e5e5e5; margin-left: 2px; margin-right: 2px; border: 1px inset; padding: 5px;"&gt;&lt;I&gt;&lt;DIV id="tiny_quote"&gt;&lt;DIV style="margin-left: 2px; margin-right: 2px;"&gt;The subjectalso raises a veryold question: Could a value of some variable declared as '&lt;STRONG&gt;const&lt;/STRONG&gt;'be modified later?&lt;BR /&gt;&lt;BR /&gt;Best regards,&lt;BR /&gt;Sergey&lt;/DIV&gt;&lt;/DIV&gt;&lt;/I&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&lt;BR /&gt;The constness is supposed to be a compile-time helper against programming errors, but the programmer still has the ultimate decision about how the variable shall be used.When const_cast is used, the programmer is explicitly telling the compiler "I know what I'm doing, don't complain", so it's allowed to modify a const variable in that case.&lt;BR /&gt;&lt;BR /&gt;However the error that I reported initially is not like an explicit const cast, instead it may be hidden by template transformations that end up generating incorrect/invalid code against the programmer's will, thus the importance of detecting that situation with a compile error.&lt;/P&gt;</description>
    <pubDate>Thu, 26 Jan 2012 06:45:57 GMT</pubDate>
    <dc:creator>Ricardo_Costa</dc:creator>
    <dc:date>2012-01-26T06:45:57Z</dc:date>
    <item>
      <title>Invalid type cast is compiled without error</title>
      <link>https://community.intel.com/t5/Software-Archive/Invalid-type-cast-is-compiled-without-error/m-p/744604#M1695</link>
      <description>Hello,&lt;BR /&gt;&lt;BR /&gt;The Intel Compiler allows assigning an int* to a const int* &amp;amp;, which could cause unexpected behavior as in the following example:&lt;BR /&gt;&lt;BR /&gt;&lt;PRE&gt;[cpp]int* p;
const int* &amp;amp; r = p;    // assign to reference to a pointer to const int - this must not be allowed
const int immutable = 0;
r = &amp;amp;immutable;    // assign p to address of immutable through r
*p = 1;    // whoops, now 0 = 1![/cpp]&lt;/PRE&gt;&lt;BR /&gt;The code above compiles without errors,although the ASM generated ignores the assignment. &lt;BR /&gt;&lt;BR /&gt;This potential issue may be hidden in template code, so it would be hard to detect without a compile error.&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;Ricardo.</description>
      <pubDate>Thu, 17 Jun 2010 02:06:11 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Archive/Invalid-type-cast-is-compiled-without-error/m-p/744604#M1695</guid>
      <dc:creator>Ricardo_Costa</dc:creator>
      <dc:date>2010-06-17T02:06:11Z</dc:date>
    </item>
    <item>
      <title>Invalid type cast is compiled without error</title>
      <link>https://community.intel.com/t5/Software-Archive/Invalid-type-cast-is-compiled-without-error/m-p/744605#M1696</link>
      <description>Could someone comment on this issue? Thanks :)</description>
      <pubDate>Wed, 07 Jul 2010 00:33:48 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Archive/Invalid-type-cast-is-compiled-without-error/m-p/744605#M1696</guid>
      <dc:creator>Ricardo_Costa</dc:creator>
      <dc:date>2010-07-07T00:33:48Z</dc:date>
    </item>
    <item>
      <title>Invalid type cast is compiled without error</title>
      <link>https://community.intel.com/t5/Software-Archive/Invalid-type-cast-is-compiled-without-error/m-p/744606#M1697</link>
      <description>&lt;P&gt;Hi, &lt;BR /&gt;Thanks for reporting this issue. It should be a compiler bug. I have reported it to the compiler team for fix.&lt;BR /&gt;Thank you.&lt;BR /&gt;-Yang&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jul 2010 05:17:37 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Archive/Invalid-type-cast-is-compiled-without-error/m-p/744606#M1697</guid>
      <dc:creator>Yang_W_Intel</dc:creator>
      <dc:date>2010-07-09T05:17:37Z</dc:date>
    </item>
    <item>
      <title>Invalid type cast is compiled without error</title>
      <link>https://community.intel.com/t5/Software-Archive/Invalid-type-cast-is-compiled-without-error/m-p/744607#M1698</link>
      <description>Hello,&lt;DIV&gt;this issue is fixed. I checked with 12.1 update 8, icl emits the following error msg now:&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;tt.cpp(8): error: a reference of type "const int *&amp;amp;" (not const-qualified) cannot be initialized with a value of type "int *"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;DIV&gt;Jennifer&lt;/DIV&gt;</description>
      <pubDate>Mon, 23 Jan 2012 22:36:12 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Archive/Invalid-type-cast-is-compiled-without-error/m-p/744607#M1698</guid>
      <dc:creator>JenniferJ</dc:creator>
      <dc:date>2012-01-23T22:36:12Z</dc:date>
    </item>
    <item>
      <title>Invalid type cast is compiled without error</title>
      <link>https://community.intel.com/t5/Software-Archive/Invalid-type-cast-is-compiled-without-error/m-p/744608#M1699</link>
      <description>&lt;DIV id="tiny_quote"&gt;&lt;DIV style="margin-left: 2px; margin-right: 2px;"&gt;Quoting &lt;A jquery1327414353093="55" rel="/en-us/services/profile/quick_profile.php?is_paid=&amp;amp;user_id=420871" href="https://community.intel.com/en-us/profile/420871/" class="basic"&gt;Yang Wang (Intel)&lt;/A&gt;&lt;/DIV&gt;&lt;DIV style="background-color: #e5e5e5; margin-left: 2px; margin-right: 2px; border: 1px inset; padding: 5px;"&gt;&lt;P&gt;&lt;EM&gt;Hi, &lt;BR /&gt;Thanks for reporting this issue. It should be a compiler bug. I have reported it to the compiler team for &lt;BR /&gt;&lt;BR /&gt;&lt;/EM&gt; [&lt;STRONG&gt;SergeyK&lt;/STRONG&gt;] &lt;SPAN style="text-decoration: underline;"&gt;C++ language specificationshave tobe checked&lt;/SPAN&gt;.&lt;BR /&gt;&lt;BR /&gt;&lt;EM&gt;fix.&lt;BR /&gt;Thank you.&lt;BR /&gt;-Yang&lt;/EM&gt;&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&lt;BR /&gt;&lt;STRONG&gt;Here are some results for different C/C++ compilers:&lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;MS C/C++ with VS2005:&lt;/STRONG&gt; Error C2440: 'initializing' : cannot convert from 'int *' to 'const int *&amp;amp;'&lt;BR /&gt;&lt;STRONG&gt;MinGW C/C++ v3.4.2 :&lt;/STRONG&gt; Error: invalid initialization of reference of type 'const int*&amp;amp;' from expression of type 'int*'&lt;BR /&gt;&lt;STRONG&gt;Borland C/C++ v5.5.1 :&lt;/STRONG&gt; Successfully compiled&lt;BR /&gt;&lt;STRONG&gt;Turbo C/C++ v3.0.0  :&lt;/STRONG&gt; Successfully compiled&lt;BR /&gt;&lt;BR /&gt;It looks like specifications have changed because two legacy C/C++ compilers compiled the code.&lt;BR /&gt;&lt;BR /&gt;The subjectalso raises a veryold question: Could a value of some variable declared as '&lt;STRONG&gt;const&lt;/STRONG&gt;'be modified later?&lt;BR /&gt;&lt;BR /&gt;Best regards,&lt;BR /&gt;Sergey&lt;/P&gt;</description>
      <pubDate>Tue, 24 Jan 2012 14:21:54 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Archive/Invalid-type-cast-is-compiled-without-error/m-p/744608#M1699</guid>
      <dc:creator>SergeyKostrov</dc:creator>
      <dc:date>2012-01-24T14:21:54Z</dc:date>
    </item>
    <item>
      <title>Invalid type cast is compiled without error</title>
      <link>https://community.intel.com/t5/Software-Archive/Invalid-type-cast-is-compiled-without-error/m-p/744609#M1700</link>
      <description>&lt;DIV id="tiny_quote"&gt;&lt;DIV style="margin-left: 2px; margin-right: 2px;"&gt;Quoting &lt;A jquery1327457542421="55" rel="/en-us/services/profile/quick_profile.php?is_paid=&amp;amp;user_id=420871" href="https://community.intel.com/en-us/profile/420871/" class="basic"&gt;Yang Wang (Intel)&lt;/A&gt;&lt;/DIV&gt;&lt;DIV style="background-color: #e5e5e5; margin-left: 2px; margin-right: 2px; border: 1px inset; padding: 5px;"&gt;&lt;P&gt;&lt;EM&gt;Hi, &lt;BR /&gt;Thanks for reporting this issue. &lt;STRONG&gt;&lt;SPAN style="text-decoration: underline;"&gt;It should be a compiler bug.&lt;/SPAN&gt;&lt;/STRONG&gt; I have reported it to the compiler team&lt;BR /&gt;&lt;BR /&gt;&lt;/EM&gt; [&lt;STRONG&gt;SergeyK&lt;/STRONG&gt;]After a series of tests with different C/C++ compilersIconfirm it.&lt;BR /&gt;&lt;BR /&gt;&lt;EM&gt;for fix.&lt;BR /&gt;Thank you.&lt;BR /&gt;-Yang&lt;/EM&gt;&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&lt;/P&gt;I simply would like toinform that a &lt;STRONG&gt;3rd&lt;/STRONG&gt; legacy compiler, that is &lt;STRONG&gt;Visual C++ v6.0&lt;/STRONG&gt; ( from &lt;STRONG&gt;Visual Studio 98 &lt;/STRONG&gt;&lt;STRONG&gt;EE SP5&lt;/STRONG&gt; ) &lt;SPAN style="text-decoration: underline;"&gt;has the same problem&lt;/SPAN&gt;.&lt;BR /&gt;&lt;BR /&gt;Please take a look at a screenshot:&lt;BR /&gt;&lt;BR /&gt;&lt;span class="lia-inline-image-display-wrapper"&gt;&lt;img src="https://community.intel.com/skins/images/7B13F55A7CE623EF42E69096FA81A3A1/2021_redesign/images/image_not_found.png" /&gt;&lt;/span&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 25 Jan 2012 02:24:28 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Archive/Invalid-type-cast-is-compiled-without-error/m-p/744609#M1700</guid>
      <dc:creator>SergeyKostrov</dc:creator>
      <dc:date>2012-01-25T02:24:28Z</dc:date>
    </item>
    <item>
      <title>Invalid type cast is compiled without error</title>
      <link>https://community.intel.com/t5/Software-Archive/Invalid-type-cast-is-compiled-without-error/m-p/744610#M1701</link>
      <description>&lt;DIV id="tiny_quote"&gt;&lt;DIV style="margin-left: 2px; margin-right: 2px;"&gt;Quoting &lt;A jquery1327543772375="56" rel="/en-us/services/profile/quick_profile.php?is_paid=&amp;amp;user_id=353541" href="https://community.intel.com/en-us/profile/353541/" class="basic"&gt;Sergey Kostrov&lt;/A&gt;&lt;/DIV&gt;&lt;DIV style="background-color: #e5e5e5; margin-left: 2px; margin-right: 2px; border: 1px inset; padding: 5px;"&gt;&lt;I&gt;&lt;DIV id="tiny_quote"&gt;&lt;DIV style="margin-left: 2px; margin-right: 2px;"&gt;...&lt;BR /&gt;The subjectalso raises a veryold question: Could a value of some variable declared as '&lt;STRONG&gt;const&lt;/STRONG&gt;'be&lt;BR /&gt;modified later?&lt;BR /&gt;...&lt;/DIV&gt;&lt;/DIV&gt;&lt;/I&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;SPAN style="text-decoration: underline;"&gt;Here is a Test-Case:&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt; ...&lt;BR /&gt; const int iN = 0;&lt;BR /&gt; printf( "Initial value for Variable of type &amp;lt; const int &amp;gt; is: %ld\n", iN );&lt;BR /&gt;&lt;BR /&gt; for( int i = 0; i &amp;lt; 4; i++ )&lt;BR /&gt; {&lt;BR /&gt;  printf( "New value for Variable of type &amp;lt; const int &amp;gt; is: %ld\n",&lt;BR /&gt;  ++( const_cast&amp;lt; int &amp;amp; &amp;gt;( iN ) ) );&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt; printf( "Final value for Variable of type &amp;lt; const int &amp;gt; is: %ld\n", const_cast( int &amp;amp; )( iN ) );&lt;BR /&gt; printf( "Final value for Variable of type &amp;lt; int &amp;gt; is: %ld\n", iN );&lt;BR /&gt; ...&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;SPAN style="text-decoration: underline;"&gt;Output:&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt; Initial value for Variable of type &amp;lt; const int &amp;gt; is: 0&lt;/P&gt;&lt;P&gt; New value for Variable of type &amp;lt; const int &amp;gt;is: 1&lt;BR /&gt; New value for Variable of type &amp;lt; const int &amp;gt;is: 2&lt;BR /&gt; New value for Variable of type &amp;lt; const int &amp;gt;is: 3&lt;BR /&gt; New value for Variable of type &amp;lt; const int &amp;gt;is: 4&lt;/P&gt;&lt;P&gt; Final value for Variable of type &amp;lt; const int &amp;gt; is: 4&lt;BR /&gt; Final value for Variable of type &amp;lt; int &amp;gt;  is: 0&lt;/P&gt;</description>
      <pubDate>Thu, 26 Jan 2012 02:32:25 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Archive/Invalid-type-cast-is-compiled-without-error/m-p/744610#M1701</guid>
      <dc:creator>SergeyKostrov</dc:creator>
      <dc:date>2012-01-26T02:32:25Z</dc:date>
    </item>
    <item>
      <title>Invalid type cast is compiled without error</title>
      <link>https://community.intel.com/t5/Software-Archive/Invalid-type-cast-is-compiled-without-error/m-p/744611#M1702</link>
      <description>&lt;DIV id="tiny_quote"&gt;&lt;DIV style="margin-left: 2px; margin-right: 2px;"&gt;Quoting &lt;A jquery1327559880329="56" rel="/en-us/services/profile/quick_profile.php?is_paid=&amp;amp;user_id=353541" href="https://community.intel.com/en-us/profile/353541/" class="basic"&gt;Sergey Kostrov&lt;/A&gt;&lt;/DIV&gt;&lt;DIV style="background-color: #e5e5e5; margin-left: 2px; margin-right: 2px; border: 1px inset; padding: 5px;"&gt;&lt;I&gt;&lt;DIV id="tiny_quote"&gt;&lt;DIV style="margin-left: 2px; margin-right: 2px;"&gt;The subjectalso raises a veryold question: Could a value of some variable declared as '&lt;STRONG&gt;const&lt;/STRONG&gt;'be modified later?&lt;BR /&gt;&lt;BR /&gt;Best regards,&lt;BR /&gt;Sergey&lt;/DIV&gt;&lt;/DIV&gt;&lt;/I&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&lt;BR /&gt;The constness is supposed to be a compile-time helper against programming errors, but the programmer still has the ultimate decision about how the variable shall be used.When const_cast is used, the programmer is explicitly telling the compiler "I know what I'm doing, don't complain", so it's allowed to modify a const variable in that case.&lt;BR /&gt;&lt;BR /&gt;However the error that I reported initially is not like an explicit const cast, instead it may be hidden by template transformations that end up generating incorrect/invalid code against the programmer's will, thus the importance of detecting that situation with a compile error.&lt;/P&gt;</description>
      <pubDate>Thu, 26 Jan 2012 06:45:57 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Archive/Invalid-type-cast-is-compiled-without-error/m-p/744611#M1702</guid>
      <dc:creator>Ricardo_Costa</dc:creator>
      <dc:date>2012-01-26T06:45:57Z</dc:date>
    </item>
  </channel>
</rss>

