[cfe-dev] [Clang-tidy] Detecting if a catch was done by const ref

Aaron Ballman via cfe-dev cfe-dev at lists.llvm.org
Mon Mar 12 12:39:43 PDT 2018


On Mon, Mar 12, 2018 at 3:34 PM, Richard via cfe-dev
<cfe-dev at lists.llvm.org> wrote:
> [Please reply *only* to the list and do not include my email directly
> in the To: or Cc: of your reply; otherwise I will not see your reply.
> Thanks.]
>
> In article <CAAt6xTvjSPEg7OVPWVbtqWdsDp5zja9_TfLTkdzoNoksmEr=KQ at mail.gmail.com>,
>     Aaron Ballman via cfe-dev <cfe-dev at lists.llvm.org> writes:
>
>> I believe the matcher you're looking for is:
>> varDecl(hasType(references(qualType(isConstQualified()))))
>>
>> For example, given:
>>
>> void f1() {
>>   try {
>>   } catch (int &e) {
>>   }
>> }
>>
>> void f2() {
>>   try {
>>   } catch (const int &e) {
>>   }
>> }
>>
>> produces:
>>
>> clang-query> match
>> varDecl(hasType(references(qualType(isConstQualified()))))
>>
>> Match #1:
>>
>> C:\Users\Aaron\Desktop\test.cpp:9:12: note: "root" binds here
>>   } catch (const int &e) {
>>            ^~~~~~~~~~~~
>> 1 match.
>
> I think they want to match the catches that aren't const qualified, so
> it might be (untested):
>
> varDecl(hasType(references(qualType(not(isConstQualified())))))

Ah, oops, I didn't see that I had the predicate reversed. Your matcher
is close, but instead of not(), you use unless().

~Aaron

> --
> "The Direct3D Graphics Pipeline" free book <http://tinyurl.com/d3d-pipeline>
>             The Terminals Wiki <http://terminals-wiki.org>
>      The Computer Graphics Museum <http://ComputerGraphicsMuseum.org>
>   Legalize Adulthood! (my blog) <http://LegalizeAdulthood.wordpress.com>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev



More information about the cfe-dev mailing list