File tree Expand file tree Collapse file tree 6 files changed +106
-0
lines changed Expand file tree Collapse file tree 6 files changed +106
-0
lines changed Original file line number Diff line number Diff line change
1
+ macro_rules! zero_or_one {
2
+ ( $( $a: literal) ?) => { // { dg-error "invalid amount of matches for macro invocation. Expected between 0 and 1, got 2" }
3
+ f( )
4
+ }
5
+ }
6
+
7
+ fn main ( ) {
8
+ zero_or_one ! ( ) ;
9
+ zero_or_one ! ( 14 ) ;
10
+ zero_or_one ! ( 125 12 "gcc" ) ; // { dg-error "Failed to match any rule within macro" }
11
+ }
Original file line number Diff line number Diff line change
1
+ fn f ( ) { }
2
+
3
+ macro_rules! one_or_more {
4
+ ( $( $a: literal) +) => { // { dg-error "invalid amount of matches for macro invocation" }
5
+ f( )
6
+ }
7
+ }
8
+
9
+ fn main ( ) {
10
+ one_or_more ! ( 1 1 1 1 1 1 1 1 1 1 1 "rust" 'c' ) ;
11
+ one_or_more ! ( 1 ) ;
12
+ one_or_more ! ( ) ; // { dg-error "Failed to match any rule within macro" }
13
+ }
Original file line number Diff line number Diff line change
1
+ fn f ( ) { }
2
+
3
+ macro_rules! expr {
4
+ ( $( $a: expr) ?) => {
5
+ f( )
6
+ }
7
+ }
8
+
9
+ fn main ( ) {
10
+ expr ! ( ) ;
11
+ expr ! ( 14 ) ;
12
+ }
Original file line number Diff line number Diff line change
1
+ // { dg-output "any\nany\nany\nany\nany\n" }
2
+ extern "C" {
3
+ fn printf ( s : * const i8 , ...) ;
4
+ }
5
+
6
+ fn f ( ) {
7
+ let r_s = "any\n \0 " ;
8
+ let s_p = r_s as * const str ;
9
+ let c_p = s_p as * const i8 ;
10
+
11
+ printf ( c_p) ;
12
+ }
13
+
14
+ macro_rules! any {
15
+ ( $( $a: expr) * ) => {
16
+ $( $a; ) *
17
+ }
18
+ }
19
+
20
+ fn main ( ) {
21
+ any ! ( ) ; // valid, but does not print anything
22
+ any ! ( f( ) f( ) ) ;
23
+ any ! ( f( ) f( ) f( ) ) ;
24
+ }
Original file line number Diff line number Diff line change
1
+ // { dg-output "zo1\nzo1\n" }
2
+ extern "C" {
3
+ fn printf ( s : * const i8 , ...) ;
4
+ }
5
+
6
+ fn f ( ) {
7
+ let r_s = "zo1\n \0 " ;
8
+ let s_p = r_s as * const str ;
9
+ let c_p = s_p as * const i8 ;
10
+
11
+ unsafe { printf ( c_p) ; }
12
+ }
13
+
14
+ macro_rules! zero_or_one {
15
+ ( $( $a: expr) ?) => {
16
+ f( )
17
+ }
18
+ }
19
+
20
+ fn main ( ) {
21
+ zero_or_one ! ( ) ;
22
+ zero_or_one ! ( f( ) ) ;
23
+ }
Original file line number Diff line number Diff line change
1
+ // { dg-output "oom\noom\noom\n" }
2
+ extern "C" {
3
+ fn printf ( s : * const i8 , ...) ;
4
+ }
5
+
6
+ fn f ( ) {
7
+ let r_s = "oom\n \0 " ;
8
+ let s_p = r_s as * const str ;
9
+ let c_p = s_p as * const i8 ;
10
+
11
+ unsafe { printf ( c_p) ; }
12
+ }
13
+
14
+ macro_rules! one_or_more {
15
+ ( $( $a: expr) +) => {
16
+ $( $a; ) +
17
+ }
18
+ }
19
+
20
+ fn main ( ) {
21
+ one_or_more ! ( f( ) ) ;
22
+ one_or_more ! ( f( ) f( ) ) ;
23
+ }
You can’t perform that action at this time.
0 commit comments