IBM Support

IV86728: UNNECESSARY PRIVATE COPY CONSTRUCTOR WARNING

Subscribe

You can track all active APARs for this component.

 

APAR status

  • Closed as program error.

Error description

  • An unexpected warning is output when compiling with the
    -qlanglvl=extended0x option to enable XLC's C++11 support
    related to copy constructor class visibility.
    
    
       === TEST CASE ===
    
    #include <iostream>
    #include <string>
    
    namespace copy
    {
     class CopyConstructor
     {
      private:
       std::string m_str;
    
       CopyConstructor(const CopyConstructor &){};
       CopyConstructor &operator=(const CopyConstructor &) {};
    
      public:
       CopyConstructor(const std::string &str) : m_str(str) { }
    
      const std::string & toString() const { return m_str; }
     };
    
     void MyFunction(const CopyConstructor &str) { }
    }
    
    int main()
    {
     copy::MyFunction(std::string("Hello"));
    }
    
    
    $ xlC_r test.cpp -qlanglvl=extended0x
    "test.cpp", line 25.26: 1540-0306 (W) The "private" copy
    constructor "CopyConstructor(const CopyConstructor &)" cannot be
    accessed.
    "test.cpp", line 25.26: 1540-0308 (I) The semantics specify that
    a temporary object must be constructed.
    "test.cpp", line 25.26: 1540-0309 (I) The temporary is not
    constructed, but the copy constructor must be accessible.
    "test.cpp", line 12.78: 1540-1101 (W) A return value of type
    "copy::CopyConstructor &" is expected.
    $
    

Local fix

  • Use -qsuppress to suppress the individual warning messages.
    

Problem summary

  • PROBLEM DESCRIPTION:
    An unnecessary warning was generated for the copy constructor.
    
    The warning is correct given the wording for C++03.  The
    reference binding goes through the non-reference copy
    initialization path, which involves a direct initialization
    step, technically requiring the copy constructor.  However, a
    warning in this case is no longer required for C++11.
    
    USERS AFFECTED:
    Users of the C++11 language level.
    

Problem conclusion

  • The warning behaviour will remain the same for default C++03
    compiles.  The message generation is now disabled with the
    C++11 language level via -qlanglvl=extended0x .
    

Temporary fix

Comments

APAR Information

  • APAR number

    IV86728

  • Reported component name

    XL C/C++ FOR AI

  • Reported component ID

    5725C7200

  • Reported release

    D13

  • Status

    CLOSED PER

  • PE

    NoPE

  • HIPER

    NoHIPER

  • Special Attention

    NoSpecatt / Xsystem

  • Submitted date

    2016-07-11

  • Closed date

    2016-12-21

  • Last modified date

    2016-12-21

  • APAR is sysrouted FROM one or more of the following:

  • APAR is sysrouted TO one or more of the following:

    IV91673

Fix information

  • Fixed component name

    XL C/C++ FOR AI

  • Fixed component ID

    5725C7200

Applicable component levels

[{"Business Unit":{"code":"BU048","label":"IBM Software"},"Product":{"code":"SSGH3R","label":"XL C\/C++ for AIX"},"Component":"","ARM Category":[],"Platform":[{"code":"PF025","label":"Platform Independent"}],"Version":"D13","Edition":"","Line of Business":{"code":"LOB73","label":"Power TPS"}}]

Document Information

Modified date:
19 August 2024