Skip to content

C++: do not generate duplicated using statements for overloads in derived classes#1803

Merged
pwrobeldev merged 4 commits intomasterfrom
pwrobeldev/cpp-generator-distinct-using
Mar 3, 2026
Merged

C++: do not generate duplicated using statements for overloads in derived classes#1803
pwrobeldev merged 4 commits intomasterfrom
pwrobeldev/cpp-generator-distinct-using

Conversation

@pwrobeldev
Copy link
Copy Markdown
Contributor

---------- Motivation ----------
When base and derived classes declare method with the same name,
then in the derived class we need to add 'using' statement to avoid
compiler warning/error related to shadowing.

It seems that when multiple function overloads were declared in the
derived class, then Gluecodium generated redundant using statements
which look like a bug.

---------- Solution ----------
Implemented filtering of prepared using statements to ensure that they
are unique (via distinct() function call on list).

This commit:

  • brings smoke tests that reproduce the problem
  • provides fix for the bug
  • showcases that the bug is solved in smoke tests

If method with the same name is declared in the base class
and in the derived class, then to avoid warning (or error
when -Werror is enabled) that is related to shadowing
the methods from base class we need to add 'using' statement.

However, it seems that C++ generator does not filter identical
using statements when preparing the data for mustache template.

The problem is reproduced by this commit to showcase wrong
behavior in smoke tests.

Signed-off-by: Patryk Wrobel <183546751+pwrobeldev@users.noreply.github.com>
This commit filters duplicated using statements
for derived classes to avoid redundancy in the code.

Signed-off-by: Patryk Wrobel <183546751+pwrobeldev@users.noreply.github.com>
The redundant using statements are removed by
using filtering while generating the using statements
in CPP generator.

Signed-off-by: Patryk Wrobel <183546751+pwrobeldev@users.noreply.github.com>
Signed-off-by: Patryk Wrobel <183546751+pwrobeldev@users.noreply.github.com>
@pwrobeldev pwrobeldev requested a review from Hsilgos February 28, 2026 09:46
@pwrobeldev
Copy link
Copy Markdown
Contributor Author

Additional reproducer to showcase why using is needed:

@pwrobeldev
Copy link
Copy Markdown
Contributor Author

One additional note -- multiple using statements cause compilation failure:

Therefore, this MR fixes the possible compilation failure.

@pwrobeldev pwrobeldev merged commit c57c2a9 into master Mar 3, 2026
19 checks passed
@pwrobeldev pwrobeldev deleted the pwrobeldev/cpp-generator-distinct-using branch March 3, 2026 08:01
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