Topic: Local classes should have external linkage (for templates...)


Author: anthony_w.geo@yahoo.com (Anthony Williams)
Date: Sat, 3 Jul 2004 01:22:36 +0000 (UTC)
Raw View
David Abrahams <dave@boost-consulting.com> writes:

> John Doe <johndoe@nowhere.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
(http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2003/n1427.pdf)?

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                       ]





Author: dave@boost-consulting.com (David Abrahams)
Date: Sat, 3 Jul 2004 19:17:13 +0000 (UTC)
Raw View
anthony_w.geo@yahoo.com (Anthony Williams) writes:

>> 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
> (http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2003/n1427.pdf)?
>
> 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...

> 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                       ]





Author: John Doe <johndoe@nowhere.com>
Date: Thu, 1 Jul 2004 12:15:41 CST
Raw View
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                       ]





Author: David Abrahams <dave@boost-consulting.com>
Date: 2 Jul 2004 05:45:05 GMT
Raw View
John Doe <johndoe@nowhere.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.

--
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                       ]





Author: Alberto Barbati <AlbertoBarbati@libero.it>
Date: 2 Jul 2004 05:45:12 GMT
Raw View
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.

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.

> 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                       ]





Author: llewelly <llewelly.at@xmission.dot.com>
Date: Fri, 2 Jul 2004 05:24:15 CST
Raw View
Alberto Barbati <AlbertoBarbati@libero.it> writes:

> 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?


> 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.

>
> 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                       ]





Author: "Ken Hagan" <K.Hagan@thermoteknix.co.uk>
Date: Fri, 2 Jul 2004 05:24:25 CST
Raw View
On 2 Jul 2004 05:45:12 GMT, Alberto Barbati <AlbertoBarbati@libero.it>
wrote:

> 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.

> 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                       ]