Non-class, non-function friend declarations
11.8.4 [class.friend]
John Spicer

Created on 2008-09-18.00:00:00 last changed 1 month ago


Date: 2023-02-15.00:00:00

Additional notes (February, 2023)

Forwarding to EWG for review of this extension, per decision of the CWG chair. See cplusplus/papers#1466.

Date: 2008-09-18.00:00:00

With the change from a scope-based to an entity-based definition of friendship (see issues 372 and 580), it could well make sense to grant friendship to enumerations and variables, for example:

    enum E: int;
    class C {
      static const int i = 5;  // Private
      friend E;
      friend int x;
    enum E { e = C::i; };      // OK: E is a friend
    int x = C::i;              // OK: x is a friend

According to the current wording of 11.8.4 [class.friend] paragraph 3, the friend declaration of E is well-formed but ignored, while the friend declaration of x is ill-formed.

Date User Action Args
2023-02-12 17:47:41adminsetmessages: + msg7199
2008-09-18 00:00:00admincreate