From 554fd8c5195424bdbcabf5de30fdc183aba391bd Mon Sep 17 00:00:00 2001 From: upstream source tree Date: Sun, 15 Mar 2015 20:14:05 -0400 Subject: obtained gcc-4.6.4.tar.bz2 from upstream website; 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. --- gcc/testsuite/obj-c++.dg/attributes/attributes.exp | 43 +++++++++++++++ .../obj-c++.dg/attributes/categ-attribute-1.mm | 31 +++++++++++ .../obj-c++.dg/attributes/categ-attribute-2.mm | 32 +++++++++++ .../obj-c++.dg/attributes/class-attribute-1.mm | 61 +++++++++++++++++++++ .../obj-c++.dg/attributes/class-attribute-2.mm | 21 ++++++++ .../obj-c++.dg/attributes/class-attribute-3.mm | 14 +++++ .../obj-c++.dg/attributes/invalid-attribute-1.mm | 6 +++ .../obj-c++.dg/attributes/method-attribute-1.mm | 40 ++++++++++++++ .../obj-c++.dg/attributes/method-attribute-2.mm | 33 ++++++++++++ .../obj-c++.dg/attributes/method-attribute-3.mm | 24 +++++++++ .../obj-c++.dg/attributes/method-deprecated-1.mm | 33 ++++++++++++ .../obj-c++.dg/attributes/method-deprecated-2.mm | 23 ++++++++ .../obj-c++.dg/attributes/method-deprecated-3.mm | 21 ++++++++ .../obj-c++.dg/attributes/method-format-1.mm | 43 +++++++++++++++ .../obj-c++.dg/attributes/method-noreturn-1.mm | 34 ++++++++++++ .../obj-c++.dg/attributes/method-sentinel-1.mm | 36 +++++++++++++ .../obj-c++.dg/attributes/parameter-attribute-1.mm | 45 ++++++++++++++++ .../obj-c++.dg/attributes/parameter-attribute-2.mm | 25 +++++++++ .../obj-c++.dg/attributes/proto-attribute-1.mm | 21 ++++++++ .../obj-c++.dg/attributes/proto-attribute-2.mm | 33 ++++++++++++ .../obj-c++.dg/attributes/proto-attribute-3.mm | 62 ++++++++++++++++++++++ .../obj-c++.dg/attributes/proto-attribute-4.mm | 31 +++++++++++ .../obj-c++.dg/attributes/unused-parameter-1.mm | 50 +++++++++++++++++ 23 files changed, 762 insertions(+) create mode 100644 gcc/testsuite/obj-c++.dg/attributes/attributes.exp create mode 100644 gcc/testsuite/obj-c++.dg/attributes/categ-attribute-1.mm create mode 100644 gcc/testsuite/obj-c++.dg/attributes/categ-attribute-2.mm create mode 100644 gcc/testsuite/obj-c++.dg/attributes/class-attribute-1.mm create mode 100644 gcc/testsuite/obj-c++.dg/attributes/class-attribute-2.mm create mode 100644 gcc/testsuite/obj-c++.dg/attributes/class-attribute-3.mm create mode 100644 gcc/testsuite/obj-c++.dg/attributes/invalid-attribute-1.mm create mode 100644 gcc/testsuite/obj-c++.dg/attributes/method-attribute-1.mm create mode 100644 gcc/testsuite/obj-c++.dg/attributes/method-attribute-2.mm create mode 100644 gcc/testsuite/obj-c++.dg/attributes/method-attribute-3.mm create mode 100644 gcc/testsuite/obj-c++.dg/attributes/method-deprecated-1.mm create mode 100644 gcc/testsuite/obj-c++.dg/attributes/method-deprecated-2.mm create mode 100644 gcc/testsuite/obj-c++.dg/attributes/method-deprecated-3.mm create mode 100644 gcc/testsuite/obj-c++.dg/attributes/method-format-1.mm create mode 100644 gcc/testsuite/obj-c++.dg/attributes/method-noreturn-1.mm create mode 100644 gcc/testsuite/obj-c++.dg/attributes/method-sentinel-1.mm create mode 100644 gcc/testsuite/obj-c++.dg/attributes/parameter-attribute-1.mm create mode 100644 gcc/testsuite/obj-c++.dg/attributes/parameter-attribute-2.mm create mode 100644 gcc/testsuite/obj-c++.dg/attributes/proto-attribute-1.mm create mode 100644 gcc/testsuite/obj-c++.dg/attributes/proto-attribute-2.mm create mode 100644 gcc/testsuite/obj-c++.dg/attributes/proto-attribute-3.mm create mode 100644 gcc/testsuite/obj-c++.dg/attributes/proto-attribute-4.mm create mode 100644 gcc/testsuite/obj-c++.dg/attributes/unused-parameter-1.mm (limited to 'gcc/testsuite/obj-c++.dg/attributes') diff --git a/gcc/testsuite/obj-c++.dg/attributes/attributes.exp b/gcc/testsuite/obj-c++.dg/attributes/attributes.exp new file mode 100644 index 000000000..1d4cae4ef --- /dev/null +++ b/gcc/testsuite/obj-c++.dg/attributes/attributes.exp @@ -0,0 +1,43 @@ +# 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 +# . + +# Load support procs. +load_lib obj-c++-dg.exp + +# If a testcase doesn't have special options, use these. +global DEFAULT_OBJCXXFLAGS +if ![info exists DEFAULT_OBJCXXFLAGS] then { + set DEFAULT_OBJCXXFLAGS " -ansi -pedantic-errors -Wno-long-long" +} + +# Initialize `dg'. +dg-init + +# Gather a list of all tests. +set tests [lsort [glob -nocomplain $srcdir/$subdir/*.mm]] + +# Main loop. +dg-runtest $tests "-fgnu-runtime" $DEFAULT_OBJCXXFLAGS + +# darwin targets can also run code with the NeXT runtime. +if [istarget "*-*-darwin*" ] { + dg-runtest $tests "-fnext-runtime" $DEFAULT_OBJCXXFLAGS +} + +# All done. +dg-finish diff --git a/gcc/testsuite/obj-c++.dg/attributes/categ-attribute-1.mm b/gcc/testsuite/obj-c++.dg/attributes/categ-attribute-1.mm new file mode 100644 index 000000000..6c48e0ad1 --- /dev/null +++ b/gcc/testsuite/obj-c++.dg/attributes/categ-attribute-1.mm @@ -0,0 +1,31 @@ +/* { dg-do compile } */ + +#include +#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) /* { dg-warning "category attributes are not available in this version" } */ +- (int) depmth; +@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/obj-c++.dg/attributes/categ-attribute-2.mm b/gcc/testsuite/obj-c++.dg/attributes/categ-attribute-2.mm new file mode 100644 index 000000000..d2fb78913 --- /dev/null +++ b/gcc/testsuite/obj-c++.dg/attributes/categ-attribute-2.mm @@ -0,0 +1,32 @@ +/* { dg-do compile } */ + +#include +#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) /* { dg-warning "category attributes are not available in this version" } */ +- (int) depmth; +@end + +__attribute__ ((deprecated)) +@implementation obj (dep_categ) /* { dg-warning "prefix attributes are ignored before" } */ +- (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/obj-c++.dg/attributes/class-attribute-1.mm b/gcc/testsuite/obj-c++.dg/attributes/class-attribute-1.mm new file mode 100644 index 000000000..f078339b8 --- /dev/null +++ b/gcc/testsuite/obj-c++.dg/attributes/class-attribute-1.mm @@ -0,0 +1,61 @@ +/* { dg-do compile } */ +/* { dg-skip-if "No API#2 pre-Darwin9" { *-*-darwin[5-8]* } { "-fnext-runtime" } { "" } } */ + +/* Test deprecate attribute with an @interface declaration. */ + +#include +#include + +__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) /* { dg-warning "is deprecated" } */ +@end + +@interface Subclass : DeprecatedClass /* { dg-warning "is deprecated" } */ +@end + +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/obj-c++.dg/attributes/class-attribute-2.mm b/gcc/testsuite/obj-c++.dg/attributes/class-attribute-2.mm new file mode 100644 index 000000000..35015c037 --- /dev/null +++ b/gcc/testsuite/obj-c++.dg/attributes/class-attribute-2.mm @@ -0,0 +1,21 @@ +/* { dg-do compile } */ + +#include + +__attribute__ ((deprecated)) +@interface DeprecatedClass +{ + Class isa; +} ++ (id) new; +@end + +__attribute__ ((deprecated)) +@implementation DeprecatedClass /* { dg-warning "prefix attributes are ignored" } */ ++ (id) new { return nil; } +@end + +void function (void) +{ + DeprecatedClass *object = [DeprecatedClass new]; /* { dg-warning "is deprecated" } */ +} diff --git a/gcc/testsuite/obj-c++.dg/attributes/class-attribute-3.mm b/gcc/testsuite/obj-c++.dg/attributes/class-attribute-3.mm new file mode 100644 index 000000000..f96500de4 --- /dev/null +++ b/gcc/testsuite/obj-c++.dg/attributes/class-attribute-3.mm @@ -0,0 +1,14 @@ +/* Contributed by Nicola Pero , December 2010. */ +/* { dg-do compile } */ + +/* Test that you get a warning when an unknown class attribute is ignored. */ + +#include + +__attribute__ ((unknown_attribute)) +@interface MyClass /* { dg-warning "ignored" } */ +{ + Class isa; +} ++ (id) new; +@end diff --git a/gcc/testsuite/obj-c++.dg/attributes/invalid-attribute-1.mm b/gcc/testsuite/obj-c++.dg/attributes/invalid-attribute-1.mm new file mode 100644 index 000000000..96ee178d7 --- /dev/null +++ b/gcc/testsuite/obj-c++.dg/attributes/invalid-attribute-1.mm @@ -0,0 +1,6 @@ +/* Contributed by Nicola Pero , January 2011. */ +/* { dg-do compile } */ + +#include + +__attribute__ ((deprecated)) @class A; /* { dg-error "attributes may not be specified before the ..class. Objective-C.. keyword" } */ diff --git a/gcc/testsuite/obj-c++.dg/attributes/method-attribute-1.mm b/gcc/testsuite/obj-c++.dg/attributes/method-attribute-1.mm new file mode 100644 index 000000000..747deab0d --- /dev/null +++ b/gcc/testsuite/obj-c++.dg/attributes/method-attribute-1.mm @@ -0,0 +1,40 @@ +/* { dg-do compile } */ + +#include +#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 "method attributes must be specified at the end " } */ +- (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/obj-c++.dg/attributes/method-attribute-2.mm b/gcc/testsuite/obj-c++.dg/attributes/method-attribute-2.mm new file mode 100644 index 000000000..4a56b3aa8 --- /dev/null +++ b/gcc/testsuite/obj-c++.dg/attributes/method-attribute-2.mm @@ -0,0 +1,33 @@ +/* { dg-do compile } */ + +#include +#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/obj-c++.dg/attributes/method-attribute-3.mm b/gcc/testsuite/obj-c++.dg/attributes/method-attribute-3.mm new file mode 100644 index 000000000..bab40d342 --- /dev/null +++ b/gcc/testsuite/obj-c++.dg/attributes/method-attribute-3.mm @@ -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/obj-c++.dg/attributes/method-deprecated-1.mm b/gcc/testsuite/obj-c++.dg/attributes/method-deprecated-1.mm new file mode 100644 index 000000000..8343856a5 --- /dev/null +++ b/gcc/testsuite/obj-c++.dg/attributes/method-deprecated-1.mm @@ -0,0 +1,33 @@ +/* Contributed by Nicola Pero , October 2010. */ +/* { dg-do compile } */ + +#include + +@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/obj-c++.dg/attributes/method-deprecated-2.mm b/gcc/testsuite/obj-c++.dg/attributes/method-deprecated-2.mm new file mode 100644 index 000000000..1e5d87f3e --- /dev/null +++ b/gcc/testsuite/obj-c++.dg/attributes/method-deprecated-2.mm @@ -0,0 +1,23 @@ +/* Contributed by Nicola Pero , October 2010. */ +/* { dg-do compile } */ + +#include + +@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/obj-c++.dg/attributes/method-deprecated-3.mm b/gcc/testsuite/obj-c++.dg/attributes/method-deprecated-3.mm new file mode 100644 index 000000000..5c715a20b --- /dev/null +++ b/gcc/testsuite/obj-c++.dg/attributes/method-deprecated-3.mm @@ -0,0 +1,21 @@ +/* Contributed by Nicola Pero , October 2010. */ +/* { dg-do compile } */ + +#include + +/* 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/obj-c++.dg/attributes/method-format-1.mm b/gcc/testsuite/obj-c++.dg/attributes/method-format-1.mm new file mode 100644 index 000000000..11ce8eebb --- /dev/null +++ b/gcc/testsuite/obj-c++.dg/attributes/method-format-1.mm @@ -0,0 +1,43 @@ +/* Contributed by Nicola Pero , October 2010. */ +/* { dg-do compile } */ +/* { dg-options "-Wall" } */ + +#include +#include + +@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/obj-c++.dg/attributes/method-noreturn-1.mm b/gcc/testsuite/obj-c++.dg/attributes/method-noreturn-1.mm new file mode 100644 index 000000000..717d6e65e --- /dev/null +++ b/gcc/testsuite/obj-c++.dg/attributes/method-noreturn-1.mm @@ -0,0 +1,34 @@ +/* Contributed by Nicola Pero , October 2010. */ +/* { dg-do compile } */ + +#include +#include + +@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/obj-c++.dg/attributes/method-sentinel-1.mm b/gcc/testsuite/obj-c++.dg/attributes/method-sentinel-1.mm new file mode 100644 index 000000000..2b8e6fd25 --- /dev/null +++ b/gcc/testsuite/obj-c++.dg/attributes/method-sentinel-1.mm @@ -0,0 +1,36 @@ +/* Contributed by Nicola Pero , October 2010. */ +/* { dg-do compile } */ +/* { dg-options "-Wall" } */ + +#include +#include +/* Ensure a compatible definition of nil. */ +#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/obj-c++.dg/attributes/parameter-attribute-1.mm b/gcc/testsuite/obj-c++.dg/attributes/parameter-attribute-1.mm new file mode 100644 index 000000000..a4ba25943 --- /dev/null +++ b/gcc/testsuite/obj-c++.dg/attributes/parameter-attribute-1.mm @@ -0,0 +1,45 @@ +/* Test __attribute__((unused)) for an Objective-C method parameter. */ +/* { dg-do compile } */ +/* { dg-options "-Wunused-parameter" } */ + +#include + +@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/obj-c++.dg/attributes/parameter-attribute-2.mm b/gcc/testsuite/obj-c++.dg/attributes/parameter-attribute-2.mm new file mode 100644 index 000000000..3908faf99 --- /dev/null +++ b/gcc/testsuite/obj-c++.dg/attributes/parameter-attribute-2.mm @@ -0,0 +1,25 @@ +/* Test that we get warnings for unrecognized attributes. */ +/* { dg-do compile } */ + +#include + +@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/obj-c++.dg/attributes/proto-attribute-1.mm b/gcc/testsuite/obj-c++.dg/attributes/proto-attribute-1.mm new file mode 100644 index 000000000..a852a7a6c --- /dev/null +++ b/gcc/testsuite/obj-c++.dg/attributes/proto-attribute-1.mm @@ -0,0 +1,21 @@ +/* { dg-do compile } */ + +#include + +__attribute ((deprecated)) +@protocol dep_proto +- (int) depprotomth; +@end + +@interface obj /* { 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/obj-c++.dg/attributes/proto-attribute-2.mm b/gcc/testsuite/obj-c++.dg/attributes/proto-attribute-2.mm new file mode 100644 index 000000000..aba58ff33 --- /dev/null +++ b/gcc/testsuite/obj-c++.dg/attributes/proto-attribute-2.mm @@ -0,0 +1,33 @@ +/* Contributed by Nicola Pero , November 2010. */ +/* { dg-do compile } */ +/* { dg-skip-if "No API#2 pre-Darwin9" { *-*-darwin[5-8]* } { "-fnext-runtime" } { "" } } */ + +/* Test deprecate attribute with a forward declarations of + @protocol. */ + +#include +#include +#include + +__attribute__ ((deprecated)) +@protocol DeprecatedProtocol1; + +@protocol NonDeprecatedProtocol1; + +void function1 (id object); /* { dg-warning "is deprecated" } */ +void function2 (id object); + +@class Class4; + +void function3 (Class4 *object); /* { dg-warning "is deprecated" } */ +void function4 (Class4 *object); +void function5 (Class4 *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/obj-c++.dg/attributes/proto-attribute-3.mm b/gcc/testsuite/obj-c++.dg/attributes/proto-attribute-3.mm new file mode 100644 index 000000000..fc5251eee --- /dev/null +++ b/gcc/testsuite/obj-c++.dg/attributes/proto-attribute-3.mm @@ -0,0 +1,62 @@ +/* Contributed by Nicola Pero , November 2010. */ +/* { dg-do compile } */ +/* { dg-skip-if "No API#2 pre-Darwin9" { *-*-darwin[5-8]* } { "-fnext-runtime" } { "" } } */ + + +/* Test deprecate attribute with normal @protocol declarations. */ + + +#include +#include +#include + +__attribute__ ((deprecated)) +@protocol DeprecatedProtocol1 +- (void) aMethod; +@end + +@protocol NonDeprecatedProtocol1 +- (void) anotherMethod; +@end + +@protocol Protocol2 /* { dg-warning "is deprecated" } */ +- (void) someOtherMethod; +@end + +@protocol Protocol3 +- (void) someOtherMethod2; +@end + +@protocol Protocol4 /* { dg-warning "is deprecated" } */ +- (void) someOtherMethod3; +@end + + +@interface Class1 /* { dg-warning "is deprecated" } */ +@end + +@interface Class2 +@end + +@interface Class3 /* { dg-warning "is deprecated" } */ +@end + +@interface Class2 (Category1) /* { dg-warning "is deprecated" } */ +@end + +void function1 (id object); /* { dg-warning "is deprecated" } */ +void function2 (id object); + +@class Class4; + +void function3 (Class4 *object); /* { dg-warning "is deprecated" } */ +void function4 (Class4 *object); +void function5 (Class4 *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/obj-c++.dg/attributes/proto-attribute-4.mm b/gcc/testsuite/obj-c++.dg/attributes/proto-attribute-4.mm new file mode 100644 index 000000000..d2e5f28a1 --- /dev/null +++ b/gcc/testsuite/obj-c++.dg/attributes/proto-attribute-4.mm @@ -0,0 +1,31 @@ +/* Contributed by Nicola Pero , December 2010. */ +/* { dg-do compile } */ + +/* Test that you get a warning when an unknown protocol attribute is ignored. */ + +#include + +__attribute__ ((unknown_attribute)) +@protocol MyProtocol /* { dg-warning "ignored" } */ +- (id) new; +@end + +__attribute__ ((unknown_attribute)) +@protocol MyProtocol2; /* { dg-warning "ignored" } */ + +/* Use the protocols to double-check that no more warnings are + generated. */ + +@interface MyClass +@end + +int test (id x) +{ + if (@protocol (MyProtocol) == @protocol (MyProtocol2)) + return 1; + + if (x) + return 2; + + return 3; +} diff --git a/gcc/testsuite/obj-c++.dg/attributes/unused-parameter-1.mm b/gcc/testsuite/obj-c++.dg/attributes/unused-parameter-1.mm new file mode 100644 index 000000000..8fbb11e20 --- /dev/null +++ b/gcc/testsuite/obj-c++.dg/attributes/unused-parameter-1.mm @@ -0,0 +1,50 @@ +/* { dg-do compile } */ + +#include + +@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; +- (id) method6: (id) argument1 + andArgument: (id) argument2; +@end + +@implementation MyRootClass +- (id) method1: (id) argument1 +{ + return nil; +} +- (id) method2: (id) __attribute__((unused)) argument1 +{ + return nil; +} +- (id) method3: (id) __attribute__((unused)) argument1 + andArgument: (id) 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 +{ + return nil; +} +- (id) method6: (id) argument1 + andArgument: (id) argument2 +{ + return nil; +} +@end -- cgit v1.2.3