public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* G++ switch to make everything public in a class?
@ 2011-07-31 18:36 Jeffrey Walton
  2011-07-31 18:40 ` Ian Lance Taylor
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Jeffrey Walton @ 2011-07-31 18:36 UTC (permalink / raw)
  To: GCC Users List

Hi All,

I'm interested in writing test cases against c++ classes. For testing,
I'd like everything to be public so I can call protected and private
functions with bad data for negative test cases.

I don't want to use friendship since its for testing only (it would
pollute the interfaces).

Is there a switch to force everything public? If not, how does one
typically access the non-public stuff for testing?

Jeff

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: G++ switch to make everything public in a class?
  2011-07-31 18:36 G++ switch to make everything public in a class? Jeffrey Walton
@ 2011-07-31 18:40 ` Ian Lance Taylor
  2011-07-31 18:51   ` Jeffrey Walton
  2011-07-31 18:58 ` Magnus Müller
  2011-07-31 20:15 ` Kalle Olavi Niemitalo
  2 siblings, 1 reply; 9+ messages in thread
From: Ian Lance Taylor @ 2011-07-31 18:40 UTC (permalink / raw)
  To: noloader; +Cc: GCC Users List

Jeffrey Walton <noloader@gmail.com> writes:

> Is there a switch to force everything public?

-Dprivate=public -Dprotected=public

> If not, how does one
> typically access the non-public stuff for testing?

There are a variety of techniques, but this is really a general C++
question, not a gcc question.  E.g., search for "c++ testing private
methods".

Ian

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: G++ switch to make everything public in a class?
  2011-07-31 18:40 ` Ian Lance Taylor
@ 2011-07-31 18:51   ` Jeffrey Walton
  2011-08-01  1:42     ` Ian Lance Taylor
  0 siblings, 1 reply; 9+ messages in thread
From: Jeffrey Walton @ 2011-07-31 18:51 UTC (permalink / raw)
  To: Ian Lance Taylor; +Cc: GCC Users List

On Sun, Jul 31, 2011 at 2:40 PM, Ian Lance Taylor <iant@google.com> wrote:
> Jeffrey Walton <noloader@gmail.com> writes:
>
>> Is there a switch to force everything public?
>
> -Dprivate=public -Dprotected=public
>
>> If not, how does one
>> typically access the non-public stuff for testing?
>
> There are a variety of techniques, but this is really a general C++
> question, not a gcc question.  E.g., search for "c++ testing private
> methods".
Thanks Ian. But I'm not clear on why a g++ switch is not gcc help
related. GCC does have other visibility related switches (eg,
-Wctor-dtor-privacy).

Jeff

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: G++ switch to make everything public in a class?
  2011-07-31 18:36 G++ switch to make everything public in a class? Jeffrey Walton
  2011-07-31 18:40 ` Ian Lance Taylor
@ 2011-07-31 18:58 ` Magnus Müller
  2011-07-31 20:15 ` Kalle Olavi Niemitalo
  2 siblings, 0 replies; 9+ messages in thread
From: Magnus Müller @ 2011-07-31 18:58 UTC (permalink / raw)
  To: gcc-help; +Cc: noloader

[-- Attachment #1: Type: text/plain, Size: 683 bytes --]

On Sun, 31 Jul 2011 14:35:48 -0400
Jeffrey Walton <noloader@gmail.com> wrote:

>>Hi All,
>>
>>I'm interested in writing test cases against c++ classes. For testing,
>>I'd like everything to be public so I can call protected and private
>>functions with bad data for negative test cases.
>>
>>I don't want to use friendship since its for testing only (it would
>>pollute the interfaces).
>>
>>Is there a switch to force everything public? If not, how does one
>>typically access the non-public stuff for testing?
>>
>>Jeff

Define private to be public:

	gcc -Dprivate="public"

That could produce compile time errors, but it does no harm to try it.


Magnus

[-- Attachment #2: Type: application/pgp-signature, Size: 198 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: G++ switch to make everything public in a class?
  2011-07-31 18:36 G++ switch to make everything public in a class? Jeffrey Walton
  2011-07-31 18:40 ` Ian Lance Taylor
  2011-07-31 18:58 ` Magnus Müller
@ 2011-07-31 20:15 ` Kalle Olavi Niemitalo
  2 siblings, 0 replies; 9+ messages in thread
From: Kalle Olavi Niemitalo @ 2011-07-31 20:15 UTC (permalink / raw)
  To: Jeffrey Walton; +Cc: gcc-help

Jeffrey Walton <noloader@gmail.com> writes:

> Is there a switch to force everything public?

