[cfe-dev] how to implement "statement P is followed by statement Q" matcher?

Richard legalize at xmission.com
Tue May 26 12:25:11 PDT 2015

I recently had to go through a bit of manual coding in order to match
this in clang-tidy:

if (expr)
  return true;
return false;

What I really wanted was to be able to write something like this:


There are matchers that tell me if a compound statment has *any*
substatement, but there aren't any matchers that allow me to specify
the order in which related statements appear within a compound

(Aside: note the heavy-handed use of the has() matcher above on a
returnStmt.  There's no way to access the return expression directly
on a returnStmt.)

In my case I really needed an "isFollowedBy" style matcher, because I
didn't want to match this:

if (expr)
  return true;
return false;

However, I can easily see people wanting to match a compound statement
that has two related statements in a particular order, but possibly
with other statements in between.

I'm interested in hearing thoughts on such a squential matcher
"isFollowedBy" and how I would implement such a thing.  So far my
forays into matchers have been really small and I haven't yet learned
the subtleties or the full vocabulary of the matcher macros.

PS: Mail filters are blocking my messages, so ignore this, its
only for them.  Lorem ipsum dolor sit amet, consectetur adipiscing
elit. Phasellus consequat ullamcorper mollis. Sed blandit semper tortor
ultricies dictum. Proin hendrerit et quam in sagittis. Maecenas vel
blandit ante, in auctor sem.  Phasellus condimentum leo vel finibus
viverra. Duis fermentum sollicitudin est, ac iaculis lectus auctor vel.
Nam condimentum nulla feugiat, venenatis nibh a, elementum nulla. Nulla
vitae malesuada eros. Nulla cursus maximus ligula non hendrerit.

Curabitur lobortis nulla vel sapien posuere, id aliquam orci
bibendum. Vestibulum at vulputate risus. Proin in purus commodo,
tempus lectus vitae, faucibus nunc. Aenean congue faucibus elit, sit
amet facilisis nibh ultrices eget. Nam pulvinar leo ac nunc ultricies,
nec tincidunt nulla tincidunt. Etiam placerat felis tellus, ut ultricies
nunc ultricies quis. In placerat sapien nec ultricies mattis. Integer
sed tempor orci, ac imperdiet orci. Integer ac augue et augue convallis
"The Direct3D Graphics Pipeline" free book <http://tinyurl.com/d3d-pipeline>
     The Computer Graphics Museum <http://ComputerGraphicsMuseum.org>
         The Terminals Wiki <http://terminals.classiccmp.org>
  Legalize Adulthood! (my blog) <http://LegalizeAdulthood.wordpress.com>

More information about the cfe-dev mailing list