This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/29470] New: Using declaration access semantics change with templates
- From: "spam at david dot osborn dot name" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 14 Oct 2006 18:55:09 -0000
- Subject: [Bug c++/29470] New: Using declaration access semantics change with templates
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
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;
}
--
Summary: Using declaration access semantics change with templates
Product: gcc
Version: 4.1.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: spam at david dot osborn dot name
GCC build triplet: i686-pc-mingw32
GCC host triplet: i686-pc-mingw32
GCC target triplet: i686-pc-mingw32
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29470