public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/30909]  New: public member of template class not visible in derived template class
@ 2007-02-21 12:22 sl at datamyway dot de
  2007-02-21 12:28 ` [Bug c++/30909] " sl at datamyway dot de
  2007-02-21 12:55 ` rguenth at gcc dot gnu dot org
  0 siblings, 2 replies; 3+ messages in thread
From: sl at datamyway dot de @ 2007-02-21 12:22 UTC (permalink / raw)
  To: gcc-bugs

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1812 bytes --]

on SuSe linux 10.0
~/wurschtel/cpp> uname -a
Linux djebe 2.6.13-15-smp #1 SMP Tue Sep 13 14:56:15 UTC 2005 i686 i686 i386
GNU/Linux
with gcc version 4.0.2 (but also with 4.1.2)
when running make on the following files
A.h:

//const int NUM_BYTES = 5;

template<int NUM_BYTES>
class A
{

 public:
  int mBytes[NUM_BYTES];


};

-----
B.h:
#include "A.h"

template<int NUM_BYTES>
class B : public A<NUM_BYTES>
{

  public:
int blee() {
  mBytes[0]++;
  return mBytes[0];
};


};
-----
x.cpp:
#include "A.h"

template<int NUM_BYTES>
class B : public A<NUM_BYTES>
{

  public:
int blee() {
  mBytes[0]++;
  return mBytes[0];
};


};
-----
makefie:
#include "A.h"

template<int NUM_BYTES>
class B : public A<NUM_BYTES>
{

  public:
int blee() {
  mBytes[0]++;
  return mBytes[0];
};


};
-----
I get compile errors:
~/wurschtel/cpp> make
rm -f x
g++ -ansi -pedantic -Wall -o x x.cpp
B.h: In member function â&#128;&#152;int B<NUM_BYTES>::blee()â&#128;&#153;:
B.h:9: error: â&#128;&#152;mBytesâ&#128;&#153; was not declared in this scope
make: *** [x] Error 1
---
when the templates are changed to classes and the template parameter is
declared as constant everything compiles and runs ok.

On older linux running g++ version 2.95.2 everything compiles and runs ok.

Sorry if this report is duplicate, i filed it yesterday along with 30893 but
cannot find it today so I assume commit failed.


-- 
           Summary: public member of template class not visible in derived
                    template class
           Product: gcc
           Version: 4.0.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: sl at datamyway dot de


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30909


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

* [Bug c++/30909] public member of template class not visible in derived template class
  2007-02-21 12:22 [Bug c++/30909] New: public member of template class not visible in derived template class sl at datamyway dot de
@ 2007-02-21 12:28 ` sl at datamyway dot de
  2007-02-21 12:55 ` rguenth at gcc dot gnu dot org
  1 sibling, 0 replies; 3+ messages in thread
From: sl at datamyway dot de @ 2007-02-21 12:28 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from sl at datamyway dot de  2007-02-21 12:27 -------
Sorry for my cut&paste, the files really are:
A.h:

//const int NUM_BYTES = 5;

template<int NUM_BYTES>
class A
{

 public:
  int mBytes[NUM_BYTES];


};

----
B.h:
#include "A.h"

template<int NUM_BYTES>
class B : public A<NUM_BYTES>
{

  public:
int blee() {
  mBytes[0]++;
  return mBytes[0];
};
};
----
x.cpp:
#include <iostream>
using namespace std;

#include "B.h"



int main (int argc, char* argv[])
{

    B<4> *b = new B<4>;
    b->blee();
    cout << b->blee() << endl; 
}
---
makefile:

.SUFFIXES:

all: x

% :: %.cpp
        rm -f $@
        g++ -ansi -pedantic -Wall -o $@ $^

% :: %.c
        rm -f $@
        g++ -o $@ $^ -lgmp -lpq

%.o :: %.cpp %.hpp
        rm -f $@
        g++ -c $< -g

%.o :: %.c
        rm -f $@
        g++ -c $< -g
---


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30909


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

* [Bug c++/30909] public member of template class not visible in derived template class
  2007-02-21 12:22 [Bug c++/30909] New: public member of template class not visible in derived template class sl at datamyway dot de
  2007-02-21 12:28 ` [Bug c++/30909] " sl at datamyway dot de
@ 2007-02-21 12:55 ` rguenth at gcc dot gnu dot org
  1 sibling, 0 replies; 3+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2007-02-21 12:55 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from rguenth at gcc dot gnu dot org  2007-02-21 12:54 -------
Read about two-stage name lookup.  Use this->mBytes.


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30909


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

end of thread, other threads:[~2007-02-21 12:55 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-02-21 12:22 [Bug c++/30909] New: public member of template class not visible in derived template class sl at datamyway dot de
2007-02-21 12:28 ` [Bug c++/30909] " sl at datamyway dot de
2007-02-21 12:55 ` rguenth at gcc dot gnu dot org

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).