Skip to content

Evaluate type traits in valueflow#7393

Merged
chrchr-github merged 5 commits intocppcheck-opensource:mainfrom
pfultz2:evaluate-type-traits
Mar 26, 2025
Merged

Evaluate type traits in valueflow#7393
chrchr-github merged 5 commits intocppcheck-opensource:mainfrom
pfultz2:evaluate-type-traits

Conversation

@pfultz2
Copy link
Copy Markdown
Contributor

@pfultz2 pfultz2 commented Mar 22, 2025

Right now it just evaluates is_void, is_lvalue_reference, and is_rvalue_reference. More work needed to handle library types in the type traits

@pfultz2
Copy link
Copy Markdown
Contributor Author

pfultz2 commented Mar 24, 2025

@danmar @orbitcowboy @chrchr-github Any feedback?

@chrchr-github
Copy link
Copy Markdown
Collaborator

chrchr-github commented Mar 24, 2025

Is this something that can grow into a generalized type trait evaluation? Seems like a huge task in any case.
is_void, is_lvalue_reference, is_rvalue_reference don't seem like the most popular traits to me, but I guess you have to start somewhere.

@pfultz2
Copy link
Copy Markdown
Contributor Author

pfultz2 commented Mar 25, 2025

This is just a start, but the idea is to handle more traits in the future, somewhat similar to how we do math evaluations. We can also add some library support in the future so we can handle the traits from other libraries that work the same as the std traits.

I started with is_void since there was already a ticket for it, and also did is_reference since that is a simple one as well. The other traits may take some more work, but can be incrementally added.

@chrchr-github
Copy link
Copy Markdown
Collaborator

chrchr-github commented Mar 25, 2025

In addition to {} and ::value, we should probably support C++17 _v helper variable templates as well, since new code is likely to use those,

@pfultz2
Copy link
Copy Markdown
Contributor Author

pfultz2 commented Mar 25, 2025

In addition to {} and ::value, we should probably support C++17 _v helper variable templates as well, since new code is likely to use those,

Thats already supported with a ASSERT_EQUALS(true, testKnownValueOfTok("std::is_void_v<void>;", "::", 1)); test here: https://github.com/danmar/cppcheck/pull/7393/files#diff-0c918c64e1eee55c83249b2cbe2beb837af6dd0a5a4273a1ae9168cd0582ba8dR619

@chrchr-github
Copy link
Copy Markdown
Collaborator

Thats already supported with a ASSERT_EQUALS(true, testKnownValueOfTok("std::is_void_v<void>;", "::", 1)); test here: https://github.com/danmar/cppcheck/pull/7393/files#diff-0c918c64e1eee55c83249b2cbe2beb837af6dd0a5a4273a1ae9168cd0582ba8dR619

Ah ok, must have missed that test. Does that mean std::reference_v etc. are also supported?

@pfultz2
Copy link
Copy Markdown
Contributor Author

pfultz2 commented Mar 25, 2025

Does that mean std::reference_v etc. are also supported?

Yes std::is_reference_v is supported as well.

@chrchr-github chrchr-github merged commit d95f754 into cppcheck-opensource:main Mar 26, 2025
60 checks passed
@pfultz2 pfultz2 deleted the evaluate-type-traits branch March 27, 2025 14:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants