Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upInvalid C++ code being generated #5994
Comments
|
@hughsando that was pretty easy to reduce: class Main {
static function main() {
cpp.Pointer.fromRaw(cpp.Pointer.addressOf(null).rawCast());
}
}generates HXLINE( 3) ::cpp::Pointer_obj::fromRaw(::cpp::Pointer_obj::addressOf(null())->rawCast());which fails with
|
|
I think this should be a compile-time error, since addressOf requires a
reference - which 'null' is not.
Logically, once you have the address of null, you should be able to set to
to something else - which is not going to work.
Coding this in the compiler is tricky because a lot of the use for this
comes from externs, and you can't really trust the external types as
described.
I could explicitly check for the 'null' constant passed to reference - but
I suspect there will be other cases too.
…On Sat, Feb 4, 2017 at 9:14 AM, Dan Korostelev ***@***.***> wrote:
@hughsando <https://github.com/hughsando> that was pretty easy to reduce:
class Main {
static function main() {
cpp.Pointer.fromRaw(cpp.Pointer.addressOf(null).rawCast());
}
}
generates
HXLINE( 3) ::cpp::Pointer_obj::fromRaw(::cpp::Pointer_obj::addressOf(null())->rawCast());
which fails with
./src/Main.cpp(29): error C2672: 'cpp::Pointer_obj::fromRaw': no matching overloaded function found
./src/Main.cpp(29): error C2784: 'cpp::Pointer<T> cpp::Pointer_obj::fromRaw(const T *)': could not deduce template argument for 'const T *' from 'cpp::RawAutoCast'
d:/code/haxe/lib/hxcpp/git/include\cpp/Pointer.h(527): note: see declaration of 'cpp::Pointer_obj::fromRaw'
./src/Main.cpp(29): error C2784: 'cpp::Pointer<T> cpp::Pointer_obj::fromRaw(T *)': could not deduce template argument for 'T *' from 'cpp::RawAutoCast'
d:/code/haxe/lib/hxcpp/git/include\cpp/Pointer.h(525): note: see declaration of 'cpp::Pointer_obj::fromRaw'
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#5994 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABlp1hQNy-zr_giW--R3tTdmdE5dheuaks5rY9D3gaJpZM4L1yw2>
.
|
|
Hmm, it wasn't |
|
Sorry for not getting back sooner. I updated to git version of hxcpp, and now I get more weird results. First with the exact same repo I linked in first post:
Generated code in
I tried to isolate the problem as @nadako did, but I'm not certain if it's equivalent as the error is a little different this time: class Foo
{
public function new() {}
public var bar = 15;
}
class Main
{
static function main()
{
var tmp = new Foo();
var foo = cpp.Pointer.fromRaw(cpp.Pointer.addressOf(tmp).rawCast()).get_value();
trace(foo);
}
}Error while compiling
CPP code generated:
Thank you |
|
The problem here is that the "rawCast" converts the pointer to a "void *", and there is nothing then to tell hxcpp what the type should be, ie that it should be a Foo *. The when you go back fromRaw and get a value, you end up with a void. To work around this, you can add explicit casts, or assign to a typed variable class Test
{
static function main()
{
var tmp = new Foo();
var foo:cpp.Pointer<Foo> = cpp.Pointer.fromRaw(cpp.Pointer.addressOf(tmp).rawCast());
trace(foo.value);
}
} |
|
@hughsando Thanks for snippet! |
Again, really sorry for not being able to reproduce minimal viable case - I can't isolate just the failing code without library I'm using. The code compiles fine on haxe 3.2, and returns weird errors for 3.4. (not haxe ones, but C++ - should this be reported in hxcpp instead?)
https://github.com/Misiur/haxe34crasher - requires "ecx" library.