Bug 13262 - [3.3/3.4 regression] "xxx is private within this context" when initializing a *self-contained* template class
Summary: [3.3/3.4 regression] "xxx is private within this context" when initializing a...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 3.3.2
: P2 normal
Target Milestone: 3.3.3
Assignee: Kriang Lerdsuwanakij
URL:
Keywords: patch, rejects-valid
Depends on:
Blocks:
 
Reported: 2003-12-01 17:02 UTC by Francesco Monica
Modified: 2004-01-17 04:22 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2003-12-01 20:57:21


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Francesco Monica 2003-12-01 17:02:56 UTC
This code will compile successful with gcc <= 3.2.3 but doesn't work with gcc 
3.3.1 or 3.3.2: 
----------------------------------------------------- 
template < typename T > 
class Aclass 
  { 
  private: 
    Aclass() {} 
    static Aclass instance; 
  }; 
 
template < typename T > Aclass<T> Aclass<T>::instance; 
 
 
template class Aclass<int>; 
----------------------------------------------------- 
 
The gcc compiler emits an error like this: 
test.cc: In instantiation of `Aclass<int> Aclass<int>::instance': 
test.cc:12:   instantiated from here 
test.cc:5: error: `Aclass<T>::Aclass() [with T = int]' is private 
test.cc:9: error: within this context 
 
This code also works if an explicit instantiation of "instance" is added 
before the last line: 
Aclass<int> Aclass<int>::instance; 
 
That strategy (self contained class with private ctor) will be useful to build 
pattern like "Singleton", proposed by GoF. Of course there are some other ways 
to do this :-) 
 
I'm in doublt, but I think the code should be correct...
Comment 1 Wolfgang Bangerth 2003-12-01 20:57:20 UTC
Confirmed. Kriang, you are the friendship expert: I am not quite sure
what the standard says, but the present behavior doesn't really
make much sense. What do you think?

W.
Comment 2 Andrew Pinski 2003-12-02 00:45:08 UTC
From Phil's regression hunter: Search converges between 2003-05-15-trunk (#296) and 2003-05
-29-trunk (#297).
Comment 3 Andrew Pinski 2003-12-02 00:51:50 UTC
I should say that date that I just referenced is for the mainline being broken again (it was fixed at 
one point between the time 3.3 branched and that date: Search converges between 2003-02-25-
trunk (#231) and 2003-02-26-trunk (#232).).

It also was broken before the branch: Search converges between 2002-10-11-trunk (#101) and 
2002-10-12-trunk (#102).

It was never fixed on the 3.3 branch though.
Comment 4 Kriang Lerdsuwanakij 2003-12-05 12:09:19 UTC
Yup, this should compile.  Somewhere in deferred access checking code is broken.
Comment 5 Kriang Lerdsuwanakij 2003-12-15 12:23:13 UTC
Patch waiting for approval for 3.4 version:

  http://gcc.gnu.org/ml/gcc-patches/2003-12/msg01198.html

and 3.3.3:

  http://gcc.gnu.org/ml/gcc-patches/2003-12/msg01199.html
Comment 6 CVS Commits 2003-12-18 14:14:53 UTC
Subject: Bug 13262

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	lerdsuwa@gcc.gnu.org	2003-12-18 14:14:48

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

Log message:
	PR c++/13262
	* pt.c (instantiate_decl): Wrap push_nested_class and
	pop_nested_class around cp_finish_decl call for static member
	variable.
	
	* g++.dg/template/access13.C: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&r1=1.3818&r2=1.3819
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/pt.c.diff?cvsroot=gcc&r1=1.803&r2=1.804
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.3280&r2=1.3281
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/access13.C.diff?cvsroot=gcc&r1=NONE&r2=1.1

Comment 7 CVS Commits 2003-12-18 14:27:51 UTC
Subject: Bug 13262

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-3_3-branch
Changes by:	lerdsuwa@gcc.gnu.org	2003-12-18 14:27:49

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

Log message:
	PR c++/13262
	* pt.c (instantiate_decl): Wrap push_nested_class and
	pop_nested_class around cp_finish_decl call for static member
	variable.
	
	* g++.dg/template/access13.C: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.3076.2.222&r2=1.3076.2.223
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/pt.c.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.635.2.38&r2=1.635.2.39
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.2261.2.337&r2=1.2261.2.338
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/access13.C.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=NONE&r2=1.1.2.1

Comment 8 Kriang Lerdsuwanakij 2003-12-18 14:31:17 UTC
Fixed in 3.3 and 3.4 branches.