GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Expand template argument type deduction by pfultz2 · Pull Request #8688 · cppcheck-opensource/cppcheck

Conversation

@pfultz2

@pfultz2 pfultz2 commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator

Previously we only did type deduction when the argument that was passed was a literal(ie f(0)). This expands this to handle variables and expressions.

There is no varid/SymbolDatabase/ValueType information at the TemplateSimplifier stage so it uses a token-based parsing to try and deduce the type. If it can deduce the type then it will skip instantiating the function.

There is still a lot of gaps here that could be addressed in the future. Ideally, I would like to see if the logic from SymbolDatabase/ValueType could be reused here using a shared utility.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Your Name added 17 commits July 2, 2026 09:43
Your Name
Add template type deduction
2c68b09
Your Name
Simplify
eecd903
Your Name
Use a forward walk
a43039a
Your Name
Handle global function template called from a class scope
695de6e
Your Name
Improve member functions
b60e55e
Your Name
Handle late class members
de77bc6
Your Name
Handle overloading better
90c62dc
Your Name
Simplify and add unit tests
5ad01ad
Your Name
Improve comments
965281d
Your Name
Avoid output params
d966681
Your Name
Format
f64190d
Your Name
Use stl algorithm
81da87b
Your Name
Format
9b554ac
Your Name
Fix selfcheck
35e830a
Your Name
Remvoe unnecessary move
770eeb9
Your Name
Add test for 13630
0e81fca
Your Name
Format
e87f8d7
@pfultz2

pfultz2 commented Jul 3, 2026

Copy link
Copy Markdown
Collaborator Author

This fixes issue 13630, so I added a test for that.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

firewave
firewave reviewed Jul 3, 2026
View reviewed changes
Comment thread .selfcheck_suppressions
autoNoType:tools/triage/mainwindow.cpp
# ticket 11631
templateInstantiation:test/testutils.cpp
templateInstantiation

@firewave firewave Jul 3, 2026

Copy link
Copy Markdown
Collaborator

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer to have an entry for each file it occurs in so we would at least partially detect future regressions. Heck, we should probably move this to the source instead so we have actual individual suppressions.

Since the scope has widened additional tickets probably need to be filed.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@pfultz2 pfultz2 Jul 3, 2026

Copy link
Copy Markdown
Collaborator Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well we need to suppress it everytime we use functions like contains or calculate, and we are a long ways from being able to instantiate those functions. This isnt catching any errors and just adding burden. I think it would be better as a seperate report like daca.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@firewave firewave Jul 3, 2026

Copy link
Copy Markdown
Collaborator

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. It is just a debug warning (those are tracked in daca). Still a new ticket for one of the additional cases would be good for tracking.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Your Name added 5 commits July 4, 2026 14:09
Your Name
Suppress unmatchedSuppression
9933641
Your Name
Merge
6dab97d
Your Name
Suppress unmatched suppression warnings with template instantiation
a6ded13
Your Name
Fix cppcheck debug warning
7f3645f
Your Name
Check for debug warnings flag
1f813e4
danmar
danmar reviewed Jul 9, 2026
View reviewed changes

@danmar danmar left a comment •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Collaborator

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree it would be great to reuse the logic in symboldatabase etc..
It was a while since I looked at these things and I do not have a clear picture how complex it would be to achieve that. Reusing some functions sounds like a great idea.

There is a circular dependency; type deduction requires symboldatabase and symboldatabase requires type deduction so I fear that in theory we should rewrite the parser so that the templates are not instantiated as a separate step but rather do it all together at the same time.. instantiate templates, perform symboldatabase, create AST all at the same time. That is far too complex rewrite to do so I don't actually recommend that we do it in practice, it's more like "the ideal solution in theory". :-(

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread lib/templatesimplifier.cpp
Comment on lines +899 to 901
default:
return 0;
}

@danmar danmar Jul 9, 2026

Copy link
Copy Markdown
Collaborator

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this default prevents such gcc warnings 1.cpp:6:12: warning: enumeration value ‘C’ not handled in switch [-Wswitch]

I would suggest that the default is removed. And below the switch call cppcheck::unreachable();

Suggested change
default:
return 0;
}
}
cppcheck::unreachable();

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread lib/templatesimplifier.cpp
if (a.isUnsigned || a.isUnsigned == b.isUnsigned)
return a;
// the lower ranked operand is unsigned, the higher ranked operand is signed
const std::size_t sizeA = arithSize(settings, a.arith);

@danmar danmar Jul 9, 2026

Copy link
Copy Markdown
Collaborator

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I claim that the size does not matter. When 'long' and 'long long' have the same size:
'unsigned long' + 'signed long long' => 'signed long long'

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@pfultz2

pfultz2 commented Jul 9, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Collaborator Author

I agree it would be great to reuse the logic in symboldatabase etc.. It was a while since I looked at these things and I do not have a clear picture how complex it would be to achieve that. Reusing some functions sounds like a great idea.

There is a circular dependency; type deduction requires symboldatabase and symboldatabase requires type deduction so I fear that in theory we should rewrite the parser so that the templates are not instantiated as a separate step but rather do it all together at the same time.. instantiate templates, perform symboldatabase, create AST all at the same time. That is far too complex rewrite to do so I don't actually recommend that we do it in practice, it's more like "the ideal solution in theory". :-(

If we could make the symboldatabase/ast run incrementally then we can run this in a loop, so the TemplateSimplifier can use this information and then we run the symboldatabase/ast.

This is something I was working on as well, but I was looking into destroying the info everytime which makes it kind of expensive. If we could make it incremental, it might be doable.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@danmar

danmar commented Jul 12, 2026

Copy link
Copy Markdown
Collaborator

This is something I was working on as well, but I was looking into destroying the info everytime which makes it kind of expensive. If we could make it incremental, it might be doable.

ok

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@pfultz2

pfultz2 commented Jul 13, 2026

Copy link
Copy Markdown
Collaborator Author

This is something I was working on as well, but I was looking into destroying the info everytime which makes it kind of expensive. If we could make it incremental, it might be doable.

ok

So in #8720, I did get it with a partially incremental update(it still rebuilds from scratches for class instantiations and template aliases). Some local tests showed it was about 2x faster with incremental updates vs rebuild everytime. I dont know if that is the direction we would prefer to go instead.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@pfultz2 pfultz2 mentioned this pull request Jul 19, 2026
Fix 13630, 9676: Template argument deduction using SymbolDatabase #8720
Open
@pfultz2

pfultz2 commented Jul 27, 2026

Copy link
Copy Markdown
Collaborator Author

#8720 is a much better approach for this, so I am closing this.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@pfultz2 pfultz2 closed this Jul 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@danmar danmar danmar left review comments
@firewave firewave firewave left review comments

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@pfultz2 @danmar @firewave
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.