Debian Codegraph @

gcc/testsuite/objc.dg/plugin/diagnostic-test-expressions-1.m

raw
1 /* { dg-do compile } */
2 /* { dg-options "-O -fdiagnostics-show-caret -Wno-objc-root-class" } */
3
4 /* This file is similar to diagnostic-test-expressions-1.c
5 (see the notes in that file); this file adds test
6 coverage for various Objective C constructs. */
7
8 #include <objc/runtime.h> /* for SEL, Protocol */
9
10 extern void __emit_expression_range (int dummy, ...);
11
12 @protocol prot
13 @end
14
15 @interface tests <prot>
16 - (int) func0;
17 - (int) func1:(int)i;
18 + (int) func2;
19 - (void) test_sending_messages;
20 + (void) test_class_dot_name;
21 - (void) test_at_selector;
22 - (void) test_at_protocol;
23 - (void) test_at_encode:(int)i;
24 @end
25
26 @implementation tests
27 - (int) func0
28 {
29 return 42;
30 }
31 - (int) func1:(int)i
32 {
33 return i * i;
34 }
35 + (int) func2
36 {
37 return 0;
38 }
39 - (void) test_sending_messages
40 {
41 __emit_expression_range ( 0, [self func0] ); /* { dg-warning "range" } */
42 /* { dg-begin-multiline-output "" }
43 __emit_expression_range ( 0, [self func0] );
44 ~~~~~~~~~~~~
45 { dg-end-multiline-output "" } */
46 __emit_expression_range ( 0, [self func1:5] ); /* { dg-warning "range" } */
47 /* { dg-begin-multiline-output "" }
48 __emit_expression_range ( 0, [self func1:5] );
49 ~~~~~~~~~~~~~~
50 { dg-end-multiline-output "" } */
51 }
52 + (void) test_class_dot_name
53 {
54 __emit_expression_range ( 0, tests.func2 ); /* { dg-warning "range" } */
55 /* { dg-begin-multiline-output "" }
56 __emit_expression_range ( 0, tests.func2 );
57 ~~~~~~~~~~~
58 { dg-end-multiline-output "" } */
59 }
60
61 - (void) test_at_selector
62 {
63 /* For the NeXT runtime, @selector() generates a a var decl which (a) isn't
64 handled by the plugin, and (b) if it was would not necessarily have the
65 right location (there is only one var decl uniqued to each selector
66 spelling, so the location would be that of the first occurrence). Use an
67 assignment expression to test the operation. */
68 SEL aSel;
69 __emit_expression_range ( 0, aSel = @selector(foo) ); /* { dg-warning "range" } */
70 /* { dg-begin-multiline-output "" }
71 __emit_expression_range ( 0, aSel = @selector(foo) );
72 ~~~~~^~~~~~~~~~~~~~~~
73 { dg-end-multiline-output "" } */
74 }
75 - (void) test_at_protocol
76 {
77 /* As for @selector(), the NeXT runtime generates a a var decl for
78 @protocol() handle this in a similar way. */
79 Protocol *aProt;
80 __emit_expression_range ( 0, aProt = @protocol(prot) ); /* { dg-warning "range" "" } */
81 /* { dg-begin-multiline-output "" }
82 __emit_expression_range ( 0, aProt = @protocol(prot) );
83 ~~~~~~^~~~~~~~~~~~~~~~~
84 { dg-end-multiline-output "" } */
85 }
86
87 - (void) test_at_encode:(int)i
88 {
89 /* @encode() generates a STRING_CST which doesn't retain a location
90 after parsing, so we need to access it via compound expressions
91 that can't be folded away. */
92
93 /* Verify start. */
94 __emit_expression_range ( 0, @encode(int) + i ); /* { dg-warning "range" } */
95 /* { dg-begin-multiline-output "" }
96 __emit_expression_range ( 0, @encode(int) + i );
97 ~~~~~~~~~~~~~^~~
98 { dg-end-multiline-output "" } */
99
100 /* Verify finish. */
101 __emit_expression_range ( 0, i + @encode(int) ); /* { dg-warning "range" } */
102 /* { dg-begin-multiline-output "" }
103 __emit_expression_range ( 0, i + @encode(int) );
104 ~~^~~~~~~~~~~~~~
105 { dg-end-multiline-output "" } */
106 }
107 @end