[comp.lang.c++] static local with ctor

eppstein@garfield.columbia.edu (David Eppstein) (06/01/87)

The version of cfront here won't let me write functions which have
local static variables of a class having a constructor.  This seems an
unreasonable restriction to me.  Also it contradicts page 158 of The
Book which explicitly discusses static locals with constructors
(exegesis I know but I couldn't find anything in the actual
Reference Manual to contradict it).

If the problem is that the initialization code needs to be able to see
the scope of the variable it's initializing, it should be easy enough
for cfront to translate the variable to a static global with a new name
which it can guarantee is not used by anyone inappropriate.  If there's
some harder problem I don't see, I would be happy if someone could
enlighten me; but I tend to doubt it because cfront happily accepts
static globals which should be except for visibility exactly the same.

As a concrete example, I get the error message
  line 9: sorry, not implemented: local static z of class with constructor
when I run C++ on the following code.
            ------------
class foo {
    int x;
 public:
    foo(int y) { x = y; }
};

bar() {
    static foo z(0);
}
-- 
David Eppstein, eppstein@cs.columbia.edu, Columbia U. Computer Science Dept.