Closed djrieger closed 9 years ago
In MethodDeclaration.cpp there was a similar problem, maybe this snippet helps:
// insert this method into the method table in the class table
auto ct = sa.getClassTable();
auto const foo = shared_from_this();
auto md_node = std::static_pointer_cast<const MethodDeclaration>(foo);
ct[class_name].methodTable->insertMethod(return_type_and_name->getName(), md_node, returnType, param_types);
I'm not sure if I really get the problem without the code, maybe you need different versions of printError (in regard to const-ness).
As far as I know a const(_pointer)_cast can only add or remove the const qualifier, as Max mentioned a static_pointer_cast<const ast::PositionAwareNode>
is needed. Any complaints about constness in the arguments to reportError should be fixed by declaring the offending parameter const. If the compiler can't convert from shptr<Foo>
to shptr<Foo const>
automatically, this will require const_pointer_casts in every other call to reportError however.
Just figured there's a much easier solution:
sa.reportError(.., this->getPosition());
UnaryExpressions currently set the error position tot the position of their
child
expression but it should be set tothis
(UnaryExpression.cpp, lines 100 and 138). I tried replacingchild
in"is not ..."., child);
withstd::const_pointer_cast<PositionAwareNode>(shared_from_this())
. I need a (pointer) cast since reportError() expects ashptr<PositionAwareNode>
andshared_from_this()
returns ashptr<Node>
. In fact, since the method reporting the error is declared const,shared_from_this()
returns ashptr<const Node>
. This is why I thought aconst_pointer_cast
would be correct, but the compiler simply tells me "Cast is not allowed":