[Issue 7182] New: Call const or immutable member functions from class invariant
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu Dec 29 06:17:46 PST 2011
http://d.puremagic.com/issues/show_bug.cgi?id=7182
Summary: Call const or immutable member functions from class
invariant
Product: D
Version: D2
Platform: Other
OS/Version: All
Status: NEW
Severity: normal
Priority: P2
Component: DMD
AssignedTo: nobody at puremagic.com
ReportedBy: full.demon at gmail.com
--- Comment #0 from Taco <full.demon at gmail.com> 2011-12-29 06:17:44 PST ---
The following code yields an error:
class A
{
public:
int f() const
{
return 5;
}
protected:
invariant()
{
assert (f() == 5);
}
}
"Error: cannot call public/export function f from invariant"
Why? f() is const and cannot change the state of an instance of A. Invariant
checks are redundant around const/immutable public member functions.
What if 'this' was passed to the member function?
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list