Repository: Konstantin8105/c4go
Pull request #356 (2019-03-24 17:35:07)

ignore function sizeof in pointer arith

codecov[bot]: # [Codecov](https://codecov.io/gh/Konstantin8105/c4go/pull/356?src=pr&el=h1) Report
> Merging [#356](https://codecov.io/gh/Konstantin8105/c4go/pull/356?src=pr&el=desc) into [master](https://codecov.io/gh/Konstantin8105/c4go/commit/69fa214248350c9124623e7a0d2eaf25d48d52f9?src=pr&el=desc) will **not change** coverage.
> The diff coverage is `n/a`.

[![Impacted file tree graph](https://codecov.io/gh/Konstantin8105/c4go/pull/356/graphs/tree.svg?width=650&token=esH2rHXlZ2&height=150&src=pr)](https://codecov.io/gh/Konstantin8105/c4go/pull/356?src=pr&el=tree)

```diff
@@           Coverage Diff           @@
##           master     #356   +/-   ##
=======================================
  Coverage   86.25%   86.25%           
=======================================
  Files         186      186           
  Lines       10698    10698           
=======================================
  Hits         9228     9228           
  Misses       1051     1051           
  Partials      419      419
```


| [Impacted Files](https://codecov.io/gh/Konstantin8105/c4go/pull/356?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [transpiler/unary.go](https://codecov.io/gh/Konstantin8105/c4go/pull/356/diff?src=pr&el=tree#diff-dHJhbnNwaWxlci91bmFyeS5nbw==) | `74.59% <ø> (ø)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/Konstantin8105/c4go/pull/356?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/Konstantin8105/c4go/pull/356?src=pr&el=footer). Last update [69fa214...8da3601](https://codecov.io/gh/Konstantin8105/c4go/pull/356?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/scripts/scripts.txt b/scripts/scripts.txt
index 386b511..9c60e5b 100644
--- a/scripts/scripts.txt
+++ b/scripts/scripts.txt
@@ -10,9 +10,9 @@ Calculate warnings : ./testdata/ed
 		Unsafe   : 156
 
 Calculate warnings in file: ./testdata/neateqn/neateqn.go
-		After transpiling : 3 warnings.
-		Go build : 12 warnings
-		Unsafe   : 14
+		After transpiling : 0 warnings.
+		Go build : 4 warnings
+		Unsafe   : 15
 
 Calculate warnings in file: ./testdata/neatmkfn/neatmkfn.go
 		After transpiling : 557 warnings.
@@ -35,9 +35,9 @@ Calculate warnings in file: ./testdata/neatroff/neatroff.go
 		Unsafe   : 168
 
 Calculate warnings in file: ./testdata/neatvi/neatvi.go
-		After transpiling : 36 warnings.
+		After transpiling : 31 warnings.
 		Go build : 3 warnings
-		Unsafe   : 76
+		Unsafe   : 77
 
 Calculate warnings in file: testdata/vorbis/vorbis.go
 After transpiling : 5 warnings.
diff --git a/transpiler/operators.go b/transpiler/operators.go
index d261323..beeec01 100644
--- a/transpiler/operators.go
+++ b/transpiler/operators.go
@@ -85,7 +85,7 @@ func transpileConditionalOperator(n *ast.ConditionalOperator, p *program.Program
 	}
 
 	// c - else body
-	c, cType, newPre, newPost, err := transpileToExpr(n.Children()[2], p, false)
+	c, cType, newPre, newPost, err := atomicOperation(n.Children()[2], p)
 	if err != nil {
 		err = fmt.Errorf("parameter `c` : %v", err)
 		return nil, "", nil, nil, err
diff --git a/transpiler/unary.go b/transpiler/unary.go
index 2fb18ea..c5ed008 100644
--- a/transpiler/unary.go
+++ b/transpiler/unary.go
@@ -369,6 +369,7 @@ func pointerParts(node *ast.Node, p *program.Program) (
 			case *ast.CallExpr,
 				*ast.ArraySubscriptExpr,
 				*ast.MemberExpr,
+				*ast.UnaryExprOrTypeTraitExpr, // ignore sizeof
 				*ast.CStyleCastExpr:
 				return
 			}


Test patch:
diff --git a/tests/operators.c b/tests/operators.c
index e7b6385..3c6a71a 100644
--- a/tests/operators.c
+++ b/tests/operators.c
@@ -76,7 +76,7 @@ struct UUU000{
 
 int main()
 {
-    plan(153);
+    plan(158);
 
 	is_eq(valGlobInt, 42);
 	is_eq(valGlobDouble, 45);
@@ -667,6 +667,32 @@ int main()
 		is_eq(a,91);
 		is_eq(b,91);
 	}
+	diag("chars compare");
+	{
+		char *s = "building\x00";
+		char *r = "build\x00";
+		if ( *r ) {
+			pass("r is valid");
+		}
+		if ( *s ) {
+			pass("s is valid");
+		}
+		char qwe[4];
+		if ( *r && s + 2 < s + sizeof(qwe)) {
+			pass("expression is valid");
+		}
+		(void)(qwe);
+		if (*r == ' '){
+			fail("not valid comparing");
+		}
+		if (*r == 'b'){
+			pass("valid comparing");
+		}
+		while ( *r && s + 2 < s + 4){
+			pass("while pass")
+			break;
+		}
+	}
 
     done_testing();
 }
diff --git a/tests/ternary.c b/tests/ternary.c
index 6ccafa7..346e430 100644
--- a/tests/ternary.c
+++ b/tests/ternary.c
@@ -31,7 +31,7 @@ void test_return_ternary()
 
 int main()
 {
-    plan(13);
+    plan(15);
 
     int a = 'a' == 65 ? 10 : 100;
     float b = 10 == 10 ? 1.0 : 2.0;
@@ -87,5 +87,15 @@ int main()
 
     test_return_ternary();
 
+	diag("postfix else");
+	{
+		int a = 12;
+		int d;
+		d = (1 == 0) ? --a : ++a;
+		is_eq(d, 13);
+		d = (1 != 0) ? --a : ++a;
+		is_eq(d, 12);
+	}
+
     done_testing();
 }