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]

c++/3765: member using declaration can't change access from public



>Number:         3765
>Category:       c++
>Synopsis:       member using declaration can't change access from public
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          accepts-illegal
>Submitter-Id:   net
>Arrival-Date:   Sun Jul 22 18:56:00 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator:     David Baron
>Release:        gcc 3.0
>Organization:
>Environment:
Linux 2.2.14-5.0smp i686 (RedHat 6.2)
>Description:
A C++ using declaration cannot be used to change member access from public to private or from public to protected.  (Other combinations seem to work correctly.)  This is a regression that occurred between egcs 1.1.2 and gcc 2.95.2 and still exists in gcc 3.0.  (The error message given on the occasions where the |using| declaration works correctly also doesn't make much sense, since it gives the access that was overridden by the |using| even though it correctly changes the access.  But that's another bug.)

This is useful for things such as ensuring that users do not attempt to manually refcount an COM smart pointer:
http://lxr.mozilla.org/seamonkey/source/xpcom/base/nsCOMPtr.h#159
>How-To-Repeat:
Try to compile test case #1 or #4.  Compilation succeds even though it should not.

Test case #1:
===========
/* vim:cindent:ai:sw=2:et:ts=8:tw=72:
 *
 * Demonstration of bug in gcc 3.0 where |using| does not change access
 * from public to private. 
 *
 * ILLEGAL EXAMPLE
 * Test of changing access from public to private.
 *
 * See C++ standard, section 11.3 and 7.3.3.
 */

class A
{
  public:
    int foo() { return 1; }
};

class B : public A
{
  private:
    using A::foo;
};

int main()
{
  B b;
  return b.foo();   // Should not compile.
}
===========

Test case #2:
===========
/* vim:cindent:ai:sw=2:et:ts=8:tw=72:
 *
 * Demonstration of bug in gcc 3.0 where |using| does not change access
 * from public to private. 
 *
 * LEGAL EXAMPLE
 * Test of changing access from protected to public.
 *
 * See C++ standard, section 11.3 and 7.3.3.
 */

class A
{
  protected:
    int foo() { return 0; }
};

class B : public A
{
  public:
    using A::foo;
};

int main()
{
  B b;
  return b.foo();
}
===========

Test case #3:
===========
/* vim:cindent:ai:sw=2:et:ts=8:tw=72:
 *
 * Demonstration of bug in gcc 3.0 where |using| does not change access
 * from public to private. 
 *
 * ILLEGAL EXAMPLE
 * Test of changing access from protected to private.
 *
 * See C++ standard, section 11.3 and 7.3.3.
 */

class A
{
  protected:
    int foo() { return 1; }
};

class B : public A
{
  private:
  //protected:
    using A::foo;
};

class C : public B
{
  public:
    C() { B::foo(); }
};

int main()
{
  C c;
  return 1;
}
===========

Test case #4:
===========
/* vim:cindent:ai:sw=2:et:ts=8:tw=72:
 *
 * Demonstration of bug in gcc 3.0 where |using| does not change access
 * from public to private. 
 *
 * ILLEGAL EXAMPLE
 * Test of changing access from public to private.
 *
 * See C++ standard, section 11.3 and 7.3.3.
 */

class A
{
  public:
    int foo() { return 1; }
};

class B : public A
{
  private:
    using A::foo;
};

class C : public B
{
  public:
    C() { foo(); }
};

int main()
{
  C c;
  return 1;
}
===========

Test case #5:
===========
/* vim:cindent:ai:sw=2:et:ts=8:tw=72:
 *
 * Demonstration of bug in gcc 3.0 where |using| does not change access
 * from public to private. 
 *
 * LEGAL EXAMPLE
 * Test of changing access from protected to public.
 *
 * See C++ standard, section 11.3 and 7.3.3.
 */

class A
{
  protected:
    int foo() { return 0; }
};

class B : public A
{
  public:
    using A::foo;
};

int main()
{
  B b;
  return b.foo();
}
===========
>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:


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