Bug 29470 - [4.2/4.3/4.4 Regression] Using declaration access semantics change with templates
Summary: [4.2/4.3/4.4 Regression] Using declaration access semantics change with templ...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.1.1
: P2 normal
Target Milestone: 4.2.5
Assignee: Jason Merrill
URL:
Keywords: accepts-invalid
Depends on:
Blocks:
 
Reported: 2006-10-14 18:55 UTC by David Osborn
Modified: 2009-01-16 22:46 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work: 4.0.4
Known to fail: 4.1.2 4.2.0 4.1.1
Last reconfirmed: 2009-01-16 20:05:23


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description David Osborn 2006-10-14 18:55:09 UTC
In the following class template, the protected using declaration causes the inherited member to become publicly accessible.  The code compiles, even though it shouldn't.

template <typename T> struct B
{
	protected:
	T v;
};
template <typename T> struct D : B<T>
{
	protected:
	using B<T>::v;
};
int main()
{
	D<int> d;
	d.v = 0;
	return 0;
}

$ g++ test.cpp

The same code without templates gives the correct behaviour and doesn't compile.

struct B
{
	protected:
	int v;
};
struct D : B
{
	protected:
	using B::v;
};
int main()
{
	D d;
	d.v = 0;
	return 0;
}

$ g++ test.cpp
test.cpp: In function 'int main()':
test.cpp:4: error: 'int B::v' is protected
test.cpp:14: error: within this context

The preprocessed file from the template version is as follows:

# 1 "test.cpp"
# 1 "<built-in>"
# 1 "<command line>"
# 1 "test.cpp"
template <typename T> struct B
{
 protected:
 T v;
};

template <typename T> struct D : B<T>
{
 protected:
 using B<T>::v;
};

int main()
{
 D<int> d;
 d.v = 0;
 return 0;
}
Comment 1 Andrew Pinski 2006-10-14 19:02:48 UTC
Confirmed, a regression from 4.0.4.
Comment 2 Janis Johnson 2006-10-16 23:49:46 UTC
A regression hunt identified the following patch:

    http://gcc.gnu.org/viewcvs?view=rev&rev=100757

    r100757 | nathan | 2005-06-08 11:49:23 +0000 (Wed, 08 Jun 2005)
Comment 3 Joseph S. Myers 2008-07-04 21:38:13 UTC
Closing 4.1 branch.
Comment 4 Jason Merrill 2009-01-16 22:36:26 UTC
Subject: Bug 29470

Author: jason
Date: Fri Jan 16 22:36:11 2009
New Revision: 143445

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=143445
Log:
        PR c++/29470
        * pt.c (tsubst_decl) [USING_DECL]: Propagate access flags.

Added:
    trunk/gcc/testsuite/g++.dg/template/access20.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/pt.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/g++.dg/torture/pr34641.C

Comment 5 Jason Merrill 2009-01-16 22:46:32 UTC
Fixed for 4.4, not fixing accepts-invalid on other branches.