[cfe-dev] clang ast: how do I find out whether a catch is done by const reference
Tobias Langner
randomcppprogrammer at gmail.com
Thu Jul 16 14:53:04 PDT 2015
yes, the result is the same. If someone wants a compilable example: https://github.com/iso8859-1/clang-tools-extra/tree/tobias-additional-checks <https://github.com/iso8859-1/clang-tools-extra/tree/tobias-additional-checks> (a reasonably new fork of the extra tools). The branch “tobias-additional-checks” contains the code.
Thank you
Tobias
>
> Do you get the same results if you look at the canonical type instead?
>
> auto QT = caughtType->getCaughtType().getCanonicalType();
> if (QT.isConstQualified() && QT->isLValueReferenceType()) ...
>
> ~Aaron
>
>>
>> Regards
>> Tobias
>>
>> auto *type = caughtType.getTypePtr();
>> auto *varDecl = catchStmt->getExceptionDecl();
>> if (type->isPointerType()) {
>> diag(varDecl->getLocStart(),
>> "catch by const reference instead of pointer");
>> } else if (!type->isReferenceType()) {
>> diag(varDecl->getLocStart(), "catch by const reference");
>> } else {
>> if (caughtType.isConstQualified() == false) {
>> diag(varDecl->getLocStart(),
>> "catch by const reference to avoid unnecessary copies");
>> }
>> }
>> }
>>
>> I tried looking at the varDecl but from there I can’t even find out how to
>> get the QualType. Can somebody give me a hint?
>>
>> Regards
>> Tobias
>> _______________________________________________
>> cfe-dev mailing list
>> cfe-dev at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20150716/18d4cf00/attachment.html>
More information about the cfe-dev
mailing list