This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug debug/80877] New: Derived template class can access base class's private constexpr/const static fields


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

            Bug ID: 80877
           Summary: Derived template class can access base class's private
                    constexpr/const static fields
           Product: gcc
           Version: 6.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: debug
          Assignee: unassigned at gcc dot gnu.org
          Reporter: tomasz.jankowski at nokia dot com
  Target Milestone: ---

Following example shows that in some cases GCC incorrectly grants access to
base class's private static members (both constexpr and const). The issue
occurs when derived class is a template class.

class Base
{
   private:
      constexpr static int value1 {4};
      const static int value2 {5};
};

template<typename T>
class Derived : public Base
{
   public:
      Derived() :
         x{value1 + value2}
      {
         x = value1 + value2;
      }

      T getX() const
      {
         return x + value1 + value2;
      }

   private:
      T x;
};   

int main()
{
   Derived<int> temp;
   return temp.getX();
}

Code was tested on recent x86-64 Linux machine using GCC v6.2.0 and v5.3.0.
Sample was compiled with following flags:
-std=c++11 -Wall -Wextra

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]