TestNoArithmeticExprInArgument.cpp (1246B)
1 #define MOZ_NO_ARITHMETIC_EXPR_IN_ARGUMENT __attribute__((annotate("moz_no_arith_expr_in_arg"))) 2 3 struct X { 4 explicit X(int) MOZ_NO_ARITHMETIC_EXPR_IN_ARGUMENT; 5 void baz(int) MOZ_NO_ARITHMETIC_EXPR_IN_ARGUMENT; 6 }; 7 8 int operator+(int, X); 9 int operator+(X, int); 10 int operator++(X); 11 12 void badArithmeticsInArgs() { 13 int a = 1; 14 typedef int myint; 15 myint b = 2; 16 X goodObj1(a); 17 goodObj1.baz(b); 18 X badObj1(a + b); // expected-error{{cannot pass an arithmetic expression of built-in types to 'X'}} 19 X badObj2 = X(a ? 0 : ++a); // expected-error{{cannot pass an arithmetic expression of built-in types to 'X'}} 20 X badObj3(~a); // expected-error{{cannot pass an arithmetic expression of built-in types to 'X'}} 21 badObj1.baz(a - 1 - b); // expected-error{{cannot pass an arithmetic expression of built-in types to 'baz'}} 22 badObj1.baz(++a); // expected-error{{cannot pass an arithmetic expression of built-in types to 'baz'}} 23 badObj1.baz(a++); // expected-error{{cannot pass an arithmetic expression of built-in types to 'baz'}} 24 badObj1.baz(a || b); 25 badObj1.baz(a + goodObj1); 26 badObj1.baz(goodObj1 + a); 27 badObj1.baz(++goodObj1); 28 badObj1.baz(-1); 29 badObj1.baz(-1.0); 30 badObj1.baz(1 + 2); 31 badObj1.baz(1 << (sizeof(int)/2)); 32 }