c++/6079: Access error message discrepancy between template & plain class
jdonner@schedsys.com
jdonner@schedsys.com
Wed Mar 27 20:46:00 GMT 2002
>Number: 6079
>Category: c++
>Synopsis: Access error message discrepancy between template & plain class
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: unassigned
>State: open
>Class: change-request
>Submitter-Id: net
>Arrival-Date: Wed Mar 27 20:46:01 PST 2002
>Closed-Date:
>Last-Modified:
>Originator: JDonner
>Release: gcc 3.0.4
>Organization:
>Environment:
Reading specs from /usr/local/gcc304/lib/gcc-lib/i686-pc-linux-gnu/3.0.4/specs
Configured with: /home/jdonner/mk304/gcc-3.0.4/configure --prefix=/usr/local/gcc304 --enable-threads
Thread model: posix
gcc version 3.0.4
>Description:
In some circumstances g++ doesn't warn about a hidden type as directly as in others.
// badtypedef.cpp
#if defined(CASE1)
# define TMPL_ERR_MSG
#elif defined(CASE2)
# define TMPL_ERR_MSG
# define TMPL_ERR_HELPER
#endif
struct Highup{Highup() {}};
class Base : public Highup {
typedef Highup Inherited;
struct Secret{};
public:
Base() : Inherited() {}
};
#ifdef TMPL_ERR_MSG
template <class SomeT>
#endif
struct Derived : public Base {
Derived(int x) : Inherited() {
#ifdef TMPL_ERR_HELPER
Secret s;
#endif
}
};
int main() { Derived<int> d(3); }
///////////////////////////////////////
-- Normal case;
jdonner@deathstar ~> g++ badtypedef.cpp
badtypedef.cpp: In constructor `Derived::Derived(int)':
badtypedef.cpp:11: `typedef struct Highup Base::Inherited' is private
badtypedef.cpp:21: within this context
-- Making Derived a template, g++ no longer says explicitly that
-- 'Inherited' is private;
jdonner@deathstar ~> g++ -DCASE1 badtypedef.cpp
badtypedef.cpp: In constructor `Derived<SomeT>::Derived(int) [with SomeT = int]':
badtypedef.cpp:28: instantiated from here
badtypedef.cpp:21: `Highup' is not an immediate base class of `Derived<int>'
-- But referring to another hidden type restores the message about 'Inherited'.
jdonner@deathstar ~> g++ -DCASE2 badtypedef.cpp
badtypedef.cpp: In constructor `Derived<SomeT>::Derived(int)':
badtypedef.cpp:12: `struct Base::Secret' is private
badtypedef.cpp:23: within this context
badtypedef.cpp:11: `typedef struct Highup Base::Inherited' is private
badtypedef.cpp:23: within this context
badtypedef.cpp: In constructor `Derived<SomeT>::Derived(int) [with SomeT = int]':
badtypedef.cpp:28: instantiated from here
badtypedef.cpp:21: `Highup' is not an immediate base class of `Derived<int>'
g++ 2.95 does the same thing except CASE2 is no different from CASE1.
>How-To-Repeat:
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the Gcc-prs
mailing list