1/* Based on objc/execute/va_method.m, by Nicola Pero */ 2 3/* { dg-do run } */ 4/* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */ 5#include "../objc-obj-c++-shared/TestsuiteObject.m" 6#include <stdarg.h> 7#include <stdlib.h> 8 9/* Test methods with "C-style" trailing arguments, with or without ellipsis. */ 10 11@interface MathClass: TestsuiteObject 12/* sum positive numbers; -1 ends the list */ 13+ (int) sum: (int) firstNumber, int secondNumber, ...; 14+ (int) prod: (int) firstNumber, int secondNumber, int thirdNumber; 15+ (int) minimum: (int) firstNumber, ...; 16@end 17 18extern "C" int some_func(id self, SEL _cmd, int firstN, int secondN, int thirdN, ...) { 19 return firstN + secondN + thirdN; 20} 21 22@implementation MathClass 23+ (int) sum: (int) firstNumber, int secondNumber, ... 24{ 25 va_list ap; 26 int sum = 0, number = 0; 27 28 va_start (ap, secondNumber); 29 number = firstNumber + secondNumber; 30 31 while (number >= 0) 32 { 33 sum += number; 34 number = va_arg (ap, int); 35 } 36 37 va_end (ap); 38 39 return sum; 40} 41+ (int) prod: (int) firstNumber, int secondNumber, int thirdNumber { 42 return firstNumber * secondNumber * thirdNumber; 43} 44+ (int) minimum: (int) firstNumber, ... 45{ 46 va_list ap; 47 int minimum = 999, number = 0; 48 49 va_start (ap, firstNumber); 50 number = firstNumber; 51 52 while (number >= 0) 53 { 54 minimum = (minimum < number ? minimum: number); 55 number = va_arg (ap, int); 56 } 57 58 va_end (ap); 59 60 return minimum; 61} 62@end 63 64int main (void) 65{ 66 if ([MathClass sum: 1, 2, 3, 4, 5, -1] != 15) 67 abort (); 68 if ([MathClass prod: 4, 5, 6] != 120) 69 abort (); 70 if ([MathClass minimum: 17, 9, 133, 84, 35, -1] != 9) 71 abort (); 72 73 return 0; 74} 75 76