Debian Codegraph @

gcc/testsuite/obj-c++.dg/plugin/diagnostic-test-expressions-1.mm

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