[PATCH] D122460: [clang] fixed bug #54406

Randy via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Mar 24 22:09:55 PDT 2022


randyli created this revision.
randyli added reviewers: doug.gregor, rjmccall, rsmith, dblaikie, tigerleapgorge.
Herald added a project: All.
randyli requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

try to fix bug #54406

Per [class.access.base]/6, this example is ill-formed:

struct A {

  int m;

} a;
struct B : A {};
int n = a.B::m;
... because the object expression a cannot be implicitly converted to B (because B is not a base class of A). Clang does not diagnose this and accepts the member access. This opens a hole in the protected member access rules:

struct C {
protected:

  int m;

};
struct D : private C {

  int get(C &c) { return c.D::m; }

};
This example is invalid for the same reason, but Clang accepts it. ([class.protected]p1, which normally would prevent D from accessing protected members on a C object that is not a D object, does not apply here because m as a member of the naming class D is private, not protected.)


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D122460

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaExprMember.cpp
  clang/test/CXX/class.access/class.protected/p1.cpp
  clang/test/CXX/drs/dr1xx.cpp
  clang/test/CXX/expr/expr.prim/expr.prim.general/p8-0x.cpp
  clang/test/SemaCXX/member-expr.cpp
  clang/test/SemaCXX/qual-id-test.cpp
  clang/test/SemaTemplate/typo-dependent-name.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D122460.418131.patch
Type: text/x-patch
Size: 8366 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220325/d511d2e4/attachment.bin>


More information about the cfe-commits mailing list