diff mbox series

[pusshed] testsuite, Objective-c++ : Update diagnostic plugin test.

Message ID CE062708-E063-433F-A32D-97BA084B1E8B@sandoe.co.uk
State New
Headers show
Series [pusshed] testsuite, Objective-c++ : Update diagnostic plugin test. | expand

Commit Message

Iain Sandoe Oct. 11, 2020, 4:19 p.m. UTC
Hi

The @selector() and @protocol() operators produce var decls
these do not work with the example plugin.  Unfortunately,
unlike the ObjC front end, it is not so easy to construct a
substitute expression that works reliably.  Where it does not
work we xfail for now.

tested across the Darwin range, and on x86_64-linux
pushed to master
thanks
Iain

gcc/testsuite/ChangeLog:

	* obj-c++.dg/plugin/diagnostic-test-expressions-1.mm:
	Adjust testcase to include expressions for @selector and
	@protocol. XFAIL where this is still not sufficient to obtain
	a disgnostic range.
---
 .../plugin/diagnostic-test-expressions-1.mm   | 33 +++++++++++++------
 1 file changed, 23 insertions(+), 10 deletions(-)
diff mbox series

Patch

diff --git a/gcc/testsuite/obj-c++.dg/plugin/diagnostic-test-expressions-1.mm b/gcc/testsuite/obj-c++.dg/plugin/diagnostic-test-expressions-1.mm
index 609fe3d0f93..988b290ce69 100644
--- a/gcc/testsuite/obj-c++.dg/plugin/diagnostic-test-expressions-1.mm
+++ b/gcc/testsuite/obj-c++.dg/plugin/diagnostic-test-expressions-1.mm
@@ -1,10 +1,13 @@ 
 /* { dg-do compile } */
 /* { dg-options "-O -fdiagnostics-show-caret" } */
+/* { dg-excess-errors "tree range 0:0-0:0" { target { *-*-darwin* } } }  */
 
 /* This file is similar to diagnostic-test-expressions-1.c
    (see the notes in that file); this file adds test
    coverage for various Objective C constructs. */
 
+#include <objc/runtime.h> /* for SEL, Protocol */
+
 extern void __emit_expression_range (int dummy, ...);
 
 @protocol prot
@@ -17,7 +20,7 @@  extern void __emit_expression_range (int dummy, ...);
 - (void) test_sending_messages;
 + (void) test_class_dot_name;
 - (void) test_at_selector;
-- (void) test_at_protocol;
+- (void) test_at_protocol:(int)i;
 - (void) test_at_encode:(int)i;
 @end
 
@@ -49,27 +52,37 @@  extern void __emit_expression_range (int dummy, ...);
 }
 + (void) test_class_dot_name
 {
-  __emit_expression_range ( 0, tests.func2 ); /* { dg-warning "range" } */
+  __emit_expression_range ( 0, tests.func2 ); /* { dg-warning "range"  } */
 /* { dg-begin-multiline-output "" }
    __emit_expression_range ( 0, tests.func2 );
                                 ~~~~~~^~~~~
-   { dg-end-multiline-output "" } */
+   { dg-end-multiline-output ""  } */
 }
 - (void) test_at_selector
 {
-  __emit_expression_range ( 0, @selector(func0) ); /* { dg-warning "range" } */
+  /* For the NeXT runtime, @selector() generates a a var decl which (a) isn't
+     handled by the plugin, and (b) if it was would not necessarily have the
+     right location (there is only one var decl uniqued to each selector 
+     spelling, so the location would be that of the first occurrence).  Use an
+     assignment expression to test the operation.  This isn't reliable here,
+     unfortunately.  */
+  SEL aSel;
+  __emit_expression_range ( 0, aSel = @selector(foo) ); /* { dg-warning "range" } */
 /* { dg-begin-multiline-output "" }
-   __emit_expression_range ( 0, @selector(func0) );
-                                ^~~~~~~~~~~~~~~~
-   { dg-end-multiline-output "" } */
+   __emit_expression_range ( 0, aSel = @selector(foo) );
+                                ~~~~~^~~~~~~~~~~~~~~~
+   { dg-end-multiline-output "" { xfail { *-*-darwin* } } } */
 }
-- (void) test_at_protocol
+- (void) test_at_protocol:(int)i
 {
-  __emit_expression_range ( 0, @protocol(prot) ); /* { dg-warning "range" } */
+  /* As for @selector(), the NeXT runtime generates a a var decl for
+     @protocol();  Unfortunately, we can't so easily fabricate a mechanism to
+     handle this (C++ FE turns the assignment op into a NOP).  */
+  __emit_expression_range ( 0, @protocol(prot) ); /* { dg-warning "range" "" { xfail { *-*-darwin* && lp64 } } } */
 /* { dg-begin-multiline-output "" }
    __emit_expression_range ( 0, @protocol(prot) );
                                 ^~~~~~~~~~~~~~~
-   { dg-end-multiline-output "" } */
+   { dg-end-multiline-output "" { xfail { *-*-darwin* && lp64 } } } */
 }
 - (void) test_at_encode:(int)i
 {