llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.76k stars 11.89k forks source link

clang does not implement DR472 #16602

Open 991901f3-cc14-4404-b340-165691b62a58 opened 11 years ago

991901f3-cc14-4404-b340-165691b62a58 commented 11 years ago
Bugzilla Link 16228
Version unspecified
OS All
CC @DougGregor,@zygoloid

Extended Description

Per http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#472 we should not allow the following code:

class B {
public:
  int m;
};

class S: private B {
  friend class N;
};
class N: private S {
  void f() {
    B* p = this;    // OK because class S satisfies the fourth condition
                    // above: B is a base class of N accessible in f() because
                    // B is an accessible base class of S and S is an accessible
                    // base class of N.
  }
};

class N2: protected B { };

class P2: public N2 {
  void f2(N2* n2p) {
    B* bp = n2p;    // error: invented member would be protected and naming
                    // class N2 not the same as or derived from the referencing
                    // class P2
    n2p->m = 0;     // error (cf 11.4 [class.protected]) for the same reason
  }
};

GCC correctly raises a diagnostic.

991901f3-cc14-4404-b340-165691b62a58 commented 11 years ago

Sorry about that! I interpreted "Status: drafting" as tacit agreement that there was consensus on how to handle this case.

ec04fc15-fa35-46f2-80e1-5d271f2ef708 commented 11 years ago

DR472 is still open, and the current wording on the core issues list is incorrect. We don't yet know what the revised rule will be, but I expect it'll end up mirroring 11.4/1's wording to the extent possible.

(FWIW, I've started to track Clang's state on various DRs at http://clang.llvm.org/cxx_dr_status.html, but I've not got as far as this one yet)

arsenm commented 1 year ago

clang and gcc error today:

/tmp/issue16602.cpp:25:10: error: 'm' is a protected member of 'B'
   25 |     n2p->m = 0;     // error (cf 11.4 [class.protected]) for the same reason
      |          ^
/tmp/issue16602.cpp:18:11: note: constrained by protected inheritance here
   18 | class N2: protected B { };
      |           ^~~~~~~~~~~
/tmp/issue16602.cpp:3:7: note: member is declared here
    3 |   int m;
      |       ^
1 error generated.
shafik commented 1 year ago

CC @Endilll

Endilll commented 1 year ago

Yeah, I'll get back to C++ DRs at some point.

llvmbot commented 1 year ago

@llvm/issue-subscribers-clang-frontend

Endilll commented 1 year ago

We don't issue a diagnostic for the key test case, so this is not resolved yet.