Example #1
0
int main() {
  int x = 10;
  int y = 20;

  assert(addByValue(x, y) == 31);
  assert(x == 10);
  assert(y == 20);
  assert(addByReference(x, y) == 31);
  assert(x == 11);
  assert(y == 20);

  //return by value
  int value = returnByValue(3, 10);
  value++;
  assert(result == 13);

  result = 0; //reset the result

  //return by reference
  int reference = returnByReference(3, 10);
  reference++;
  assert(reference == 14);
}
void f() {
  throw returnByReference(); // Should diagnose
  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: throw expression should throw anonymous temporary values instead [misc-throw-by-value-catch-by-reference]
  throw returnByValue(); // Should not diagnose
}