Replace string comparison with AST check in IsBuiltin for std::complex#842
Conversation
4bfa493 to
0c8daee
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #842 +/- ##
==========================================
+ Coverage 79.72% 79.75% +0.03%
==========================================
Files 11 11
Lines 4025 4031 +6
==========================================
+ Hits 3209 3215 +6
Misses 816 816
🚀 New features to boost your workflow:
|
|
clang-tidy review says "All clean, LGTM! 👍" |
Vipul-Cariappa
left a comment
There was a problem hiding this comment.
Looks good to me!
Could you add a test case that covers the uncovered line for the test coverage.
| if (const auto* RD = Ty->getAsCXXRecordDecl()) { | ||
| if (const auto* CTSD = dyn_cast<ClassTemplateSpecializationDecl>(RD)) { | ||
| IdentifierInfo* II = CTSD->getSpecializedTemplate()->getIdentifier(); | ||
| if (II && II->isStr("complex") && |
There was a problem hiding this comment.
There is still some string comparison, but I guess this is a better approach.
Hi I am Done |
|
clang-tidy review says "All clean, LGTM! 👍" |
Can you rebase on latest main to fix the CI failures? (and squash into a single commit) |
ba65476 to
434eabc
Compare
Yup done! |
Will I do this or will the maintainers? |
|
clang-tidy review says "All clean, LGTM! 👍" |
Vipul-Cariappa
left a comment
There was a problem hiding this comment.
LGTM!
I am approving this, but will defer merging for now. As the CI is failing, I believe the CI failures are unrelated to these changes.
We are looking into the failures in the CI. For now, I don't think it is caused by your changes, therefore we will take care of it. Unless we find out there is some change in this PR that is the cause. You will have to fix things. Will inform you 😄. |
| if (const auto* RD = Ty->getAsCXXRecordDecl()) { | ||
| if (const auto* CTSD = dyn_cast<ClassTemplateSpecializationDecl>(RD)) { | ||
| IdentifierInfo* II = CTSD->getSpecializedTemplate()->getIdentifier(); | ||
| if (II && II->isStr("complex") && |
There was a problem hiding this comment.
What about Type::isAnyComplexType?
There was a problem hiding this comment.
isAnyComplexType() is already called on line 409 ... but std::complex<T> is a class temp record type and , not a Clang ComplexType, so the func should be returning false for it. The AST check below is specifically to handle standard complex typpa specialisations.
Understood thank you! |
434eabc to
210eee9
Compare
|
clang-tidy review says "All clean, LGTM! 👍" |
|
Hi @Vipul-Cariappa , I rebased it to the latest fix and seems all CI errors have been resolves |
|
clang-tidy review says "All clean, LGTM! 👍" |
Description
Replace the fragile string-based check for
std::complexinIsBuiltin()with a proper Clang AST query.he old code was checking if a type's name contained the word "complex" as a string, which is pretty hacky cuz any random user class with "complex" in the name would get wrongly treated as a builtin. I swapped it out for a proper AST check that looks at whether the type is actually a
std::complex<T>specialization by walking the Clang AST. Same approach that's already used in other parts of the codebase, so it fits right in.Resolves the FIXME at line 411:
// FIXME: Figure out how to avoid the string comparison.Type of change
Testing
ScopeReflection_IsBuiltintest which covers:bool,char,signed char,void)_Complextypes (_Complex float,_Complex double,_Complex long double,_Complex __float128)std::complex<T>template specializations (via#include <complex>and iterating over specializations)Checklist