<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div class="">I believe the best you can do is to convert the string to an IdentifierInfo and access hadMacroDefinition:</div>```<div class=""><font face="Menlo" class="">IdentifierInfo &FooII = Context.Idents.get("Foo");<br class="">bool FooMaybeMacroName = FooII.hadMacroDefinition();</font></div><div class="">```</div><div class="">This won’t be perfect — it won’t tell you whether Foo was defined at the particular SourceLocation you are interested in, only whether at some point in the TU a macro with that name was defined.</div><div class=""><br class=""></div><div class="">It would be nice to be able to test `FooII.hasMacroDefinition()` instead, but the problem mentioned in the other thread rears its head here too: the AST matching on which clang tidy depends is all done during HandleTranslationUnit, *after* all parsing has completed, so hasMacroDefinition() will only return true if a macro with that name was not #undef’d.  <br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On Jan 6, 2022, at 7:39 PM, Richard via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org" class="">cfe-dev@lists.llvm.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="">Hi Team,<br class=""><br class="">Preprocessor::isMacroDefined seems to be what I want, but how can I<br class="">access the active preprocesor from inside a clang-tidy check?<br class=""><br class="">Currently I have a check that walks over a declaration string with the<br class="">Lexer.  A bug was filed that this check had a negative interaction<br class="">with macros (no surprise).  I've got a hacked up solution that passes<br class="">my test cases, but it would be really nice to know if a raw_id token I<br class="">just encountered while lexing the declaration is the name of a macro.<br class=""><br class="">For context, see:<br class="">Lexing state machine<br class=""><<a href="https://github.com/llvm/llvm-project/blob/main/clang-tools-extra/clang-tidy/modernize/RedundantVoidArgCheck.cpp#L118" class="">https://github.com/llvm/llvm-project/blob/main/clang-tools-extra/clang-tidy/modernize/RedundantVoidArgCheck.cpp#L118</a>><br class="">bug<br class=""><<a href="https://github.com/llvm/llvm-project/issues/43791" class="">https://github.com/llvm/llvm-project/issues/43791</a>><br class=""><br class="">Thanks,<br class=""><br class="">-- Richard<br class="">-- <br class="">"The Direct3D Graphics Pipeline" free book <<a href="http://tinyurl.com/d3d-pipeline" class="">http://tinyurl.com/d3d-pipeline</a>><br class="">             The Terminals Wiki <<a href="http://terminals-wiki.org" class="">http://terminals-wiki.org</a>><br class="">     The Computer Graphics Museum <<a href="http://ComputerGraphicsMuseum.org" class="">http://ComputerGraphicsMuseum.org</a>><br class="">  Legalize Adulthood! (my blog) <<a href="http://LegalizeAdulthood.wordpress.com" class="">http://LegalizeAdulthood.wordpress.com</a>><br class="">_______________________________________________<br class="">cfe-dev mailing list<br class=""><a href="mailto:cfe-dev@lists.llvm.org" class="">cfe-dev@lists.llvm.org</a><br class="">https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev<br class=""></div></div></blockquote></div><br class=""></div></body></html>