G++ 4.4 has -fno-access-control.  I don't know about other versions.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: G++ switch to make everything public in a class?
  2011-07-31 18:51   ` Jeffrey Walton
@ 2011-08-01  1:42     ` Ian Lance Taylor
  2011-08-01 10:06       ` Jonathan Wakely
  0 siblings, 1 reply; 9+ messages in thread
From: Ian Lance Taylor @ 2011-08-01  1:42 UTC (permalink / raw)
  To: noloader; +Cc: GCC Users List

Jeffrey Walton <noloader@gmail.com> writes:

> On Sun, Jul 31, 2011 at 2:40 PM, Ian Lance Taylor <iant@google.com> wrote:
>> Jeffrey Walton <noloader@gmail.com> writes:
>>
>>> Is there a switch to force everything public?
>>
>> -Dprivate=public -Dprotected=public
>>
>>> If not, how does one
>>> typically access the non-public stuff for testing?
>>
>> There are a variety of techniques, but this is really a general C++
>> question, not a gcc question.  E.g., search for "c++ testing private
>> methods".
> Thanks Ian. But I'm not clear on why a g++ switch is not gcc help
> related. GCC does have other visibility related switches (eg,
> -Wctor-dtor-privacy).

Oh, sure, the question about a g++ option is certainly appropriate for
gcc-help, and I answered that part of the question.  Using -D options as
I proposed would be equivalent to any option specifically for this
feature, and in fact there is no other option.

Ian

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: G++ switch to make everything public in a class?
  2011-08-01  1:42     ` Ian Lance Taylor
@ 2011-08-01 10:06       ` Jonathan Wakely
  2011-08-01 10:10         ` Marc Glisse
  2011-08-01 16:25         ` Ian Lance Taylor
  0 siblings, 2 replies; 9+ messages in thread
From: Jonathan Wakely @ 2011-08-01 10:06 UTC (permalink / raw)
  To: Ian Lance Taylor; +Cc: noloader, GCC Users List

On 1 August 2011 02:42, Ian Lance Taylor wrote:
> Jeffrey Walton <noloader@gmail.com> writes:
>
>> On Sun, Jul 31, 2011 at 2:40 PM, Ian Lance Taylor <iant@google.com> wrote:
>>> Jeffrey Walton <noloader@gmail.com> writes:
>>>
>>>> Is there a switch to force everything public?
>>>
>>> -Dprivate=public -Dprotected=public

You might also need -Dclass=struct

>>>> If not, how does one
>>>> typically access the non-public stuff for testing?
>>>
>>> There are a variety of techniques, but this is really a general C++
>>> question, not a gcc question.  E.g., search for "c++ testing private
>>> methods".
>> Thanks Ian. But I'm not clear on why a g++ switch is not gcc help
>> related. GCC does have other visibility related switches (eg,
>> -Wctor-dtor-privacy).
>
> Oh, sure, the question about a g++ option is certainly appropriate for
> gcc-help, and I answered that part of the question.  Using -D options as
> I proposed would be equivalent to any option specifically for this
> feature, and in fact there is no other option.

Except -fno-access-control

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: G++ switch to make everything public in a class?
  2011-08-01 10:06       ` Jonathan Wakely
@ 2011-08-01 10:10         ` Marc Glisse
  2011-08-01 16:25         ` Ian Lance Taylor
  1 sibling, 0 replies; 9+ messages in thread
From: Marc Glisse @ 2011-08-01 10:10 UTC (permalink / raw)
  To: Jonathan Wakely; +Cc: Ian Lance Taylor, noloader, GCC Users List

On Mon, 1 Aug 2011, Jonathan Wakely wrote:

> On 1 August 2011 02:42, Ian Lance Taylor wrote:
>> Jeffrey Walton <noloader@gmail.com> writes:
>>
>>> On Sun, Jul 31, 2011 at 2:40 PM, Ian Lance Taylor <iant@google.com> wrote:
>>>> Jeffrey Walton <noloader@gmail.com> writes:
>>>>
>>>>> Is there a switch to force everything public?
>>>>
>>>> -Dprivate=public -Dprotected=public
>
> You might also need -Dclass=struct

That one never works, because of:
template<class>class X;

(yes, it's a pain to have keywords that are almost equivalent but not 
quite...)

-- 
Marc Glisse

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: G++ switch to make everything public in a class?
  2011-08-01 10:06       ` Jonathan Wakely
  2011-08-01 10:10         ` Marc Glisse
@ 2011-08-01 16:25         ` Ian Lance Taylor
  1 sibling, 0 replies; 9+ messages in thread
From: Ian Lance Taylor @ 2011-08-01 16:25 UTC (permalink / raw)
  To: Jonathan Wakely; +Cc: noloader, GCC Users List

Jonathan Wakely <jwakely.gcc@gmail.com> writes:

> Except -fno-access-control

Thanks, didn't know about that one.

Ian

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2011-08-01 16:25 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-07-31 18:36 G++ switch to make everything public in a class? Jeffrey Walton
2011-07-31 18:40 ` Ian Lance Taylor
2011-07-31 18:51   ` Jeffrey Walton
2011-08-01  1:42     ` Ian Lance Taylor
2011-08-01 10:06       ` Jonathan Wakely
2011-08-01 10:10         ` Marc Glisse
2011-08-01 16:25         ` Ian Lance Taylor
2011-07-31 18:58 ` Magnus Müller
2011-07-31 20:15 ` Kalle Olavi Niemitalo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).