[PATCH] D143840: [clang] Add the check of membership for the issue #58674 and improve the lookup process

Jordan Rupprecht via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Feb 23 18:26:29 PST 2023


rupprecht added a comment.

This has already been reverted, but I found a breakage (not a crash) caused by this:

  #include <type_traits>
  
  class Base {
   protected:
    int member;
  };
  
  template <typename Parent>
  struct Subclass : public Parent {
    static_assert(std::is_base_of<Base, Parent>::value,
                  "Parent not derived from Base");
    int func() { return Base::member; }
  };
  
  using Impl = Subclass<Base>;
  
  int use() {
    Impl i;
    return i.func();
  }

gcc/msvc both accept this. But clang says:

  <source>:8:29: error: 'member' is a protected member of 'Base'
    int func() { return Base::member; }
                              ^
  <source>:15:12: note: in instantiation of member function 'Subclass<Base>::func' requested here
    return i.func();
             ^
  <source>:3:7: note: must name member using the type of the current context 'Subclass<Base>'
    int member;
        ^

A fix is to write `Parent::member` instead of `Base::member`, but I'm wondering what the spec actually says about this, and if clang is right to reject it.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D143840/new/

https://reviews.llvm.org/D143840



More information about the cfe-commits mailing list