<?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 Re: HP C++ bug? in Operating System - OpenVMS</title>
    <link>https://community.hpe.com/t5/operating-system-openvms/hp-c-bug/m-p/4168786#M43541</link>
    <description>A reply . . .&lt;BR /&gt;&lt;BR /&gt;The default is /standard=relaxed, which enables an&lt;BR /&gt;anachronism that our previous versions of the compiler&lt;BR /&gt;supported, and we chose not to break existing customer&lt;BR /&gt;code compiled with default options when newer versions&lt;BR /&gt;implemented the standard behavior.&lt;BR /&gt;&lt;BR /&gt;The choices are to compile with /standard=strict, or&lt;BR /&gt;add the undocumented option /switch=no_nonconst_ref_anachronism</description>
    <pubDate>Thu, 27 Mar 2008 17:17:51 GMT</pubDate>
    <dc:creator>Robert Brooks_1</dc:creator>
    <dc:date>2008-03-27T17:17:51Z</dc:date>
    <item>
      <title>HP C++ bug?</title>
      <link>https://community.hpe.com/t5/operating-system-openvms/hp-c-bug/m-p/4168782#M43537</link>
      <description>&lt;!--!*#--&gt;Hello,&lt;BR /&gt;&lt;BR /&gt;I believe I've found a bug in the OpenVMS C++ compiler.  I couldn't find a way to report it on the website, so I'm posting here in the hope that someone from the C++ team is reading ;-)&lt;BR /&gt;&lt;BR /&gt;I'm using C++ V7.3-009 on OpenVMS Alpha V8.3.  When I compile this code:&lt;BR /&gt;&lt;BR /&gt;#include        &lt;STRING&gt;&lt;BR /&gt;&lt;BR /&gt;void f(std::string const &amp;amp;a) {}&lt;BR /&gt;void f(std::string &amp;amp;b) {}                      &lt;BR /&gt;std::string g() { return "test"; }&lt;BR /&gt;&lt;BR /&gt;int main() {&lt;BR /&gt;        f(g());&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;I receive this error:&lt;BR /&gt;&lt;BR /&gt;        f(g());&lt;BR /&gt;..........^&lt;BR /&gt;%CXX-W-REFTEMPORARY, initial value of reference to non-const must be an&lt;BR /&gt;          lvalue&lt;BR /&gt;at line number 8 in file DQA0:[users.river]test2.cxx;6&lt;BR /&gt;&lt;BR /&gt;I believe the compiler is in error here, because passing a temporary T to a function taking a T const&amp;amp; is allowed; the compiler should call the first function.  Instead, it seems to be ignoring the first function, and calling the second (which correctly gives an error because a temporary cannot be converted to a T&amp;amp;).&lt;BR /&gt;&lt;BR /&gt;I have tested this example with Comeau C++ and GNU C++, both of which compile it correctly.&lt;/STRING&gt;</description>
      <pubDate>Thu, 27 Mar 2008 06:04:59 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-openvms/hp-c-bug/m-p/4168782#M43537</guid>
      <dc:creator>River Tarnell</dc:creator>
      <dc:date>2008-03-27T06:04:59Z</dc:date>
    </item>
    <item>
      <title>Re: HP C++ bug?</title>
      <link>https://community.hpe.com/t5/operating-system-openvms/hp-c-bug/m-p/4168783#M43538</link>
      <description>River,&lt;BR /&gt;&lt;BR /&gt;&amp;gt; I believe the compiler is in error here&lt;BR /&gt;&lt;BR /&gt;I believe there is cause for discussion here.&lt;BR /&gt;When interpreting the "f(g());" construct, the compiler has to decide which one of the two variants of the function "f" it should take. Depending on the return type of the function "g" (which is a "std::string"), the argument of the second variant matches more closely than the argument of the 1st variant (which has the "const").&lt;BR /&gt;Why not help the compiler a bit by type casting like "f((const std::string &amp;amp;)g());"&lt;BR /&gt;&lt;BR /&gt;Hope this helps.&lt;BR /&gt;Kris (aka Qkcl)</description>
      <pubDate>Thu, 27 Mar 2008 06:39:36 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-openvms/hp-c-bug/m-p/4168783#M43538</guid>
      <dc:creator>Kris Clippeleyr</dc:creator>
      <dc:date>2008-03-27T06:39:36Z</dc:date>
    </item>
    <item>
      <title>Re: HP C++ bug?</title>
      <link>https://community.hpe.com/t5/operating-system-openvms/hp-c-bug/m-p/4168784#M43539</link>
      <description>&lt;!--!*#--&gt;I don't agree; I believe the compiler much choose the first function.  This is what the C++ standard (1998 edition) has to say about overload resolution of free functions:&lt;BR /&gt;&lt;BR /&gt;Firstly, section 13.3.1.1.1, describing how "candidate functions" for an overloaded call are selected:&lt;BR /&gt;   [...] If the name resolves to a nonmember function declaration, that function and its overloaded declarations constitute the set of candidate functions&lt;BR /&gt;&lt;BR /&gt;So, we start with both overloads of "f" as candidate functions.&lt;BR /&gt;&lt;BR /&gt;Then, according to 13.3, paragraph 3:&lt;BR /&gt;  &lt;BR /&gt;  [...] once the candidate functions and argument lists have been identified, the selection of the best function is the same in all cases:&lt;BR /&gt;    â   First, a subset of the candidate functionsâ  those that have the proper number of arguments and meet certain other conditionsâ  is selected to form a set of viable functions (13.3.2).&lt;BR /&gt;    â   Then the best viable function is selected based on the implicit conversion sequences (13.3.3.1) needed to match each argument to the corresponding parameter of each viable function.&lt;BR /&gt;&lt;BR /&gt;13.3.2 defines a "viable function":&lt;BR /&gt;&lt;BR /&gt;2 First, to be a viable function, a candidate function shall have enough parameters to agree in number with the&lt;BR /&gt;arguments in the list.&lt;BR /&gt;3 Second, for F to be a viable function, there shall exist for each argument an implicit conversion sequence&lt;BR /&gt;(13.3.3.1) that converts that argument to the corresponding parameter of F. If the parameter has reference&lt;BR /&gt;type, the implicit conversion sequence includes the operation of binding the reference, and the fact that a&lt;BR /&gt;reference to nonconst cannot be bound to an rvalue can affect the viability of the function (see 13.3.3.1.4).&lt;BR /&gt;&lt;BR /&gt;2. is true for both overloads of f; they both have a single argument.  However, 13.3.3.1 makes it clear that 3. is not true for the second f:&lt;BR /&gt;&lt;BR /&gt;13.3.3.1:&lt;BR /&gt;  5 For the case where the parameter type is a reference, see 13.3.3.1.4.&lt;BR /&gt;13.3.3.1.4:&lt;BR /&gt;  3 A standard conversion sequence cannot be formed if it requires binding a reference to nonconst to an rvalue (except when binding an implicit object parameter; see the special rules for that case in 13.3.1).&lt;BR /&gt;  [Note: this means, for example, that a candidate function cannot be a viable function if it has a nonconst reference parameter (other than the implicit object parameter) and the corresponding argument is a temporary or would require one to be created to initialize the reference (see 8.5.3). ]&lt;BR /&gt;&lt;BR /&gt;The argument - g() - is a temporary of type std::string; therefore, it cannot be bound to the "std::string &amp;amp;" argument of the second f().  Therefore, the second f() is not a viable function, and the compiler must discard it.  The only remaining viable function -- and therefore the best -- is the first f().</description>
      <pubDate>Thu, 27 Mar 2008 07:54:29 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-openvms/hp-c-bug/m-p/4168784#M43539</guid>
      <dc:creator>River Tarnell</dc:creator>
      <dc:date>2008-03-27T07:54:29Z</dc:date>
    </item>
    <item>
      <title>Re: HP C++ bug?</title>
      <link>https://community.hpe.com/t5/operating-system-openvms/hp-c-bug/m-p/4168785#M43540</link>
      <description>I couldn't find a way to report it on the website, so I'm posting here in the hope that someone from the C++ team is reading ;-)&lt;BR /&gt;&lt;BR /&gt;--&lt;BR /&gt;&lt;BR /&gt;I'm not with the C++ compiler team, but I've asked someone in VMS Engineering who does work with various compilers to take a look at this thread.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;-- Rob</description>
      <pubDate>Thu, 27 Mar 2008 16:19:26 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-openvms/hp-c-bug/m-p/4168785#M43540</guid>
      <dc:creator>Robert Brooks_1</dc:creator>
      <dc:date>2008-03-27T16:19:26Z</dc:date>
    </item>
    <item>
      <title>Re: HP C++ bug?</title>
      <link>https://community.hpe.com/t5/operating-system-openvms/hp-c-bug/m-p/4168786#M43541</link>
      <description>A reply . . .&lt;BR /&gt;&lt;BR /&gt;The default is /standard=relaxed, which enables an&lt;BR /&gt;anachronism that our previous versions of the compiler&lt;BR /&gt;supported, and we chose not to break existing customer&lt;BR /&gt;code compiled with default options when newer versions&lt;BR /&gt;implemented the standard behavior.&lt;BR /&gt;&lt;BR /&gt;The choices are to compile with /standard=strict, or&lt;BR /&gt;add the undocumented option /switch=no_nonconst_ref_anachronism</description>
      <pubDate>Thu, 27 Mar 2008 17:17:51 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-openvms/hp-c-bug/m-p/4168786#M43541</guid>
      <dc:creator>Robert Brooks_1</dc:creator>
      <dc:date>2008-03-27T17:17:51Z</dc:date>
    </item>
  </channel>
</rss>

