public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* gcc 3.4.5: Partially specialized descendant of template doesn't see members of base
@ 2006-10-07  9:08 Mazay
  2006-10-08 13:27 ` Dima Sorkin
  0 siblings, 1 reply; 2+ messages in thread
From: Mazay @ 2006-10-07  9:08 UTC (permalink / raw)
  To: gcc-help

Hello.

I'm not sure, if this code should to compile in accordance with ISO, but it
compiles by g++ 4.1.1 and by VC2003-2005.

Here is a little test for it:

---------------------------------------------------------
template<class T>
class Base
{
protected:
    T x;
    Base() {}
};

template <class T,int num>
class Der: public Base<T>
{
public:
    using Base<T>::x; 

    Der():Base<T>() {}
    int get();
};

template <class T>
class Der<T,4>: public Base<T>
{
public:
    using Base<T>::x; //!!

    Der():Base<T>() {}
    int get();
};
    
template <class T,int num>
int Der<T,num>::get()
{
    return x-num;
} 

template <class T>
int Der<T,4>::get()
{
    return x+4; //38 row. The error is here. x is not declared in this scope.
}  

int main()
{
    return 0;
}
---------------------------------------------------------

Compilation output:
---------------------------------------------------------
C:\prg\test\mingw_templ>g++ main.cpp
main.cpp: In member function `int Der<T, 4>::get()':
main.cpp:38: error: `x' was not declared in this scope
---------------------------------------------------------

Compiler version information:
---------------------------------------------------------
C:\prg\test\mingw_templ>g++ -v
Reading specs from C:/Install/MinGW/bin/../lib/gcc/mingw32/3.4.5/specs
Configured with: ../gcc-3.4.5/configure --with-gcc --with-gnu-ld --with-gnu-as --host=mingw32 --target=mingw32 --prefix=
/mingw --enable-threads --disable-nls --enable-languages=c,c++,f77,ada,objc,java --disable-win32-registry --disable-shar
ed --enable-sjlj-exceptions --enable-libgcj --disable-java-awt --without-x --enable-java-gc=boehm --disable-libgcj-debug
 --enable-interpreter --enable-hash-synchronization --enable-libstdcxx-debug
Thread model: win32
gcc version 3.4.5 (mingw special)
---------------------------------------------------------

An error can be fixed by replacing of string "return x+4;"
 by "return this->x+4;". But it is fairly bad decision.
I suppose that this is a bug (because it compiles by 4.1.1), but I
can't use newer compiler, because 3.4.5 is the lattest in MinGW. And I
have to use MinGW :( .
I hope, that some better workaround or patch for compiler exists, and
somebody here can help me.
        

Regards,
Mazay.


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: gcc 3.4.5: Partially specialized descendant of template doesn't see members of base
  2006-10-07  9:08 gcc 3.4.5: Partially specialized descendant of template doesn't see members of base Mazay
@ 2006-10-08 13:27 ` Dima Sorkin
  0 siblings, 0 replies; 2+ messages in thread
From: Dima Sorkin @ 2006-10-08 13:27 UTC (permalink / raw)
  To: Mazzzy2005; +Cc: gcc-help

Hi.
 See my remarks with "///".
Regards,
 Dima.

On 10/7/06, Mazay wrote:
> template <class T>
> class Der<T,4>: public Base<T>
> {
> public:
>     using Base<T>::x; //!!
///   I think this is misuse of "using". "using" in a class scope is
intended for
/// disambigation in the case of multiple inheritance.

> template <class T,int num>
> int Der<T,num>::get()
> {
>     return x-num;
///   I don't know why compiler does not shout on this one, see below.

> }
>
> template <class T>
> int Der<T,4>::get()
> {
>     return x+4; //38 row. The error is here. x is not declared in this scope.
///   It should be "this->x". Otherwise compiler should shout, because
of two pass
/// compilation of the templates, it cannot know what is "x".

> }
>
> Compilation output:
> ---------------------------------------------------------
> C:\prg\test\mingw_templ>g++ main.cpp
> main.cpp: In member function `int Der<T, 4>::get()':
> main.cpp:38: error: `x' was not declared in this scope
> ---------------------------------------------------------
>
> Compiler version information:
> ---------------------------------------------------------
> C:\prg\test\mingw_templ>g++ -v
> Reading specs from C:/Install/MinGW/bin/../lib/gcc/mingw32/3.4.5/specs
> Configured with: ../gcc-3.4.5/configure --with-gcc --with-gnu-ld --with-gnu-as

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2006-10-08 13:27 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-10-07  9:08 gcc 3.4.5: Partially specialized descendant of template doesn't see members of base Mazay
2006-10-08 13:27 ` Dima Sorkin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).