 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
John Doe Guest
|
Posted: Thu Jul 01, 2004 5:20 pm Post subject: Local classes should have external linkage (for templates... |
|
|
Currently it's not allowed to do this
void foo ()
{
class foo_local { /* local class ... */ };
std::vector<foo_local> foo_local_vector; // Illegal
// use vector...
}
(snippet taken from here:
http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&safe=off&selm=akjl0u%241j8827%241%40ID-136218.news.dfncis.de
)
I really miss this feature!
I don't see any problem in adding this to the upcoming standard. The C++
name mangling should avoid every problem of making an unique name for
foo::foo_local and make it have external linkage
What are the chances (%) that in the upcoming standard the
foo::foo_local will get external linkage?
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
|
|
| Back to top |
|
 |
David Abrahams Guest
|
Posted: Fri Jul 02, 2004 5:45 am Post subject: Re: Local classes should have external linkage (for template |
|
|
John Doe <johndoe (AT) nowhere (DOT) com> writes:
| Quote: | What are the chances (%) that in the upcoming standard the
foo::foo_local will get external linkage?
|
Without someone like you who cares about it writing a proposal I'd
say they're very close to zero.
--
Dave Abrahams
Boost Consulting
http://www.boost-consulting.com
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
|
|
| Back to top |
|
 |
Alberto Barbati Guest
|
Posted: Fri Jul 02, 2004 5:45 am Post subject: Re: Local classes should have external linkage (for template |
|
|
John Doe wrote:
| Quote: | Currently it's not allowed to do this
void foo ()
{
class foo_local { /* local class ... */ };
std::vector<foo_local> foo_local_vector; // Illegal
// use vector...
}
[...]
I don't see any problem in adding this to the upcoming standard. The C++
name mangling should avoid every problem of making an unique name for
foo::foo_local and make it have external linkage
|
According to 3.5/8 foo_local has no linkage at all (not even internal
linkage). I think that asking it to have external linkage is way too much.
Anyway, there's another problem that you are not considering. As (quite
obscurely) described in 14.6.4.1/3, the point of instantiation of
std::vector<foo_local> "immediately precedes" function foo().
Unfortunately, at such point foo_local has not yet been declared! Even
if foo_local had external linkage, the instantiation could not take
place at that point.
Therefore, in order to allow the use of local classes as template
parameters, you need to change both the concepts of linkage and the
rules for template instantiation. It's not clear (at least it's not
clear to me how could they be changed and what side-effects such
changes could bring. If you want to make a study and a detailed
proposal, you're welcome.
| Quote: | What are the chances (%) that in the upcoming standard the
foo::foo_local will get external linkage?
|
I agree with you that using local classes as template parameters would
be very useful, however, I doubt we will see such a feature in the next
revision of C++, if ever.
Alberto
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
|
|
| Back to top |
|
 |
llewelly Guest
|
Posted: Fri Jul 02, 2004 11:24 am Post subject: Re: Local classes should have external linkage (for template |
|
|
Alberto Barbati <AlbertoBarbati (AT) libero (DOT) it> writes:
| Quote: | John Doe wrote:
Currently it's not allowed to do this
void foo ()
{
class foo_local { /* local class ... */ };
std::vector<foo_local> foo_local_vector; // Illegal
// use vector...
}
[...]
I don't see any problem in adding this to the upcoming standard. The
C++ name mangling should avoid every problem of making an unique
name for foo::foo_local and make it have external linkage
According to 3.5/8 foo_local has no linkage at all (not even internal
linkage). I think that asking it to have external linkage is way too
much.
|
Why do you think this?
| Quote: | Anyway, there's another problem that you are not considering. As
(quite obscurely) described in 14.6.4.1/3, the point of instantiation
of std::vector<foo_local> "immediately precedes" function
foo(). Unfortunately, at such point foo_local has not yet been
declared! Even if foo_local had external linkage, the instantiation
could not take place at that point.
|
This is a more important problem.
| Quote: |
Therefore, in order to allow the use of local classes as template
parameters, you need to change both the concepts of linkage and the
rules for template instantiation. It's not clear (at least it's not
clear to me how could they be changed and what side-effects such
changes could bring. If you want to make a study and a detailed
proposal, you're welcome.
What are the chances (%) that in the upcoming standard the
foo::foo_local will get external linkage?
I agree with you that using local classes as template parameters would
be very useful, however, I doubt we will see such a feature in the
next revision of C++, if ever.
|
There's a proposal: n1427, see http://xrl.us/cb33
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
|
|
| Back to top |
|
 |
Ken Hagan Guest
|
Posted: Fri Jul 02, 2004 11:24 am Post subject: Re: Local classes should have external linkage (for template |
|
|
On 2 Jul 2004 05:45:12 GMT, Alberto Barbati <AlbertoBarbati (AT) libero (DOT) it>
wrote:
| Quote: | Anyway, there's another problem that you are not considering. As (quite
obscurely) described in 14.6.4.1/3, the point of instantiation of
std::vector<foo_local> "immediately precedes" function foo().
Unfortunately, at such point foo_local has not yet been declared! Even
if foo_local had external linkage, the instantiation could not take
place at that point.
|
Quoting (to save others looking it up)...
Otherwise, the point of instantiation [...] immediately precedes
the namespace scope declaration or definition that refers to the
specialization.
It seems to me that the unhelpful part of this sentence is the reference
to the "namespace scope". Presumably the following code also has the
same point of instantiation...
void foo ()
{
class foo_local { /* local class ... */ };
struct Local
{
static void bar()
{
std::vector<foo_local> foo_local_vector; // Illegal
}
};
}
...and so would be illegal for the same reason.
| Quote: | Therefore, in order to allow the use of local classes as template
parameters, you need to change both the concepts of linkage and the
rules for template instantiation. It's not clear (at least it's not
clear to me how could they be changed and what side-effects such
changes could bring. If you want to make a study and a detailed
proposal, you're welcome.
|
Presumably the desired semantics are simply...
namespace unique_compiler_generated_name
{
class foo_local { /* local class ... */ };
}
void foo ()
{
using namespace unique_compiler_generated_name;
std::vector<foo_local> foo_local_vector;
}
...and the issues involved wouldn't be very different from those that
arise from the anonymous namespace.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
|
|
| Back to top |
|
 |
Anthony Williams Guest
|
Posted: Sat Jul 03, 2004 1:22 am Post subject: Re: Local classes should have external linkage (for template |
|
|
David Abrahams <dave (AT) boost-consulting (DOT) com> writes:
| Quote: | John Doe <johndoe (AT) nowhere (DOT) com> writes:
What are the chances (%) that in the upcoming standard the
foo::foo_local will get external linkage?
Without someone like you who cares about it writing a proposal I'd
say they're very close to zero.
|
You mean, like N1427 from the Pre-Oxford mailing
([url]http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2003/n1427.pdf)?[/url]
This is on the Evolution Working Group Issues List (N1598,
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2004/n1598.html) as issues
EP006 and ES043.
If you have any advice on what more can be done to get this through, that
would be welcome.
Anthony
--
Anthony Williams
Senior Software Engineer, Beran Instruments Ltd.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
|
|
| Back to top |
|
 |
David Abrahams Guest
|
Posted: Sat Jul 03, 2004 7:17 pm Post subject: Re: Local classes should have external linkage (for template |
|
|
[email]anthony_w.geo (AT) yahoo (DOT) com[/email] (Anthony Williams) writes:
| Quote: | Without someone like you who cares about it writing a proposal I'd
say they're very close to zero.
You mean, like N1427 from the Pre-Oxford mailing
([url]http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2003/n1427.pdf)?[/url]
This is on the Evolution Working Group Issues List (N1598,
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2004/n1598.html) as issues
EP006 and ES043.
|
Oh! In that case...
| Quote: | If you have any advice on what more can be done to get this through, that
would be welcome.
|
...show up at committee meetings, work with the papers' authors on
getting the proposals accepted, join the committee...
--
Dave Abrahams
Boost Consulting
http://www.boost-consulting.com
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|