Uploaded image for project: 'C++ Standard Library'
  1. C++ Standard Library
  2. STDCXX-945

[Sun C++] truncwarn on safe conversion

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: External
    • Labels:
      None
    • Severity:
      Compiler Warning

      Description

      Dear Sun Studio Developer,

      Thank you for your interest in improving the quality of Sun Studio
      product.

      Your report has been assigned an internal review ID of 1254911.

      Please be aware that the large volume of reports we receive sometimes
      prevents us from responding individually to each message.

      If the information is determined to be a new Bug or Request for
      Enhancement (RFE), or a duplicate of a known Bug or RFE, you will
      receive a followup email containing a seven digit bug number. By
      using this seven digit bug number, you may search for, view, or vote
      for this bug in the Bug Database at http://bugs.sun.com/. Please note
      that we cannot promise to fix all reported bugs.

      If you just reported an issue that could have a major impact on your
      project and require a timely response, please consider purchasing
      one of the support offerings described at
      http://developers.sun.com/prodtech/cc/support/support_services.jsp.

      The Sun Developer Network (http://developers.sun.com) is a free service
      that Sun offers. To join, visit http://developers.sun.com/global/join_sdn.html.

      Regards,
      Sun Studio Developer Bug Report Review Team

      ---------------------------------------------------------------

      Date Created: Fri May 23 11:23:54 MDT 2008
      Type: bug
      Customer Name: Martin Sebor
      Customer Email: sebor AT roguewave DOT com
      SDN ID:
      status: Waiting
      Category: c++
      Subcategory: other
      Company: Rogue Wave Software
      release: studio12
      hardware: sun4
      OSversion: solaris_10
      priority: 4
      Synopsis: truncwarn on safe code
      Description:
      FULL PRODUCT VERSION :

      ADDITIONAL OS VERSION INFORMATION :
      Solaris 10

      A DESCRIPTION OF THE PROBLEM :
      The compiler issues conversion warnings for obviously safe code. For instance, the initialization:
      on line 2 below cannot cause truncation since the result of the & operator is guaranteed to be in range of unsigned int (on both ILP32 and LP64), even though the type of the initializer expression is wider than the object under initialization.

          /* 1 */ unsigned long  a = 0;
          /* 2 */ unsigned int   b = a & 0xffffffff;
      

      The compiler should detect these cases and avoid issuing warnings for them.

      In addition, as the Error Message(s) show, all the warnings are unnecessarily duplicated.

      Finally, declaring each object const silences the warnings. The warnings should be issued consistently, regardless of any cv-qualifiers.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Compile attached program as follows:

      CC +w -m64 -V u.cpp
      

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      No conversion (truncation) warnings.
      ACTUAL -
      Conversion (truncation) warnings.

      ERROR MESSAGES/STACK TRACES THAT OCCUR :

      CC: Sun C++ 5.9 SunOS_i386 Patch 124864-01 2007/07/25
      /amd/packages/mdx/solaris/amd64/compilers/sun/C++5.9j1/prod/bin/c++filt: Sun C++ 5.9 SunOS_i386 2007/05/03
      ccfe: Sun C++ 5.9 SunOS_i386 Patch 124864-01 2007/07/25
      "u.cpp", line 4: Warning: Conversion of 64 bit type value to "const unsigned" causes truncation.
      "u.cpp", line 4: Warning: Conversion of 64 bit type value to "const unsigned" causes truncation.
      "u.cpp", line 5: Warning: Conversion of 64 bit type value to "const unsigned short" causes truncation.
      "u.cpp", line 5: Warning: Conversion of 64 bit type value to "const unsigned short" causes truncation.
      "u.cpp", line 6: Warning: Conversion of 64 bit type value to "const unsigned char" causes truncation.
      "u.cpp", line 6: Warning: Conversion of 64 bit type value to "const unsigned char" causes truncation.
      6 Warning(s) detected.
      ld: Software Generation Utilities - Solaris Link Editors: 5.10-1.482
      

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------

      int main ()
      {
          /* const */ unsigned long  a = 0;
          const unsigned int   b = a & 0xffffffff;
          const unsigned short c = a & 0xffff;
          const unsigned char  d = a & 0xff;
      }
      

      ---------- END SOURCE ----------
      workaround:
      comments: (company - Rogue Wave Software , email - sebor@roguewave.com)

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              sebor Martin Sebor
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated: