ソースを参照

[cpp] Use auto-casting rules with RawPointer (#9194)

* [cpp] add  to use auto-cast rules

* [test] add regression test for #9194

* [test] Guard with #if (cpp && !cppia)

* [test] Provide an empty test to keep the test-runner happy

* Run test for cppia
George Corney 5 年 前
コミット
6979ebc7cb
2 ファイル変更25 行追加0 行削除
  1. 1 0
      src/generators/gencpp.ml
  2. 24 0
      tests/unit/src/unit/hxcpp_issues/Issue9194.hx

+ 1 - 0
src/generators/gencpp.ml

@@ -3092,6 +3092,7 @@ let retype_expression ctx request_type function_args function_type expression_tr
             else (match return_type with
             else (match return_type with
                | TCppObjC(k) -> CppCastObjC(baseCpp,k), return_type
                | TCppObjC(k) -> CppCastObjC(baseCpp,k), return_type
                | TCppPointer(_,_)
                | TCppPointer(_,_)
+               | TCppRawPointer(_,_)
                | TCppStar(_)
                | TCppStar(_)
                | TCppInst(_) -> CppCast(baseCpp,return_type), return_type
                | TCppInst(_) -> CppCast(baseCpp,return_type), return_type
                | TCppString -> CppCastScalar(baseCpp,"::String"), return_type
                | TCppString -> CppCastScalar(baseCpp,"::String"), return_type

+ 24 - 0
tests/unit/src/unit/hxcpp_issues/Issue9194.hx

@@ -0,0 +1,24 @@
+package unit.hxcpp_issues;
+
+
+class Issue9194 extends Test {
+
+	@:analyzer(no_optimize)
+	function test() {
+		#if cpp
+		// will fail during C++ compile
+		var buffer: cpp.RawPointer<cpp.Void> = null;
+		var floatBuffer: cpp.RawPointer<cpp.Float32> = cast buffer;
+		// generates incorrect: float* floatBuffer = buffer
+		// the lack of native casting means the compiler throws an error here
+
+		var buffer: cpp.Star<cpp.Void> = null;
+		var floatBuffer: cpp.Star<cpp.Float32> = cast buffer;
+		// generates correct: float* floatBuffer = ( (float*) buffer ) 
+		#end
+
+		// empty test to keep the test-runner happy
+		t(true);
+	}
+
+}