Bug 14777 - [4.3/4.4/ Regression] typedef doesn't fully expose base class type
Summary: [4.3/4.4/ Regression] typedef doesn't fully expose base class type
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 3.4.0
: P5 normal
Target Milestone: 4.5.0
Assignee: Not yet assigned to anyone
URL:
Keywords: accepts-invalid
Depends on:
Blocks:
 
Reported: 2004-03-29 21:09 UTC by Martin Dorey
Modified: 2009-11-23 15:40 UTC (History)
5 users (show)

See Also:
Host:
Target:
Build:
Known to work: 3.3.4
Known to fail: 3.4.0 4.0.0 4.0.4 2.95.3 4.1.0
Last reconfirmed: 2009-11-13 10:37:17


Attachments
Fix candidate (1.81 KB, patch)
2009-11-16 21:35 UTC, Dodji Seketeli
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Dorey 2004-03-29 21:09:37 UTC
template <typename T>
struct B
{
protected:
  typedef int M;
};

template <typename T>
struct A : B<T> {
  typedef typename B<T>::M N;
  A (int = N ());
};

A<int> a = A<int> ();

Produces:

Connection.cpp:5: error: `typedef int B<int>::M' is protected
Connection.cpp:14: error: within this context

With recent snapshots (eg gcc 3.4.0 20040324 - can send full version guff if it
wouldn't just be more clutter for you to read).  Sorry, that's as simple as I
managed to make the example - I did try everything I could think of to simplify
it further.

Interestingly, or perhaps not, this does compile when I think it shouldn't. 
It's the same thing except for char instead of int in the typedef for N.

template <typename T>
struct B
{
protected:
  typedef int M;
};

template <typename T>
struct A : B<T> {
  typedef typename B<char>::M N;
  A (int = N ());
};

A<int> a = A<int> ();
Comment 1 Wolfgang Bangerth 2004-03-29 21:19:26 UTC
Confirmed. A regression in 3.4 and mainline. 
 
W. 
Comment 2 Mark Mitchell 2004-06-05 19:51:12 UTC
Working on a fix.
Comment 3 GCC Commits 2004-06-07 15:52:30 UTC
Subject: Bug 14777

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-3_4-branch
Changes by:	mmitchel@gcc.gnu.org	2004-06-07 15:52:23

Modified files:
	gcc            : ChangeLog c-common.c 
	gcc/cp         : ChangeLog except.c parser.c pt.c 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/g++.dg/eh: throw1.C 
	gcc/testsuite/g++.dg/expr: sizeof3.C 
	gcc/testsuite/g++.dg/template: access14.C enum1.C 

Log message:
	PR c++/15337
	* error.c (c_sizeof_or_alignof_type): Use more detailed error
	message.
	
	PR c++/15766
	* parser.c (cp_parser_iteration_statement): Fix typo in error
	message.
	
	PR c++/14777
	* pt.c (tsubst_default_argument): Do not defer access checks
	while substituting into the default argument.
	
	PR c++/15554
	* pt.c (tsubst_copy): Do not try to substitute for an enumeration
	constant in a non-dependent context.
	
	PR c++/15057
	* except.c (build_throw): Ensure that temp_expr has been
	initialized.
	
	PR c++/15337
	* g++.dg/expr/sizeof3.C: New test.
	
	PR c++/14777
	* g++.dg/template/access14.C: New test.
	
	PR c++/15554
	* g++.dg/template/enum1.C: New test.
	
	PR c++/15057
	* g++.dg/eh/throw1.C: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=2.2326.2.470&r2=2.2326.2.471
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/c-common.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.476.4.6&r2=1.476.4.7
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.115&r2=1.3892.2.116
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/except.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.164.4.4&r2=1.164.4.5
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/parser.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.157.2.31&r2=1.157.2.32
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/pt.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.816.2.28&r2=1.816.2.29
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.197&r2=1.3389.2.198
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/eh/throw1.C.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=NONE&r2=1.1.2.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/expr/sizeof3.C.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=NONE&r2=1.1.2.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/access14.C.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=NONE&r2=1.1.2.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/enum1.C.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=NONE&r2=1.1.2.1

Comment 4 GCC Commits 2004-06-07 15:54:22 UTC
Subject: Bug 14777

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	mmitchel@gcc.gnu.org	2004-06-07 15:54:15

Modified files:
	gcc            : ChangeLog c-common.c 
	gcc/cp         : ChangeLog except.c parser.c pt.c 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/g++.dg/eh: throw1.C 
	gcc/testsuite/g++.dg/expr: sizeof3.C 
	gcc/testsuite/g++.dg/template: access14.C enum1.C 

Log message:
	PR c++/15337
	* error.c (c_sizeof_or_alignof_type): Use more detailed error
	message.
	
	PR c++/15766
	* parser.c (cp_parser_iteration_statement): Fix typo in error
	message.
	
	PR c++/14777
	* pt.c (tsubst_default_argument): Do not defer access checks
	while substituting into the default argument.
	
	PR c++/15554
	* pt.c (tsubst_copy): Do not try to substitute for an enumeration
	constant in a non-dependent context.
	
	PR c++/15057
	* except.c (build_throw): Ensure that temp_expr has been
	initialized.
	
	PR c++/15337
	* g++.dg/expr/sizeof3.C: New test.
	
	PR c++/14777
	* g++.dg/template/access14.C: New test.
	
	PR c++/15554
	* g++.dg/template/enum1.C: New test.
	
	PR c++/15057
	* g++.dg/eh/throw1.C: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.3859&r2=2.3860
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/c-common.c.diff?cvsroot=gcc&r1=1.509&r2=1.510
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&r1=1.4083&r2=1.4084
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/except.c.diff?cvsroot=gcc&r1=1.167&r2=1.168
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/parser.c.diff?cvsroot=gcc&r1=1.200&r2=1.201
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/pt.c.diff?cvsroot=gcc&r1=1.859&r2=1.860
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.3816&r2=1.3817
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/eh/throw1.C.diff?cvsroot=gcc&r1=1.1&r2=1.2
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/expr/sizeof3.C.diff?cvsroot=gcc&r1=1.1&r2=1.2
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/access14.C.diff?cvsroot=gcc&r1=1.1&r2=1.2
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/enum1.C.diff?cvsroot=gcc&r1=1.1&r2=1.2

Comment 5 Mark Mitchell 2004-06-07 16:24:20 UTC
The first example has been fixed in 3.4.1.

The second example is an accepts-invalid and may not be a regression.  In any
case, it's going to be hard to fix -- the language actually required that you
*both* resolve the typename at template-declaration time, and remember the
spelling of the name so that you can do acccess-checks at template-instantiation
time.  That's not something for which we currently have data structures.  So,
I'm removing the target milestone for this PR.
Comment 6 Andrew Pinski 2005-03-09 04:45:37 UTC
(In reply to comment #5)
> The first example has been fixed in 3.4.1.
> 
> The second example is an accepts-invalid and may not be a regression. 
It is a regression from 3.3.3 and 3.2.3.

Comment 7 Andrew Pinski 2005-07-22 21:12:28 UTC
Moving to 4.0.2 pre Mark.
Comment 8 Mark Mitchell 2005-10-30 22:16:22 UTC
We need new infrastructure to fix accepts-invalid access-control issues in templates.

I removed the target milestone on this PR once before, but Andrew Pinksi put it back.  Now, I've downgraded this to P5.  

Comment 9 Gabriel Dos Reis 2007-01-18 02:52:23 UTC
Not to be fixed in GCC-4.0.x
Comment 10 Joseph S. Myers 2008-07-04 16:30:30 UTC
Closing 4.1 branch.
Comment 11 Joseph S. Myers 2009-03-31 16:16:36 UTC
Closing 4.2 branch.
Comment 12 Richard Biener 2009-08-04 12:26:00 UTC
GCC 4.3.4 is being released, adjusting target milestone.
Comment 13 Jason Merrill 2009-11-13 05:41:02 UTC
I'm assuming Mark isn't actually working on this bug.

Dodji, this looks like something that the template typedef access control code you added for 4.5 could deal with, want to take a look?
Comment 14 dodji@seketeli.org 2009-11-13 07:55:34 UTC
Subject: Re:  [4.3/4.4/4.5 Regression] typedef doesn't fully
	expose base class type

> Dodji, this looks like something that the template typedef access control code
> you added for 4.5 could deal with, want to take a look?

Sure, I'll look at it.
Thanks.
Comment 15 Mark Mitchell 2009-11-13 15:07:49 UTC
Subject: Re:  [4.3/4.4/4.5 Regression] typedef doesn't fully
 expose base class type

jason at gcc dot gnu dot org wrote:
> I'm assuming Mark isn't actually working on this bug.

Sad, but true.

Comment 16 Dodji Seketeli 2009-11-16 21:35:36 UTC
Created attachment 19025 [details]
Fix candidate

I am testing this patch ...
Comment 17 dodji@seketeli.org 2009-11-16 22:13:00 UTC
Subject: Re:  [4.3/4.4/4.5 Regression] typedef doesn't fully
	expose base class type

Patch sent to http://gcc.gnu.org/ml/gcc-patches/2009-11/msg00813.html

Comment 18 Dodji Seketeli 2009-11-23 13:30:10 UTC
Subject: Bug 14777

Author: dodji
Date: Mon Nov 23 13:29:50 2009
New Revision: 154443

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=154443
Log:
Fix PR c++/14777

gcc/cp/ChangeLog:

	PR c++/14777
	* cp-tree.def <TEMPLATE_INFO>: Declare new kind of tree
	node.
	* cp-tree.h (struct tree_template_info,
	struct qualified_typedef_usage_s): New.
	(cp_tree_node_structure_enum): add TS_CP_TEMPLATE_INFO.
	(union lang_tree_node): Add template_info.
	(TI_TEMPLATE, TI_ARGS, TI_TYPEDEFS_NEEDING_ACCESS_CHECKING):
	Adjust.
	(build_template_info): Declare.
	(get_types_needing_access_check): Adjust return type.
	(add_typedef_to_current_template_for_access_check): Declare.
	* cp-objcp-common.c (cp_tree_size): Handle TEMPLATE_INFO.
	* semantics.c (add_typedef_to_current_template_for_access_check):
	Split from ...
	(check_accessibility_of_qualified_id): ... here.
	* decl.c (make_typename_type): Use it.
	* pt.c (build_template_info): Define.
	(check_explicit_specialization, find_parameter_packs_r,
	push_template_decl_real, lookup_template_class,
	for_each_template_parm_r, tsubst_decl, tsubst): Use
	build_template_info.
	(get_types_needing_access_check): Adjust return type.
	(append_type_to_template_for_access_check_1): Record the
	location of the usage point of the typedef. Adjust to TEMPLATE_INFO.
	(append_type_to_template_for_access_check): Add new location
	parameter. Pass it to append_type_to_template_for_access_check_1.
	Adjust to TEMPLATE_INFO.
	(perform_typedefs_access_check): Temporarily set input_location to
	the usage point of the typedef we are checking access for. Adjust
	to new TEMPLATE_INFO tree node.
	* tree.c (bind_template_template_parm): Use build_template_info.
	* call.c (add_template_candidate_real): Likewise.
	* decl.c (grokfndecl): Likewise.
	(cp_tree_node_structure): Handle TEMPLATE_INFO.

gcc/testsuite/ChangeLog:

	PR c++/14777
	* g++.dg/template/typedef13.C: Adjust.
	* g++.dg/template/typedef19.C: Adjust.
	* g++.dg/template/typedef20.C: Adjust.
	* g++.dg/template/typedef22.C: New test.

Added:
    trunk/gcc/testsuite/g++.dg/template/typedef22.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/call.c
    trunk/gcc/cp/cp-objcp-common.c
    trunk/gcc/cp/cp-tree.def
    trunk/gcc/cp/cp-tree.h
    trunk/gcc/cp/decl.c
    trunk/gcc/cp/pt.c
    trunk/gcc/cp/semantics.c
    trunk/gcc/cp/tree.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/g++.dg/template/typedef13.C
    trunk/gcc/testsuite/g++.dg/template/typedef19.C
    trunk/gcc/testsuite/g++.dg/template/typedef20.C

Comment 19 Dodji Seketeli 2009-11-23 13:44:40 UTC
This should be fixed in 4.5. Adjusting the Regression tag.
Not planning to fix in 4.3/44.
Comment 20 Jason Merrill 2009-11-23 15:40:49 UTC
If you don't think it's worth fixing on the older branches, the right thing to do is set the Target Milestone to the release where it will be fixed, and then close the bug as fixed.