IBM Support

PK85126: COMPILER ERROR WHEN USING FRIEND CLASS TO ACCESS PROTECTED MEMB ERS OF A CLASS

Subscribe

You can track all active APARs for this component.

APAR status

  • Closed as Permanent restriction.

Error description

  • Quintus defect :223845
    
    
                Summary:
    ---------
    Compiler error when using friend class to access protected
    members of a class
    
    Description:
    ------------
    The reason that this is a defect is simply that the
    CPP_CG.Class.Friend
    property does not work for parts with the Advanced compiler and
    MS VC6.
    
    The VC6 compiler error is correct according to the specification
    of the
    C++ language.  In 'The C++ Programming Language' by Bjarne
    Stroustrup
    (I'm using the 3rd edition), section C.11.3 'Access to Member
    Class', it
    is clear in the example that an Inner class should be declared
    before it is granted friend access to its Outer class.
    
    The classic code generator
    (CPP_CG.Configuration.CodeGeneratorTool =
    Classic) produces code that compiles OK with VC6 --- this
    problem has
    only arisen with the Advanced code generator.
    
    The defect is that the Advanced compiler should declare all part
    classes
    before friend declarations, as per the C++ language
    specification.
    There are (at least) two possible ways of doing this:
    1. Have forward declarations of all parts, before the friend
    declarations (this is what the classic compiler does), or
    2. Place the friend declarations after the declarations of all
    parts
    (this is like work-around using the specification epilog and not
    friend class property).
    
    Steps to reproduce:
    -------------------
    Create a class Container
    Add a protected operation OpInContainer to this class
    Create a part Object_0 inside Container
    Add an operation OpInObject to this object
    Add association between the two
    In OpInObject accesss mycontainer-?OpInContainer();
    Add object_0 as friend to container
    Build the model in VC6 and observe the error.
    
    Defect: All forward decalarations of parts should come before
    the friend declaration , which doesn happen in this case.
    
    Open project placed in \\ilre-dc\TestCases\Rhapsody\
    Error: Cannot access protected member of a class
    (With cygwin it gives redefinition error since friend class is
    added for the part as well)
    
    Compiles fine in Rhp 7.2
    Does not compile with Rhp 7.4 and higher
    Exception:
    
    Compiles fine with MSVS 2005
    Does not compile with VC6
    
    PMR Number: PMR 61794,019,866
    

Local fix

  • CPP_CG.Class.SpecificationEpilog and add code for a
    friend declaration
    after the declaration of the part class
    

Problem summary

  • ****************************************************************
    * USERS AFFECTED:                                              *
    ****************************************************************
    * PROBLEM DESCRIPTION:                                         *
    ****************************************************************
    * RECOMMENDATION:                                              *
    ****************************************************************
    Compiler error when using a friend class to access protected
    members of a class.
    

Problem conclusion

  • There are no plans at the moment to change this code
    generation behavior. There are two available workarounds:
    1) Add "class" to the friend declaration. For example,
    instead of using MyClass for the CPP_CG::Class::Friend
    property, use "class MyClass".
    2) Model a ??Friend?? dependency.
    Either of these approaches will result in code that
    compiles.
    

Temporary fix

Comments

APAR Information

  • APAR number

    PK85126

  • Reported component name

    TLOGIC RHAPSODY

  • Reported component ID

    5724V74RP

  • Reported release

    740

  • Status

    CLOSED PRS

  • PE

    NoPE

  • HIPER

    NoHIPER

  • Special Attention

    NoSpecatt

  • Submitted date

    2009-04-22

  • Closed date

    2010-12-16

  • Last modified date

    2010-12-16

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

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

Fix information

Applicable component levels



Document information

More support for: Rational Rhapsody

Software version: 7.4

Reference #: PK85126

Modified date: 16 December 2010