diff options
author | upstream source tree <ports@midipix.org> | 2015-03-15 20:14:05 -0400 |
---|---|---|
committer | upstream source tree <ports@midipix.org> | 2015-03-15 20:14:05 -0400 |
commit | 554fd8c5195424bdbcabf5de30fdc183aba391bd (patch) | |
tree | 976dc5ab7fddf506dadce60ae936f43f58787092 /gcc/testsuite/objc.dg/attributes | |
download | cbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.bz2 cbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.xz |
obtained gcc-4.6.4.tar.bz2 from upstream website;upstream
verified gcc-4.6.4.tar.bz2.sig;
imported gcc-4.6.4 source tree from verified upstream tarball.
downloading a git-generated archive based on the 'upstream' tag
should provide you with a source tree that is binary identical
to the one extracted from the above tarball.
if you have obtained the source via the command 'git clone',
however, do note that line-endings of files in your working
directory might differ from line-endings of the respective
files in the upstream repository.
Diffstat (limited to 'gcc/testsuite/objc.dg/attributes')
23 files changed, 737 insertions, 0 deletions
diff --git a/gcc/testsuite/objc.dg/attributes/attributes.exp b/gcc/testsuite/objc.dg/attributes/attributes.exp new file mode 100644 index 000000000..cb11216c5 --- /dev/null +++ b/gcc/testsuite/objc.dg/attributes/attributes.exp @@ -0,0 +1,44 @@ +# Copyright (C) 2010 Free Software Foundation, Inc. +# +# This file is part of GCC. +# +# GCC is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GCC is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GCC; see the file COPYING3. If not see +# <http://www.gnu.org/licenses/>. + +# Load support procs. + +load_lib objc-dg.exp + +# If a testcase doesn't have special options, use these. +global DEFAULT_CFLAGS +if ![info exists DEFAULT_CFLAGS] then { + set DEFAULT_CFLAGS "" +} + +# Initialize `dg'. +dg-init + +# Gather a list of all tests. +set tests [lsort [glob -nocomplain $srcdir/$subdir/*.m]] + +# Main loop. +dg-runtest $tests "-fgnu-runtime" $DEFAULT_CFLAGS + +# darwin targets can also run code with the NeXT runtime. +if [istarget "*-*-darwin*" ] { + dg-runtest $tests "-fnext-runtime" $DEFAULT_CFLAGS +} + +# All done. +dg-finish diff --git a/gcc/testsuite/objc.dg/attributes/categ-attribute-1.m b/gcc/testsuite/objc.dg/attributes/categ-attribute-1.m new file mode 100644 index 000000000..e9fe9c986 --- /dev/null +++ b/gcc/testsuite/objc.dg/attributes/categ-attribute-1.m @@ -0,0 +1,31 @@ +/* { dg-do compile } */ + +#include <objc/objc.h> +#include "../../objc-obj-c++-shared/Object1.h" + +@interface obj : Object { +@public + int var; +} +- (int) mth; +@end + +@implementation obj +- (int) mth { return var; } +@end + +__attribute ((deprecated)) +@interface obj (dep_categ) +- (int) depmth;/* { dg-warning "category attributes are not available in this version" } */ +@end + +@implementation obj (dep_categ) +- (int) depmth { return var + 1; } +@end + +int foo (void) +{ + obj *p = [obj new]; + int q = [p depmth]; + return [p mth]; +} diff --git a/gcc/testsuite/objc.dg/attributes/categ-attribute-2.m b/gcc/testsuite/objc.dg/attributes/categ-attribute-2.m new file mode 100644 index 000000000..4a98de130 --- /dev/null +++ b/gcc/testsuite/objc.dg/attributes/categ-attribute-2.m @@ -0,0 +1,32 @@ +/* { dg-do compile } */ + +#include <objc/objc.h> +#include "../../objc-obj-c++-shared/Object1.h" + +@interface obj : Object { +@public + int var; +} +- (int) mth; +@end + +@implementation obj +- (int) mth { return var; } +@end + +__attribute__ ((deprecated("no dep_categ"))) +@interface obj (dep_categ) +- (int) depmth;/* { dg-warning "category attributes are not available in this version" } */ +@end + +__attribute__ ((deprecated)) +@implementation obj (dep_categ) /* { dg-warning "prefix attributes are ignored for implementations" } */ +- (int) depmth { return var + 1; } +@end + +int foo (void) +{ + obj *p = [obj new]; + int q = [p depmth]; + return [p mth]; +} diff --git a/gcc/testsuite/objc.dg/attributes/class-attribute-1.m b/gcc/testsuite/objc.dg/attributes/class-attribute-1.m new file mode 100644 index 000000000..3444760bc --- /dev/null +++ b/gcc/testsuite/objc.dg/attributes/class-attribute-1.m @@ -0,0 +1,59 @@ +/* { dg-do compile } */ + +/* Test deprecate attribute with an @interface declaration. */ + +#include <objc/objc.h> + +__attribute__ ((deprecated)) +@interface DeprecatedClass +{ + Class isa; +} ++ (id) classObject; ++ (id) new; +@end + +@implementation DeprecatedClass ++ (id) classObject { return self; } ++ (id) new { return nil; } +@end + +@interface DeprecatedClass (Category) +@end /* { dg-warning "is deprecated" } */ + +@interface Subclass : DeprecatedClass +@end /* { dg-warning "is deprecated" } */ + +DeprecatedClass *object; /* { dg-warning "is deprecated" } */ + +int function (DeprecatedClass *object) /* { dg-warning "is deprecated" } */ +{ + /* Note how the following deprecation warning is generated by + "DeprecatedClass *", not by "[DeprecatedClass ...]. */ + DeprecatedClass *x = [DeprecatedClass new]; /* { dg-warning "is deprecated" } */ + + if (x == object) + return 0; + else + return 1; +} + +id function2 (void) +{ + return DeprecatedClass.classObject; /* { dg-warning "is deprecated" } */ +} + +@interface NormalClass +{ + Class isa; + DeprecatedClass *object; /* { dg-warning "is deprecated" } */ +} +- (DeprecatedClass *)method; /* { dg-warning "is deprecated" } */ +@end + +@implementation NormalClass +- (DeprecatedClass *)method /* { dg-warning "is deprecated" } */ +{ + return nil; +} +@end diff --git a/gcc/testsuite/objc.dg/attributes/class-attribute-2.m b/gcc/testsuite/objc.dg/attributes/class-attribute-2.m new file mode 100644 index 000000000..2e1bacb3f --- /dev/null +++ b/gcc/testsuite/objc.dg/attributes/class-attribute-2.m @@ -0,0 +1,21 @@ +/* { dg-do compile } */ + +#include <objc/objc.h> + +__attribute__ ((deprecated)) +@interface DeprecatedClass +{ + Class isa; +} ++ (id) new; +@end + +__attribute__ ((deprecated)) +@implementation DeprecatedClass /* { dg-warning "prefix attributes are ignored for implementations" } */ ++ (id) new { return nil; } +@end + +void function (void) +{ + DeprecatedClass *object = [DeprecatedClass new]; /* { dg-warning "is deprecated" } */ +} diff --git a/gcc/testsuite/objc.dg/attributes/class-attribute-3.m b/gcc/testsuite/objc.dg/attributes/class-attribute-3.m new file mode 100644 index 000000000..6cc5d4e26 --- /dev/null +++ b/gcc/testsuite/objc.dg/attributes/class-attribute-3.m @@ -0,0 +1,14 @@ +/* Contributed by Nicola Pero <nicola.pero@meta-innovation.com>, December 2010. */ +/* { dg-do compile } */ + +/* Test that you get a warning when an unknown class attribute is ignored. */ + +#include <objc/objc.h> + +__attribute__ ((unknown_attribute)) +@interface MyClass +{ /* { dg-warning "ignored" } */ + Class isa; +} ++ (id) new; +@end diff --git a/gcc/testsuite/objc.dg/attributes/invalid-attribute-1.m b/gcc/testsuite/objc.dg/attributes/invalid-attribute-1.m new file mode 100644 index 000000000..ec17e9d71 --- /dev/null +++ b/gcc/testsuite/objc.dg/attributes/invalid-attribute-1.m @@ -0,0 +1,6 @@ +/* Contributed by Nicola Pero <nicola.pero@meta-innovation.com>, January 2011. */ +/* { dg-do compile } */ + +#include <objc/objc.h> + +__attribute__ ((deprecated)) @class A; /* { dg-error "unexpected attribute before .class." } */ diff --git a/gcc/testsuite/objc.dg/attributes/method-attribute-1.m b/gcc/testsuite/objc.dg/attributes/method-attribute-1.m new file mode 100644 index 000000000..ffe72e20f --- /dev/null +++ b/gcc/testsuite/objc.dg/attributes/method-attribute-1.m @@ -0,0 +1,40 @@ +/* { dg-do compile } */ + +#include <objc/objc.h> +#include "../../objc-obj-c++-shared/Object1.h" + +@interface obj : Object { +@public + int var; +} +- (int) mth; ++ (id) dep_cls_mth __attribute__((deprecated)) ; +- (int) dep_ins_mth __attribute__((deprecated)) ; +- (int) dep_ins_mtharg: (int) i __attribute__((deprecated)) ; +- (int) dep_ins_mtharg1: (int) i __attribute__((deprecated)) add: (int) j;/* { dg-error "expected ';' or '\{' after method attribute definition" } */ +- (int) nodef __attribute__((deprecated)) { return var-2; } ; /* { dg-error "expected ';' before '\{' token" } */ +__attribute__((deprecated)) +- (int) bad_pref_mth; /* { dg-warning "prefix attributes are ignored for methods" } */ +@end + +@implementation obj +- (int) mth { return var; } ++ (id) dep_cls_mth { return self; } +- (int) dep_ins_mth { return var ; } +- (int) dep_ins_mtharg: (int) i { return var + i ; } +- (int) dep_ins_mtharg1: (int) i add: (int) j { return var + i + j ; } +- (int) bad_pref_mth { return var; }; +- (int) nodef { return var-2; } ; +@end + +int foo (void) +{ + obj *p = [obj new]; + id n = [obj dep_cls_mth]; /* { dg-warning "is deprecated" } */ + + [p dep_ins_mth]; /* { dg-warning "is deprecated" } */ + [p dep_ins_mtharg:2]; /* { dg-warning "is deprecated" } */ + [p dep_ins_mtharg1:3 add:3]; + + return [p mth]; +} diff --git a/gcc/testsuite/objc.dg/attributes/method-attribute-2.m b/gcc/testsuite/objc.dg/attributes/method-attribute-2.m new file mode 100644 index 000000000..4a56b3aa8 --- /dev/null +++ b/gcc/testsuite/objc.dg/attributes/method-attribute-2.m @@ -0,0 +1,33 @@ +/* { dg-do compile } */ + +#include <objc/objc.h> +#include "../../objc-obj-c++-shared/Object1.h" + +@interface obj : Object { +@public + int var; +} +- (int) depmth __attribute__((deprecated)); +- (int) depmtharg:(int) iarg __attribute__((deprecated)); +- (int) unusedarg:(int) __attribute__((unused)) uarg ; +- (int) depunusedarg:(int) __attribute__((unused)) uarg __attribute__((deprecated)) ; +@end + +@implementation obj +- (int) depmth __attribute__((deprecated)) { return var; } /* { dg-warning "method attributes can not be specified in @implementation context" } */ +- (int) depmtharg:(int) iarg { return var + iarg ; } +- (int) unusedarg:(int) __attribute__((unused)) uarg { return var; } +- (int) depunusedarg:(int) __attribute__((unused)) uarg { return var; } +@end + +int foo (void) +{ + obj *p = [obj new]; + + [p depmth]; /* { dg-warning "is deprecated" } */ + [p depmtharg:1]; /* { dg-warning "is deprecated" } */ + [p unusedarg:2]; /* { dg-bogus "is deprecated" } */ + [p depunusedarg:3 ]; /* { dg-warning "is deprecated" } */ + + return [p depmtharg:0]; /* { dg-warning "is deprecated" } */ +} diff --git a/gcc/testsuite/objc.dg/attributes/method-attribute-3.m b/gcc/testsuite/objc.dg/attributes/method-attribute-3.m new file mode 100644 index 000000000..de607a3d9 --- /dev/null +++ b/gcc/testsuite/objc.dg/attributes/method-attribute-3.m @@ -0,0 +1,24 @@ +/* { dg-do compile } */ + +#include "../../objc-obj-c++-shared/Object1.h" + +@interface obj : Object { +@public + int var; +} +- (int) vargsn: (int) count, ... __attribute__((deprecated)); +@end + +@implementation obj +- (int) vargsn: (int) count, ... +{ + return 0; +} +@end + +int foo (void) +{ + obj *p = [obj new]; + + return [p vargsn:0]; /* { dg-warning "'vargsn:' is deprecated .declared at " } */ +} diff --git a/gcc/testsuite/objc.dg/attributes/method-deprecated-1.m b/gcc/testsuite/objc.dg/attributes/method-deprecated-1.m new file mode 100644 index 000000000..8343856a5 --- /dev/null +++ b/gcc/testsuite/objc.dg/attributes/method-deprecated-1.m @@ -0,0 +1,33 @@ +/* Contributed by Nicola Pero <nicola.pero@meta-innovation.com>, October 2010. */ +/* { dg-do compile } */ + +#include <objc/objc.h> + +@interface MyClass +{ + Class isa; +} ++ (int) method; +- (int) method; ++ (int) deprecatedClassMethod __attribute__((deprecated)); +- (int) deprecatedInstanceMethod __attribute__((deprecated)); +@end + +/* Test that deprecation warnings are produced, but not if the + receiver is of type 'id'. */ +void foo (void) +{ + Class c; + id object; + MyClass *another_object; + + [c method]; + [object method]; + [c deprecatedClassMethod]; + [object deprecatedInstanceMethod]; + + [object method]; + [another_object method]; + [MyClass deprecatedClassMethod]; /* { dg-warning "is deprecated" } */ + [another_object deprecatedInstanceMethod]; /* { dg-warning "is deprecated" } */ +} diff --git a/gcc/testsuite/objc.dg/attributes/method-deprecated-2.m b/gcc/testsuite/objc.dg/attributes/method-deprecated-2.m new file mode 100644 index 000000000..1e5d87f3e --- /dev/null +++ b/gcc/testsuite/objc.dg/attributes/method-deprecated-2.m @@ -0,0 +1,23 @@ +/* Contributed by Nicola Pero <nicola.pero@meta-innovation.com>, October 2010. */ +/* { dg-do compile } */ + +#include <objc/objc.h> + +@interface MyClass +{ + Class isa; +} ++ (int) deprecatedClassMethod: (id)firstObject, ... __attribute__((sentinel)) __attribute__((deprecated)); +- (int) deprecatedInstanceMethod: (id)firstobject, ... __attribute__((sentinel)) __attribute__((deprecated)); +@end + +/* Test that deprecation warnings are produced even if the method is + also marked with another attribute too (this is to test the + processing of multiple attributes). */ +void foo (void) +{ + MyClass *object = nil; + + [MyClass deprecatedClassMethod: object, nil]; /* { dg-warning "is deprecated" } */ + [object deprecatedInstanceMethod: object, nil]; /* { dg-warning "is deprecated" } */ +} diff --git a/gcc/testsuite/objc.dg/attributes/method-deprecated-3.m b/gcc/testsuite/objc.dg/attributes/method-deprecated-3.m new file mode 100644 index 000000000..5c715a20b --- /dev/null +++ b/gcc/testsuite/objc.dg/attributes/method-deprecated-3.m @@ -0,0 +1,21 @@ +/* Contributed by Nicola Pero <nicola.pero@meta-innovation.com>, October 2010. */ +/* { dg-do compile } */ + +#include <objc/objc.h> + +/* Test that __attribute__ ((__deprecated__)) works as well as __attribute__ ((deprecated)). */ +@interface MyClass +{ + Class isa; +} ++ (int) deprecatedClassMethod: (id)firstObject, ... __attribute__((__deprecated__)); +- (int) deprecatedInstanceMethod: (id)firstobject, ... __attribute__((__deprecated__)); +@end + +void foo (void) +{ + MyClass *object = nil; + + [MyClass deprecatedClassMethod: object, nil]; /* { dg-warning "is deprecated" } */ + [object deprecatedInstanceMethod: object, nil]; /* { dg-warning "is deprecated" } */ +} diff --git a/gcc/testsuite/objc.dg/attributes/method-format-1.m b/gcc/testsuite/objc.dg/attributes/method-format-1.m new file mode 100644 index 000000000..11ce8eebb --- /dev/null +++ b/gcc/testsuite/objc.dg/attributes/method-format-1.m @@ -0,0 +1,43 @@ +/* Contributed by Nicola Pero <nicola.pero@meta-innovation.com>, October 2010. */ +/* { dg-do compile } */ +/* { dg-options "-Wall" } */ + +#include <objc/objc.h> +#include <stdlib.h> + +@interface LogObject +{ + Class isa; +} ++ (void) log: (int)level message: (const char *) my_format, ... __attribute__ ((format (printf, 2, 3))); +- (void) log: (int)level message: (const char *) my_format, ... __attribute__ ((format (printf, 2, 3))); + ++ (void) debug: (const char *) my_format, ... __attribute__ ((format (printf, 1, 2))); +- (void) debug: (const char *) my_format, ... __attribute__ ((format (printf, 1, 2))); + +/* Just make sure a missing or invalid attribute won't crash the compiler. */ +- (void) log2: (int)level message: (const char *) my_format, ... __attribute__ ((format (printf, 2))); /* { dg-error "wrong" } */ ++ (void) debug2: (const char *) my_format, ... __attribute__ ((format (printf))); /* { dg-error "wrong" } */ +- (void) debug2: (const char *) my_format, ... __attribute__ ((format (printf))); /* { dg-error "wrong" } */ ++ (void) alert: (const char *) my_format __attribute__ ((format (printf, 1, 2))); /* { dg-error "args to be formatted is not ..." } */ +- (void) alert: (const char *) my_format __attribute__ ((format (printf, 1, 2))); /* { dg-error "args to be formatted is not ..." } */ +@end + +void test (LogObject *object) +{ + [object log: 2 message: "attribute only applies to variadic functions"]; + [object log: 2 message: "attribute %s only applies to variadic functions", "'format'"]; + [object log: 2 message: "attribute %s only applies to variadic functions"]; /* { dg-warning "expects a matching" } */ + + [object debug: "attribute only applies to variadic functions"]; + [object debug: "attribute %s only applies to variadic functions", "'format'"]; + [object debug: "attribute %s only applies to variadic functions"]; /* { dg-warning "expects a matching" } */ + + [LogObject log: 2 message: "attribute only applies to variadic functions"]; + [LogObject log: 2 message: "attribute %s only applies to variadic functions", "'format'"]; + [LogObject log: 2 message: "attribute %s only applies to variadic functions"]; /* { dg-warning "expects a matching" } */ + + [LogObject debug: "attribute only applies to variadic functions"]; + [LogObject debug: "attribute %s only applies to variadic functions", "'format'"]; + [LogObject debug: "attribute %s only applies to variadic functions"]; /* { dg-warning "expects a matching" } */ +} diff --git a/gcc/testsuite/objc.dg/attributes/method-noreturn-1.m b/gcc/testsuite/objc.dg/attributes/method-noreturn-1.m new file mode 100644 index 000000000..717d6e65e --- /dev/null +++ b/gcc/testsuite/objc.dg/attributes/method-noreturn-1.m @@ -0,0 +1,34 @@ +/* Contributed by Nicola Pero <nicola.pero@meta-innovation.com>, October 2010. */ +/* { dg-do compile } */ + +#include <objc/objc.h> +#include <stdlib.h> + +@interface MyClass +{ + Class isa; +} ++ (id) method1 __attribute__ ((noreturn)); +- (id) method2 __attribute__ ((noreturn)); ++ (id) method3 __attribute__ ((noreturn)); +- (id) method4 __attribute__ ((noreturn)); +@end + +@implementation MyClass ++ (id) method1 +{ + return self; /* { dg-warning "function declared .noreturn. has a .return. statement" } */ +} /* { dg-warning ".noreturn. function does return" "" { target *-*-* } 20 } */ +- (id) method2 +{ + return self; /* { dg-warning "function declared .noreturn. has a .return. statement" } */ +} /* { dg-warning ".noreturn. function does return" "" { target *-*-* } 24 } */ ++ (id) method3 +{ + abort (); +} +- (id) method4 +{ + abort (); +} +@end diff --git a/gcc/testsuite/objc.dg/attributes/method-sentinel-1.m b/gcc/testsuite/objc.dg/attributes/method-sentinel-1.m new file mode 100644 index 000000000..e2abb1e8a --- /dev/null +++ b/gcc/testsuite/objc.dg/attributes/method-sentinel-1.m @@ -0,0 +1,35 @@ +/* Contributed by Nicola Pero <nicola.pero@meta-innovation.com>, October 2010. */ +/* { dg-do compile } */ +/* { dg-options "-Wall" } */ + +#include <objc/objc.h> +#include <stdlib.h> +#include "../../objc-obj-c++-shared/objc-test-suite-types.h" + +@interface NSArray +{ + Class isa; +} ++ (id) arrayWithObject: (id)object __attribute__ ((sentinel)); /* { dg-warning "attribute only applies to variadic functions" } */ ++ (id) arrayWithObjects: (id)firstObject, ... __attribute__ ((sentinel)); + +- (id) initWithObject: (id)object __attribute__ ((sentinel)); /* { dg-warning "attribute only applies to variadic functions" } */ +- (id) initWithObjects: (id)firstObject, ... __attribute__ ((sentinel)); +@end + +void test (id object) +{ + NSArray *array; + + array = [NSArray arrayWithObject: object]; + array = [NSArray arrayWithObjects: object, nil]; + array = [NSArray arrayWithObjects: object, object, nil]; + array = [NSArray arrayWithObjects: object]; /* { dg-warning "not enough variable arguments" } */ + array = [NSArray arrayWithObjects: object, object]; /* { dg-warning "missing sentinel" } */ + + [array initWithObject: object]; + [array initWithObjects: object, nil]; + [array initWithObjects: object, object, nil]; + [array initWithObjects: object]; /* { dg-warning "not enough variable arguments" } */ + [array initWithObjects: object, object]; /* { dg-warning "missing sentinel" } */ +} diff --git a/gcc/testsuite/objc.dg/attributes/objc-exception-1.m b/gcc/testsuite/objc.dg/attributes/objc-exception-1.m new file mode 100644 index 000000000..e7f6f856f --- /dev/null +++ b/gcc/testsuite/objc.dg/attributes/objc-exception-1.m @@ -0,0 +1,32 @@ +/* Contributed by Nicola Pero <nicola.pero@meta-innovation.com>, February 2011. */ +/* { dg-do compile } */ + +/* Test that the 'objc_exception' attribute is accepted for + @interfaces, but not for anything else. */ + +#include <objc/objc.h> + +/* Fine. */ +__attribute__ ((objc_exception)) +@interface MyClass +{ + Class isa; +} +@end + +/* Fine. */ +__attribute__ ((__objc_exception__)) +@interface MyClass2 +{ + Class isa; +} +@end + +__attribute__ ((objc_exception)) +@protocol MyProtocol; /* { dg-warning "ignored" } */ + +__attribute__ ((objc_exception)) +int myVariable; /* { dg-warning "ignored" } */ + +__attribute__ ((objc_exception)) +int myFunction (int argument); /* { dg-warning "ignored" } */ diff --git a/gcc/testsuite/objc.dg/attributes/parameter-attribute-1.m b/gcc/testsuite/objc.dg/attributes/parameter-attribute-1.m new file mode 100644 index 000000000..8263df66d --- /dev/null +++ b/gcc/testsuite/objc.dg/attributes/parameter-attribute-1.m @@ -0,0 +1,45 @@ +/* Test __attribute__((unused)) for an Objective-C method parameter. */ +/* { dg-do compile } */ +/* { dg-options "-Wunused-parameter" } */ + +#include <objc/objc.h> + +@interface MyRootClass +{ + Class isa; +} +- (id) method1: (id) argument1; +- (id) method2: (id) __attribute__((unused)) argument1; +- (id) method3: (id) __attribute__((unused)) argument1 + andArgument: (id) argument2; +- (id) method4: (id) __attribute__((unused)) argument1 + andArgument: (id) __attribute__((unused)) argument2; +- (id) method5: (id) argument1 + andArgument: (id) __attribute__ ((unused)) argument2; +@end + +@implementation MyRootClass +- (id) method1: (id) argument1 +{ /* { dg-warning "unused parameter .argument1." } */ + return nil; +} +- (id) method2: (id) __attribute__((unused)) argument1 +{ + return nil; +} +- (id) method3: (id) __attribute__((unused)) argument1 + andArgument: (id) argument2 +{ /* { dg-warning "unused parameter .argument2." } */ + return nil; +} +- (id) method4: (id) __attribute__((unused)) argument1 + andArgument: (id) __attribute__((unused)) argument2 +{ + return nil; +} +- (id) method5: (id) argument1 + andArgument: (id) __attribute__ ((unused)) argument2 +{ /* { dg-warning "unused parameter .argument1." } */ + return nil; +} +@end diff --git a/gcc/testsuite/objc.dg/attributes/parameter-attribute-2.m b/gcc/testsuite/objc.dg/attributes/parameter-attribute-2.m new file mode 100644 index 000000000..99c5a308b --- /dev/null +++ b/gcc/testsuite/objc.dg/attributes/parameter-attribute-2.m @@ -0,0 +1,25 @@ +/* Test that we get warnings for unrecognized attributes. */ +/* { dg-do compile } */ + +#include <objc/objc.h> + +@interface MyRootClass +{ + Class isa; +} +/* TODO: Emit warnings in the @interface as well. Currently we only emit + them in @implementation. */ ++ (id) method1: (id) __attribute__ ((xxxxx)) argument1; ++ (id) method2: (id) __attribute__ ((noinline)) argument1; +@end + +@implementation MyRootClass ++ (id) method1: (id) __attribute__ ((xxxxx)) argument1 +{ /* { dg-warning ".xxxxx. attribute directive ignored" } */ + return argument1; +} ++ (id) method2: (id) __attribute__ ((noinline)) argument1 +{ /* { dg-warning ".noinline. attribute ignored" } */ + return argument1; +} +@end diff --git a/gcc/testsuite/objc.dg/attributes/proto-attribute-1.m b/gcc/testsuite/objc.dg/attributes/proto-attribute-1.m new file mode 100644 index 000000000..a852a7a6c --- /dev/null +++ b/gcc/testsuite/objc.dg/attributes/proto-attribute-1.m @@ -0,0 +1,21 @@ +/* { dg-do compile } */ + +#include <objc/objc.h> + +__attribute ((deprecated)) +@protocol dep_proto +- (int) depprotomth; +@end + +@interface obj <dep_proto> /* { dg-warning "is deprecated" } */ +{ +@public + int var; +} +- (int) mth; +@end + +@implementation obj +- (int) mth { return var; } +- (int) depprotomth { return var + 1; } +@end diff --git a/gcc/testsuite/objc.dg/attributes/proto-attribute-2.m b/gcc/testsuite/objc.dg/attributes/proto-attribute-2.m new file mode 100644 index 000000000..b23b81de2 --- /dev/null +++ b/gcc/testsuite/objc.dg/attributes/proto-attribute-2.m @@ -0,0 +1,31 @@ +/* Contributed by Nicola Pero <nicola.pero@meta-innovation.com>, November 2010. */ +/* { dg-do compile } */ + +/* Test deprecate attribute with a forward declarations of + @protocol. */ + +#include <stdlib.h> +#include <objc/objc.h> + +__attribute__ ((deprecated)) +@protocol DeprecatedProtocol1; + +@protocol NonDeprecatedProtocol1; + +void function1 (id <DeprecatedProtocol1> object); /* { dg-warning "is deprecated" } */ +void function2 (id <NonDeprecatedProtocol1> object); + +@class Class4; + +void function3 (Class4 <DeprecatedProtocol1> *object); /* { dg-warning "is deprecated" } */ +void function4 (Class4 <NonDeprecatedProtocol1> *object); +void function5 (Class4 <NonDeprecatedProtocol1, DeprecatedProtocol1> *object); /* { dg-warning "is deprecated" } */ + +int function6 (void) +{ + Protocol *p1 = @protocol (DeprecatedProtocol1); /* { dg-warning "is deprecated" } */ + Protocol *p2 = @protocol (NonDeprecatedProtocol1); + + return (p1 == p2); +} + diff --git a/gcc/testsuite/objc.dg/attributes/proto-attribute-3.m b/gcc/testsuite/objc.dg/attributes/proto-attribute-3.m new file mode 100644 index 000000000..2be286ecf --- /dev/null +++ b/gcc/testsuite/objc.dg/attributes/proto-attribute-3.m @@ -0,0 +1,59 @@ +/* Contributed by Nicola Pero <nicola.pero@meta-innovation.com>, November 2010. */ +/* { dg-do compile } */ + +/* Test deprecate attribute with normal @protocol declarations. */ + + +#include <stdlib.h> +#include <objc/objc.h> + +__attribute__ ((deprecated)) +@protocol DeprecatedProtocol1 +- (void) aMethod; +@end + +@protocol NonDeprecatedProtocol1 +- (void) anotherMethod; +@end + +@protocol Protocol2 <DeprecatedProtocol1> /* { dg-warning "is deprecated" } */ +- (void) someOtherMethod; +@end + +@protocol Protocol3 <NonDeprecatedProtocol1> +- (void) someOtherMethod2; +@end + +@protocol Protocol4 <NonDeprecatedProtocol1, DeprecatedProtocol1> /* { dg-warning "is deprecated" } */ +- (void) someOtherMethod3; +@end + + +@interface Class1 <DeprecatedProtocol1> /* { dg-warning "is deprecated" } */ +@end + +@interface Class2 <NonDeprecatedProtocol1> +@end + +@interface Class3 <NonDeprecatedProtocol1, DeprecatedProtocol1> /* { dg-warning "is deprecated" } */ +@end + +@interface Class2 (Category1) <DeprecatedProtocol1> /* { dg-warning "is deprecated" } */ +@end + +void function1 (id <DeprecatedProtocol1> object); /* { dg-warning "is deprecated" } */ +void function2 (id <NonDeprecatedProtocol1> object); + +@class Class4; + +void function3 (Class4 <DeprecatedProtocol1> *object); /* { dg-warning "is deprecated" } */ +void function4 (Class4 <NonDeprecatedProtocol1> *object); +void function5 (Class4 <NonDeprecatedProtocol1, DeprecatedProtocol1> *object); /* { dg-warning "is deprecated" } */ + +int function6 (void) +{ + Protocol *p1 = @protocol (DeprecatedProtocol1); /* { dg-warning "is deprecated" } */ + Protocol *p2 = @protocol (NonDeprecatedProtocol1); + + return (p1 == p2); +} diff --git a/gcc/testsuite/objc.dg/attributes/proto-attribute-4.m b/gcc/testsuite/objc.dg/attributes/proto-attribute-4.m new file mode 100644 index 000000000..226fd68b3 --- /dev/null +++ b/gcc/testsuite/objc.dg/attributes/proto-attribute-4.m @@ -0,0 +1,31 @@ +/* Contributed by Nicola Pero <nicola.pero@meta-innovation.com>, December 2010. */ +/* { dg-do compile } */ + +/* Test that you get a warning when an unknown protocol attribute is ignored. */ + +#include <objc/objc.h> + +__attribute__ ((unknown_attribute)) +@protocol MyProtocol +- (id) new; /* { dg-warning "ignored" } */ +@end + +__attribute__ ((unknown_attribute)) +@protocol MyProtocol2; /* { dg-warning "ignored" } */ + +/* Use the protocols to double-check that no more warnings are + generated. */ + +@interface MyClass <MyProtocol> +@end + +int test (id <MyProtocol2> x) +{ + if (@protocol (MyProtocol) == @protocol (MyProtocol2)) + return 1; + + if (x) + return 2; + + return 3; +} |