aboutsummaryrefslogtreecommitdiffstats
path: root/gcc-4.9/gcc/testsuite/obj-c++.dg/comp-types-5.mm
blob: 99f6772bd42eeb7742cc3189b147aaf0a1ad1f28 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/* Test errors for assignments and comparisons between ObjC and C++ types.  */
/* Author: Nicola Pero <nicola@brainstorm.co.uk>.  */
/* { dg-do compile } */

#include <objc/objc.h>

/* The NeXT runtime headers do not define NULL.  */
#ifndef NULL
#define NULL ((void *)0)
#endif

@protocol MyProtocol
- (void) method;
@end

@interface MyClass
@end

int main()
{
  id obj = nil;
  id <MyProtocol> obj_p = nil;
  MyClass *obj_c = nil;
  Class obj_C = Nil;
  
  int i = 0;
  int *j = (int *)NULL;

  /* These should all generate warnings.  */
  
  obj = i; /* { dg-error "invalid conversion" } */
  obj = j; /* { dg-error "cannot convert" } */

  obj_p = i; /* { dg-error "invalid conversion" } */
  obj_p = j; /* { dg-error "cannot convert" } */
  
  obj_c = i; /* { dg-error "invalid conversion" } */
  obj_c = j; /* { dg-error "cannot convert" } */

  obj_C = i; /* { dg-error "invalid conversion" } */
  obj_C = j; /* { dg-error "cannot convert" } */
  
  i = obj;   /* { dg-error "invalid conversion" } */
  i = obj_p; /* { dg-error "invalid conversion" } */
  i = obj_c; /* { dg-error "invalid conversion" } */
  i = obj_C; /* { dg-error "invalid conversion" } */
  
  j = obj;   /* { dg-error "cannot convert" } */
  j = obj_p; /* { dg-error "cannot convert" } */
  j = obj_c; /* { dg-error "cannot convert" } */
  j = obj_C; /* { dg-error "cannot convert" } */
  
  if (obj == i) ; /* { dg-error "comparison between pointer and integer" } */
  if (i == obj) ; /* { dg-error "comparison between pointer and integer" } */
  if (obj == j) ; /* { dg-error "lacks a cast" } */
  if (j == obj) ; /* { dg-error "lacks a cast" } */

  if (obj_c == i) ; /*{ dg-error "comparison between pointer and integer" }*/
  if (i == obj_c) ; /*{ dg-error "comparison between pointer and integer" }*/
  if (obj_c == j) ; /* { dg-error "lacks a cast" } */
  if (j == obj_c) ; /* { dg-error "lacks a cast" } */

  if (obj_p == i) ; /*{ dg-error "comparison between pointer and integer" }*/
  if (i == obj_p) ; /*{ dg-error "comparison between pointer and integer" }*/
  if (obj_p == j) ; /* { dg-error "lacks a cast" } */
  if (j == obj_p) ; /* { dg-error "lacks a cast" } */

  if (obj_C == i) ; /*{ dg-error "comparison between pointer and integer" }*/
  if (i == obj_C) ; /*{ dg-error "comparison between pointer and integer" }*/
  if (obj_C == j) ; /* { dg-error "lacks a cast" } */
  if (j == obj_C) ; /* { dg-error "lacks a cast" } */

  return 0;
}