Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2010-10

[patch] removing compiler warning from aasmtia.pas unit

3 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Graeme Geldenhuys

Hi,

http://mantis.freepascal.org/view.php?id=17709

Constructor is "tried" to be made private - this is not possible.

There is comments in the code about why the visibility of the constructor is private. But that is pointless, because you can't lower visibility of a constructor or any other class method, you can only raise visibility.

If the constructor is really such an issue, then an exception needs to be raised in it, and NewInstance() used to create such a class instance or something. Anyway, there are a few ways this can be done, but all the solutions I know are not very pretty (not pascal like if you will). For now the patch simply removes the warning.

Original change to private was made by Pierre somebody in r15784. ------------------------
Author: pierre
Date: Wed Aug 11 21:45:55 2010 +0000

* commit 15780 reverted

git-svn-id:
3ad0048d-3df7-0310-abae-a5850022a9f2
------------------------

Regards,   - Graeme - _______________________________________________ fpGUI - a cross-platform Free Pascal GUI toolkit http://opensoft.homeip.net:8080/fpgui/

Reply by email

Graeme Geldenhuys
to Graeme Geldenhuys

Hi,

I'd like to learn something here, so that's why I'm asking for a further explanation of this.

Jonas said in the now resolved Mantis report:
"The code is not trying to lower any visibility. The first declaration of that constructor is in tai_section itself. And making it private does make it inaccessible from other units."

I still think this is wrong. See the class class hierarchy below.

TObject
|
TLinkedListItem
|
tai
|
tai_section

TObject already defines a constructor as public. That's it, now you can lower the constructor visibility.

TLinkListItem defines public constructors.

Tai defines public constructors.

So how can tai_section

So yes, tai_section might have that "one" constructor as private, but in no way does it stop anybody from creating an instance of that class with all the inherited constructors (all being public). And in doing so, it will put that tai_section instance in an "undefined" state, because it doesn't execute the code implemented in that private constructor.

So this just seems wrong on so many levels, and the FPC compiler rightfully gives a warning about this.

Regards,
- Graeme -

Reply by email

Jonas Maebe
to Graeme Geldenhuys
Graeme Geldenhuys wrote
So yes, tai_section might have that "one" constructor as private, but in no way does it stop anybody from creating an instance of that class with all the inherited constructors (all being public).

That's correct.

And in doing so, it will put that tai_section instance in an "undefined" state, because it doesn't execute the code implemented in that private constructor.

In that case, you'll either get internalerrors soon afterwards or code that won't assemble. That is much preferable to having a tai_section that assembles fine but which behaves wrongly (which is what you can easily get if you don't use the new_section() function to create a new section).

Jonas

Reply by email