Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid JS code generated for struct [[cheerp::jsexport]], but not for class #89

Closed
yeputons opened this issue Jul 2, 2019 · 2 comments

Comments

@yeputons
Copy link

yeputons commented Jul 2, 2019

Example code:

struct [[cheerp::jsexport]] Foo {
public:
    int a;
    Foo(int x) : a(x) {}
};

void webMain() {
    new Foo(10);
}

With "C:\cheerp\bin\clang++.exe" -target cheerp -cheerp-pretty-code -O0 a.cpp it's compiled to:

"use strict";
/*Compiled using Cheerp (R) by Leaning Technologies Ltd*/
var __imul=Math.imul;
var __fround=Math.fround;
var oSlot=0;var nullArray=[null];var nullObj={d:nullArray,o:0};
function __ZN3FooC1Ei(Lthis,Lx){
	Lthis.i0=Lx;
}
function __Z7webMainv(){
	var tmp0=null;
	tmp0=new ._Z3Foo(undefined);
	__ZN3FooC1Ei(tmp0,10);
}
function _memcpy(Ldst0,Mdst0,Lsrc0,Msrc0,Llen0){
	// omitted for the GitHub issue    
}
__Z7webMainv();

Note that there is syntax error:

.../a.out:11
	tmp0=new ._Z3Foo(undefined);
	          ^^^^^^
SyntaxError: Unexpected identifier

However, if I just change struct to class, a valid JS is produced.

My cheerp version is:

Cheerp 2.0 clang version 3.7.0 (https://github.com/leaningtech/cheerp-clang.git 70472c979d8cc9e1deafd9da94d6f54c7661b31c) (https://github.com/leaningtech/cheerp-llvm.git 7d4a8f11e29d6df426ba449e4a9aa20f897be08e) (based on LLVM 3.7.0svn)
Target: i686-pc-windows-gnu
Thread model: posix
@alexp-sssup
Copy link
Member

Yes, we can reproduce this bug, we will let you know when it's fixed. In the mean time, as you found out, you can work around the problem by using a class with a public: before the first field. That's equivalent to a struct.

@alexp-sssup
Copy link
Member

Problem fixed in current master

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants