https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87652

            Bug ID: 87652
           Summary: inner class template of outer class template can't
                    access friend's protected data member
           Product: gcc
           Version: 8.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: haining.cpp at gmail dot com
  Target Milestone: ---

#### Example program ####

template <typename>
struct Outer {
  template <typename>
  class Inner {
    template <typename>
    friend class Inner; // All Inners should be friends

   public:
     template <typename T>
     void use_other_x(const Inner<T>& other) const {
       (void)other.x; // should be fine, we're all friends
     }
   private: // no error if private instead
     int x;
  };
};

int main() {
  Outer<int>::Inner<void> i1;
  Outer<int>::Inner<char> i2;
  i1.use_other_x(i2);
}

#### Error message ####

prog.cc: In instantiation of 'void Outer< <template-parameter-1-1> >::Inner<
<template-parameter-2-1> >::use_other_x(const Outer< <template-parameter-1-1>
>::Inner<T>&) const [with T = char; <template-parameter-2-1> = void;
<template-parameter-1-1> = int]':
prog.cc:21:20:   required from here
prog.cc:11:20: error: 'int Outer<int>::Inner<char>::x' is protected within this
context
        (void)other.x;
              ~~~~~~^
prog.cc:14:10: note: declared protected here
      int x;


#### Notes ####

No problems observed when using private: instead of protected:

Reply via email to