c++/6402: Qualified reference to variable causes copy

wolfgang.bangerth@iwr.uni-heidelberg.de wolfgang.bangerth@iwr.uni-heidelberg.de
Mon Apr 22 04:46:00 GMT 2002


>Number:         6402
>Category:       c++
>Synopsis:       Qualified reference to variable causes copy
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Apr 22 01:46:01 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     Wolfgang Bangerth
>Release:        unknown-1.0
>Organization:
>Environment:
gcc 2.95, 3.1pre, 3.2 mainline
>Description:
The following snippet doesn't compiler, although I believe
it should. The copy operation is caused by me qualifying
the name of the member variable "t" with the name of the
base class. The original code came from an application
where the base class exists twice and a qualification is
actually necessary.

Regards
  Wolfgang

-----------------------code------------------------
struct T {
    T();
  private:
    T (const T&);
};

struct Base {
    T t;
};

struct Derived : public Base {
    void f() {
      const T &t_ref = Base::t;  // taking reference, not a copy!
    };
};

-----------------error message-----------------------
x.cc: In method `void Derived::f()':
x.cc:4: `T::T(const T &)' is private
x.cc:13: within this context
>How-To-Repeat:

>Fix:

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



More information about the Gcc-bugs mailing list