IBM Support

LI74341: Error being incorrectly generated by the xlC compiler

Subscribe

You can track all active APARs for this component.

 

APAR status

  • Closed as program error.

Error description

  • Problem:
    A friend declaration inside of a class inside of a namespace
    inside
    of an extern "C" block is incorrectly generating an error.
    
    =====Start of a.C======
    extern "C" {
      namespace N {
      struct A {
        friend void foo();
      };
      }
    }
    ==========End of a.C==============
    
    $xlC -c a.C
    "a.C", line 4.19: 1540-0434 (S) The friend function must also be
    declared in the enclosing block scope.
    

Local fix

  • You can also use a work around to solve the problem.  The
    original code had extern "C" around everything (i.e. the
    namespace and class definition).  This is overkill and can be
    confusing since the member functions have to follow the C++
    linkage.  If it is feasible you can look at changing the source
    code to something more accurate.  See the following example.
    This gives you an alternate to waiting for an interim compiler
    fix.  The work around is still valid C++ code and should be
    compiled by other compilers too.
    
    -- a-fix.C
    namespace N {
      extern "C" {
        void foo();
      }
      struct A {
        friend void foo();
      };
    }
    -- a-fix.C --
    This work around is more typical C++ code.  You should have
    better luck porting it from compiler to compiler.
    

Problem summary

  • Users who want to have a friend declaration inside a
    class/struct inside of a namespace inside of an extern "C"
    block. An incorrect error was generated.
    
    The original intent of the error is to catch friend declaration
    inside a local class (without prior declaration).
    We incorrectly applied the same check on a namespace inside of
    an extern "C" block.
    

Problem conclusion

  • Additional if statements are in place to distinguish a local
    class from a namespace inside of an extern "C" block before the
    check.
    

Temporary fix

Comments

APAR Information

  • APAR number

    LI74341

  • Reported component name

    XL C/C++ SLES10

  • Reported component ID

    5724U8300

  • Reported release

    A10

  • Status

    CLOSED PER

  • PE

    NoPE

  • HIPER

    NoHIPER

  • Special Attention

    NoSpecatt

  • Submitted date

    2009-03-31

  • Closed date

    2009-03-31

  • Last modified date

    2009-03-31

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

    IZ33823

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

    LI74403

Fix information

  • Fixed component name

    XL C/C++ SLES10

  • Fixed component ID

    5724U8300

Applicable component levels

[{"Business Unit":{"code":"BU054","label":"Systems w\/TPS"},"Product":{"code":"SSJT9L","label":"XL C\/C++"},"Platform":[{"code":"PF025","label":"Platform Independent"}],"Version":"A.1","Line of Business":{"code":"LOB08","label":"Cognitive Systems"}}]

Document Information

Modified date:
16 October 2021