--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposal...@isocpp.org.
To post to this group, send email to std-pr...@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
Maybe not intuitive, but this is by design. For performance reasons, the compiler needs to know the layout of a struct, and it can only do that if the definition is visible. Any workarounds require an indirection AFAIK, as does implementing this as standard behavior. If you want hiding and abi compatibility use the PIMPL idiom for private data. But realize that it adds an extra indirection.-Tim
--
I'm not sure whether a restriction should be made to only allow private nonvirtual functions outside the class definition -- a rule could be added that the class layout may not be different for any nonzero number of virtual functions, and the compiler could signal an error if a virtual function is to be added to a class whose definition doesn't contain any virtual functions.
On segunda-feira, 4 de novembro de 2013 03:09:00, Philipp Stephani wrote:No, they cannot.
> 2013/11/4 Philipp Stephani <p.ste...@gmail.com>
>
> > I'm not sure whether a restriction should be made to only allow private
> > nonvirtual functions outside the class definition -- a rule could be added
> > that the class layout may not be different for any nonzero number of
> > virtual functions, and the compiler could signal an error if a virtual
> > function is to be added to a class whose definition doesn't contain any
> > virtual functions.
>
> This is wrong: As already pointed out by the OP, all virtual functions can
> be overridden and are therefore part of the interface, regardless of their
> visibility.
Overriding a virtual function may change the ABI. *Any* virtual declaration
must be visible to all callers.
On segunda-feira, 4 de novembro de 2013 06:02:39, Ville Voutilainen wrote:Ok, after rereading what I posted, looks like I might not have answered the
> They cannot? As in, virtual functions cannot be overridden? Are you thinking
> about final here?
>
>
> > Overriding a virtual function may change the ABI. *Any* virtual
> > declaration
> > must be visible to all callers.
> Same question, I guess.
right post. So let me start over:
This thread is about adding methods to a class without having it in the main
class { } body, which is visible to all users. I support that idea.
However, that must be entirely restricted to non-virtual methods.
Adding a virtual method, like everyone who has done any binary compatibility
work knows, is not possible. That includes overrides. Any and all virtual
methods present in a given class -- whether new or overrides -- must be
declared in the class body and visible to all users.
On segunda-feira, 4 de novembro de 2013 06:41:12, Ville Voutilainen wrote:See these two exceptions to overriding virtuals
> I still have trouble grokking the "that includes overrides" part. How does
> adding an override change the ABI?
http://techbase.kde.org/Policies/Binary_Compatibility_Examples#Override_a_virtual_with_a_covariant_return_with_different_top_address
http://techbase.kde.org/Policies/Binary_Compatibility_Examples#Override_a_virtual_that_doesn.27t_come_from_a_primary_base
These two overrides are actually new virtuals in disguise under the portable
IA-64 C++ ABI used by GCC and Clang. Since those two cases are possible, we
have to take into consideration the possibility that other overrides are
actually new virtuals under other ABIs.
That means we must treat all overrides as if they were new virtuals for the
purpose of defining the standard.
--
Private member *data* does need to be declared in the class definition so that callers know what size to lay out for the object. Private member *functions* do not.
On Monday, November 4, 2013 2:05:15 AM UTC+1, Billy O'Neal wrote:Private member *data* does need to be declared in the class definition so that callers know what size to lay out for the object. Private member *functions* do not.Not entirely true. In general, callers don't need to know the layout. The layout is (only?) required when accessing data members, the size is only required when creating an object on the stack.
Not requiring private data members in the header would be nice too IMO.
Hello,I've been thinking about a new proposal for a "class implementation namespace", where I initially thought to only allow member function implementations that were already declared, but reading this proposal I realized that allowing new private member function declarations would solve your problem. It would look something like this using your example://foo.hhclass Foo {
public:void doWork();private:int _f;}//foo.cc:class Foo namespace {
--
On Mon, Nov 4, 2013 at 1:01 PM, Richard Smith <ric...@metafoo.co.uk> wrote:I don't think so. This scope, afaics, is private, with contents safe
>> //foo.cc:
>>
>> class Foo namespace {
>
>
> "class X namespace" looks a lot like "allow me to violate access control
> here, please".
to be added without changing the ABI.
On Mon, Nov 4, 2013 at 12:36 PM, Zhihao Yuan <z...@miator.net> wrote:On Mon, Nov 4, 2013 at 1:01 PM, Richard Smith <ric...@metafoo.co.uk> wrote:I don't think so. This scope, afaics, is private, with contents safe
>> //foo.cc:
>>
>> class Foo namespace {
>
>
> "class X namespace" looks a lot like "allow me to violate access control
> here, please".
to be added without changing the ABI.If you can add friends to a 'class namespace', you can trivially use it to violate access control (and get access to private members from some third party TU). You can get the same effect even without allowing friends in a 'class namespace', but you need to work a little harder. For instance:struct Launderer {virtual int get(Foo *p) = 0;} *launderer;class Foo namespace {struct FooLaunderer : Launderer {FooLaunderer() { launderer = this; }int get(Foo *p) { return p->_f; }} static theLaunderer;}