macros: Check follow-set restrictions on matcher's first delimiter

This commit is contained in:
Arthur Cohen 2022-03-24 13:50:03 +01:00
parent 8283724bc2
commit 912b04216d
2 changed files with 24 additions and 3 deletions

View File

@ -202,9 +202,25 @@ peculiar_fragment_match_compatible (AST::MacroMatchFragment &last_match,
}
case AST::MacroMatch::Matcher: {
auto matcher = static_cast<AST::MacroMatcher *> (&match);
auto &matches = matcher->get_matches ();
if (!matches.empty ())
error_locus = matches.front ()->get_match_locus ();
auto first_token = matcher->get_delim_type ();
TokenId delim_id;
switch (first_token)
{
case AST::PARENS:
delim_id = LEFT_PAREN;
break;
case AST::SQUARE:
delim_id = LEFT_SQUARE;
break;
case AST::CURLY:
delim_id = LEFT_CURLY;
break;
}
if (contains (allowed_toks, delim_id))
return true;
kind_str = "token `" + std::string (get_token_description (delim_id))
+ "` at start of matcher";
error_locus = matcher->get_match_locus ();
break;
}
case AST::MacroMatch::Fragment: {

View File

@ -0,0 +1,5 @@
macro_rules! m {
($e:expr (, parenthesis_forbidden)) => {{}}; // { dg-error "token .\\(. at start of matcher is not allowed after .expr. fragment" }
// { dg-error "required first macro rule" "" { target *-*-* } .-1 }
// { dg-error "failed to parse item in crate" "" { target *-*-* } .-2 }
}