Mercurial > ~dholland > hg > ag > index.cgi
view tests/agcl/bugs/wraperror.syn @ 6:607e3be6bad8
Adjust to the moving target called the C++ standard.
Apparently nowadays it's not allowed to define an explicit copy
constructor but not an assignment operator. Consequently, defining the
explicit copy constructor in terms of the implicit/automatic
assignment operator for general convenience no longer works.
Add assignment operators.
Caution: not tested with the IBM compiler, but there's no particular
reason it shouldn't work.
author | David A. Holland |
---|---|
date | Mon, 30 May 2022 23:46:22 -0400 |
parents | 13d2b8934445 |
children |
line wrap: on
line source
{ /* * AnaGram, A System for Syntax Directed Programming * Copyright 2006 David A. Holland. All Rights Reserved. * See the file COPYING for license and usage terms. * * wraperror: test for wrappers and error token together */ #include <stdio.h> struct thingy { const char *name; int val; void g(const char *n, int v) { name = n; val = v; } void g(const thingy &t) { name = t.name; val = t.val; } void m(const char *msg) { printf("%s %s: %p, %d\n", msg, name, this, val); } thingy(const char *n, int v) { g(n,v); m("Constructed new"); } thingy(const thingy &t) { g(t); m("Copied"); } void operator = (const thingy &t) { g(t); m("Assigned"); } ~thingy() { m("Destroyed"); } }; struct foo : public thingy { foo(int v) : thingy("foo", v) {} foo(const foo &f) : thingy(f) {} void operator = (const foo &f) { thingy::operator = (f); } ~foo() {} }; struct bar : public thingy { bar(int v) : thingy("bar", v) {} bar(const bar &f) : thingy(f) {} void operator = (const bar &f) { thingy::operator = (f); } ~bar() {} }; void do_foo(foo &f) { f.m("do_foo"); } void do_bar(bar &b) { b.m("do_bar"); } } [ parser file name = "#.cpp" wrapper { foo } ] file $ -> declarations, eof declarations -> declaration... declaration -> foo decl:f, '\n' = do_foo(f); -> bar decl:b, '\n' = do_bar(b); -> '\n' -> error (foo) foo decl -> 'f', 'o', 'o' = foo(1); (bar) bar decl -> 'b', 'a', 'r' = bar(2); eof = 0 { int main() { wraperror(); return 0; } }