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