public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/20028] New: problem with protected members in template inheritance
@ 2005-02-17 20:21 jcobyrne at cox dot net
  2005-02-17 20:23 ` [Bug c++/20028] " jcobyrne at cox dot net
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: jcobyrne at cox dot net @ 2005-02-17 20:21 UTC (permalink / raw)
  To: gcc-bugs

Apparently g++ isn't recognizing protected members in inheritance before the 
class declaration.  Furthermore, G++ segfaults when adding the first line, and 
the friend class.

----------------------

zehly@lain:~ $ cat a.cc
class Foo;

template <class T> class A
{ friend class Foo; protected: typedef T someType; };

template <class T> class B
{ protected: typedef T anotherType; };

template <typename T, template <class> class X, template <class> class Y>
class Foo : public X <T>, public Y <typename X<T>::someType>
{ typedef Y<typename X<T>::someType> yetAnotherType; };

int main ()
{ Foo<int, A, B> x; return 0; }

-------------

zehly@lain:~ $ g++40 -v -save-temps -o a a.cc
Using built-in specs.
Configured with: ./..//gcc-4.0-20050130/configure --disable-nls --with-system-
zlib --with-libiconv-prefix=/usr/local --program-suffix=40 --with-gxx-include-
dir=/usr/local/lib/gcc/i386-portbld-freebsd5.3/4.0.0/include/c++/ --disable-
shared --disable-libgcj --prefix=/usr/local i386-portbld-freebsd5.3
Thread model: posix
gcc version 4.0.0 20050130 (experimental) [FreeBSD]
 /usr/local/libexec/gcc/i386-portbld-freebsd5.3/4.0.0/cc1plus -E -quiet -v 
a.cc -fpch-preprocess -o a.ii
ignoring nonexistent directory "/usr/local/lib/gcc/i386-portbld-
freebsd5.3/4.0.0/../../../../i386-portbld-freebsd5.3/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/lib/gcc/i386-portbld-freebsd5.3/4.0.0/include/c++/
 /usr/local/lib/gcc/i386-portbld-freebsd5.3/4.0.0/include/c++//i386-portbld-
freebsd5.3
 /usr/local/lib/gcc/i386-portbld-freebsd5.3/4.0.0/include/c++//backward
 /usr/local/include
 /usr/local/lib/gcc/i386-portbld-freebsd5.3/4.0.0/include
 /usr/include
End of search list.
 /usr/local/libexec/gcc/i386-portbld-freebsd5.3/4.0.0/cc1plus -fpreprocessed 
a.ii -quiet -dumpbase a.cc -auxbase a -version -o a.s
GNU C++ version 4.0.0 20050130 (experimental) [FreeBSD] (i386-portbld-
freebsd5.3)
        compiled by GNU C version 4.0.0 20050130 (experimental) [FreeBSD].
GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
a.cc:10: error: 'Foo' is not a template type
a.cc: In function 'int main()':
a.cc:14: error: 'Foo' is not a template
a.cc:13: internal compiler error: Segmentation fault
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://gcc.gnu.org/bugs.html> for instructions.

----------------------

zehly@lain:~ $ cat a.ii
# 1 "a.cc"
# 1 "<built-in>"
# 1 "<command line>"
# 1 "a.cc"
class Foo;

template <class T> class A
{ friend class Foo; protected: typedef T someType; };

template <class T> class B
{ protected: typedef T anotherType; };

template <typename T, template <class> class X, template <class> class Y>
class Foo : public X <T>, public Y <typename X<T>::someType>
{ typedef Y<typename X<T>::someType> yetAnotherType; };

int main ()
{ Foo<int, A, B> x; return 0; }

-- 
           Summary: problem with protected members in template inheritance
           Product: gcc
           Version: 4.0.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: jcobyrne at cox dot net
                CC: gcc-bugs at gcc dot gnu dot org


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


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

* [Bug c++/20028] problem with protected members in template inheritance
  2005-02-17 20:21 [Bug c++/20028] New: problem with protected members in template inheritance jcobyrne at cox dot net
@ 2005-02-17 20:23 ` jcobyrne at cox dot net
  2005-02-17 22:26 ` [Bug c++/20028] [3.4/4.0 Regression] class and then template class gives an ICE pinskia at gcc dot gnu dot org
                   ` (9 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: jcobyrne at cox dot net @ 2005-02-17 20:23 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From jcobyrne at cox dot net  2005-02-17 16:08 -------
By the way, when removing the friend class and line 1 of the source file, the 
code WILL compile on g++3.2.

-- 


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


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

* [Bug c++/20028] [3.4/4.0 Regression] class and then template class gives an ICE
  2005-02-17 20:21 [Bug c++/20028] New: problem with protected members in template inheritance jcobyrne at cox dot net
  2005-02-17 20:23 ` [Bug c++/20028] " jcobyrne at cox dot net
@ 2005-02-17 22:26 ` pinskia at gcc dot gnu dot org
  2005-02-17 23:06 ` aoliva at gcc dot gnu dot org
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-02-17 22:26 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-02-17 17:55 -------
The code is invalid.
But this is a regression from 3.3.3 where we did not ICE.
Reduced testcase:
class Foo;
template <typename T> class Foo { };
int main ()
{
  Foo<int> x;
  return 0;
}


-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|                            |1
           Keywords|                            |error-recovery, ice-on-
                   |                            |invalid-code
   Last reconfirmed|0000-00-00 00:00:00         |2005-02-17 17:55:25
               date|                            |
            Summary|problem with protected      |[3.4/4.0 Regression] class
                   |members in template         |and then template class
                   |inheritance                 |gives an ICE
   Target Milestone|---                         |3.4.4


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


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

* [Bug c++/20028] [3.4/4.0 Regression] class and then template class gives an ICE
  2005-02-17 20:21 [Bug c++/20028] New: problem with protected members in template inheritance jcobyrne at cox dot net
  2005-02-17 20:23 ` [Bug c++/20028] " jcobyrne at cox dot net
  2005-02-17 22:26 ` [Bug c++/20028] [3.4/4.0 Regression] class and then template class gives an ICE pinskia at gcc dot gnu dot org
@ 2005-02-17 23:06 ` aoliva at gcc dot gnu dot org
  2005-02-17 23:20 ` cvs-commit at gcc dot gnu dot org
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: aoliva at gcc dot gnu dot org @ 2005-02-17 23:06 UTC (permalink / raw)
  To: gcc-bugs



-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |aoliva at gcc dot gnu dot
                   |dot org                     |org
             Status|NEW                         |ASSIGNED
   Last reconfirmed|2005-02-17 17:55:25         |2005-02-17 19:09:18
               date|                            |
   Target Milestone|3.4.4                       |---


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


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

* [Bug c++/20028] [3.4/4.0 Regression] class and then template class gives an ICE
  2005-02-17 20:21 [Bug c++/20028] New: problem with protected members in template inheritance jcobyrne at cox dot net
                   ` (2 preceding siblings ...)
  2005-02-17 23:06 ` aoliva at gcc dot gnu dot org
@ 2005-02-17 23:20 ` cvs-commit at gcc dot gnu dot org
  2005-02-17 23:50 ` [Bug c++/20028] [3.4 " pinskia at gcc dot gnu dot org
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: cvs-commit at gcc dot gnu dot org @ 2005-02-17 23:20 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From cvs-commit at gcc dot gnu dot org  2005-02-17 19:25 -------
Subject: Bug 20028

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	aoliva@gcc.gnu.org	2005-02-17 19:25:05

Modified files:
	gcc/cp         : ChangeLog class.c 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/g++.dg/template: crash34.C 

Log message:
	gcc/cp/ChangeLog:
	PR c++/20028
	* class.c (finish_struct): Initialize TYPE_SIZE_UNIT of a
	template along with TYPE_SIZE.
	gcc/testsuite/ChangeLog:
	PR c++/20028
	* g++.dg/template/crash34.C: New.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&r1=1.4632&r2=1.4633
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/class.c.diff?cvsroot=gcc&r1=1.705&r2=1.706
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.5043&r2=1.5044
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/crash34.C.diff?cvsroot=gcc&r1=NONE&r2=1.1



-- 


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


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

* [Bug c++/20028] [3.4 Regression] class and then template class gives an ICE
  2005-02-17 20:21 [Bug c++/20028] New: problem with protected members in template inheritance jcobyrne at cox dot net
                   ` (3 preceding siblings ...)
  2005-02-17 23:20 ` cvs-commit at gcc dot gnu dot org
@ 2005-02-17 23:50 ` pinskia at gcc dot gnu dot org
  2005-02-18  1:36 ` jcobyrne at cox dot net
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-02-17 23:50 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-02-17 20:02 -------
Patch here: <http://gcc.gnu.org/ml/gcc-patches/2005-02/msg01020.html> for 3.4.x.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch
            Summary|[3.4/4.0 Regression] class  |[3.4 Regression] class and
                   |and then template class     |then template class gives an
                   |gives an ICE                |ICE
   Target Milestone|---                         |3.4.4


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


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

* [Bug c++/20028] [3.4 Regression] class and then template class gives an ICE
  2005-02-17 20:21 [Bug c++/20028] New: problem with protected members in template inheritance jcobyrne at cox dot net
                   ` (4 preceding siblings ...)
  2005-02-17 23:50 ` [Bug c++/20028] [3.4 " pinskia at gcc dot gnu dot org
@ 2005-02-18  1:36 ` jcobyrne at cox dot net
  2005-02-18  2:59 ` pinskia at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: jcobyrne at cox dot net @ 2005-02-18  1:36 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From jcobyrne at cox dot net  2005-02-17 21:09 -------
(In reply to comment #4)
> Patch here: <http://gcc.gnu.org/ml/gcc-patches/2005-02/msg01020.html> for 
3.4.x.

The following code _IS_ correct and _DOES_ compile on 3.2.

template <class T> class A
{ protected: typedef T someType; };

template <class T> class B
{ protected: typedef T anotherType; };

// we should be able to access protected members of classes X and Y here,
// because we are inheriting them.
template <typename T, template <class> class X, template <class> class Y>
class Foo : public X <T>, public Y <typename X<T>::someType>
{ typedef Y<typename X<T>::someType> yetAnotherType; };

int main ()
{ Foo<int, A, B> x; return 0; }

-----------

I guess I stumbled on the segfault by mistake in my vain attempts to get the 
code to compile on 3.3 and greater.  Syntactically and semantically, I have 
confirmed that this code does work, and it is also used similarly in 
Alexandrescu's book on C++ Design Patterns.

-- 


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


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

* [Bug c++/20028] [3.4 Regression] class and then template class gives an ICE
  2005-02-17 20:21 [Bug c++/20028] New: problem with protected members in template inheritance jcobyrne at cox dot net
                   ` (5 preceding siblings ...)
  2005-02-18  1:36 ` jcobyrne at cox dot net
@ 2005-02-18  2:59 ` pinskia at gcc dot gnu dot org
  2005-02-18  3:22 ` jcobyrne at cox dot net
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-02-18  2:59 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-02-17 21:14 -------
(In reply to comment #5)
> (In reply to comment #4)
> I guess I stumbled on the segfault by mistake in my vain attempts to get the 
> code to compile on 3.3 and greater.  Syntactically and semantically, I have 
> confirmed that this code does work, and it is also used similarly in 
> Alexandrescu's book on C++ Design Patterns.

Yes you did stumbled on the segfault but note this is not valid code still, yes a C++ book can get it 
wrong.




-- 


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


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

* [Bug c++/20028] [3.4 Regression] class and then template class gives an ICE
  2005-02-17 20:21 [Bug c++/20028] New: problem with protected members in template inheritance jcobyrne at cox dot net
                   ` (6 preceding siblings ...)
  2005-02-18  2:59 ` pinskia at gcc dot gnu dot org
@ 2005-02-18  3:22 ` jcobyrne at cox dot net
  2005-02-18  4:12 ` pinskia at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: jcobyrne at cox dot net @ 2005-02-18  3:22 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From jcobyrne at cox dot net  2005-02-17 21:21 -------
If the code is wrong, what accounts for the fact that wrong code would compile 
on 3.2 and not on 3.3 or 3.4?  Also, Alexandrescu did not write it wrong, as it 
is also used in his Loki library that is known to compile under GCC as well as 
other compilers.

-- 


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


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

* [Bug c++/20028] [3.4 Regression] class and then template class gives an ICE
  2005-02-17 20:21 [Bug c++/20028] New: problem with protected members in template inheritance jcobyrne at cox dot net
                   ` (7 preceding siblings ...)
  2005-02-18  3:22 ` jcobyrne at cox dot net
@ 2005-02-18  4:12 ` pinskia at gcc dot gnu dot org
  2005-02-22  0:12 ` cvs-commit at gcc dot gnu dot org
  2005-02-22  0:32 ` pinskia at gcc dot gnu dot org
  10 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-02-18  4:12 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-02-17 21:26 -------
(In reply to comment #7)
> If the code is wrong, what accounts for the fact that wrong code would compile 
> on 3.2 and not on 3.3 or 3.4?  Also, Alexandrescu did not write it wrong, as it 
> is also used in his Loki library that is known to compile under GCC as well as 
> other compilers.

Because it was a bug in 3.2 and before.  It does not compile with a slightly older EDG front-end.

-- 


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


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

* [Bug c++/20028] [3.4 Regression] class and then template class gives an ICE
  2005-02-17 20:21 [Bug c++/20028] New: problem with protected members in template inheritance jcobyrne at cox dot net
                   ` (8 preceding siblings ...)
  2005-02-18  4:12 ` pinskia at gcc dot gnu dot org
@ 2005-02-22  0:12 ` cvs-commit at gcc dot gnu dot org
  2005-02-22  0:32 ` pinskia at gcc dot gnu dot org
  10 siblings, 0 replies; 12+ messages in thread
From: cvs-commit at gcc dot gnu dot org @ 2005-02-22  0:12 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From cvs-commit at gcc dot gnu dot org  2005-02-21 21:11 -------
Subject: Bug 20028

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-3_4-branch
Changes by:	aoliva@gcc.gnu.org	2005-02-21 21:11:51

Modified files:
	gcc/cp         : ChangeLog class.c 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/g++.dg/template: crash34.C 

Log message:
	gcc/cp/ChangeLog:
	PR c++/20028
	* class.c (finish_struct): Initialize TYPE_SIZE_UNIT of a
	template along with TYPE_SIZE.
	gcc/testsuite/ChangeLog:
	PR c++/20028
	* g++.dg/template/crash34.C: New.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.3892.2.200&r2=1.3892.2.201
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/class.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.595.4.9&r2=1.595.4.10
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.3389.2.363&r2=1.3389.2.364
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/crash34.C.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=NONE&r2=1.1.2.1



-- 


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


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

* [Bug c++/20028] [3.4 Regression] class and then template class gives an ICE
  2005-02-17 20:21 [Bug c++/20028] New: problem with protected members in template inheritance jcobyrne at cox dot net
                   ` (9 preceding siblings ...)
  2005-02-22  0:12 ` cvs-commit at gcc dot gnu dot org
@ 2005-02-22  0:32 ` pinskia at gcc dot gnu dot org
  10 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-02-22  0:32 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-02-21 21:34 -------
Fixed.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED


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


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

end of thread, other threads:[~2005-02-21 21:34 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-02-17 20:21 [Bug c++/20028] New: problem with protected members in template inheritance jcobyrne at cox dot net
2005-02-17 20:23 ` [Bug c++/20028] " jcobyrne at cox dot net
2005-02-17 22:26 ` [Bug c++/20028] [3.4/4.0 Regression] class and then template class gives an ICE pinskia at gcc dot gnu dot org
2005-02-17 23:06 ` aoliva at gcc dot gnu dot org
2005-02-17 23:20 ` cvs-commit at gcc dot gnu dot org
2005-02-17 23:50 ` [Bug c++/20028] [3.4 " pinskia at gcc dot gnu dot org
2005-02-18  1:36 ` jcobyrne at cox dot net
2005-02-18  2:59 ` pinskia at gcc dot gnu dot org
2005-02-18  3:22 ` jcobyrne at cox dot net
2005-02-18  4:12 ` pinskia at gcc dot gnu dot org
2005-02-22  0:12 ` cvs-commit at gcc dot gnu dot org
2005-02-22  0:32 ` pinskia 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).