Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix nonstandard C++ in headers #7194

Open
wants to merge 2 commits into
base: development
Choose a base branch
from

Conversation

gilles-peskine-arm
Copy link
Contributor

@gilles-peskine-arm gilles-peskine-arm commented Mar 1, 2023

Fix some code in header files that is standard C99, but not standard C++11.

I use C++11 as the cutoff because Mbed TLS headers have never been pedantically compliant C++98 due to the use of commas at the end of enumerator lists (and perhaps other features).

This is work in progress addressing #7087. It fixes the initializers, but not the problem with linkage of functions that return structs.

Gatekeeper checklist

  • changelog TODO
  • backport TODO
  • tests provided

The PAKE structure initialization uses a named initializer, which is not
supported in versions of C++ that are still widespread. The named
initializer doesn't really help here, so get rid of it. More generally, this
commit simplifies the initialization of the structure by always including
the dummy field.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
@gilles-peskine-arm gilles-peskine-arm added component-platform Portability layer and build scripts needs-ci Needs to pass CI tests size-s Estimated task size: small (~2d) priority-medium Medium priority - this can be reviewed as time permits labels Mar 1, 2023
This avoids us accidentally using language features in headers that are not
present in standard C++ or were added very recently.

I used C++11 as the cutoff because our code base relies on several features
that aren't present in C++98, including commas at the end of enumerator
lists which have been present in the Mbed TLS code base since the PolarSSL
days.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
@RytoEX
Copy link

RytoEX commented May 17, 2023

#6567 appears to have made similar changes. Does that obsolete/supersede this?

@gilles-peskine-arm
Copy link
Contributor Author

@RytoEX Thanks for making the link! #6567 obsoletes the PAKE context changes, but the addition of C++ pedantic application builds in this PR are still relevant. I'll rebase.

Also, since #6557 fixed part of a known issue, I guess we should write a changelog entry. Or maybe we should wait for a full fix?

@RytoEX
Copy link

RytoEX commented May 18, 2023

@RytoEX Thanks for making the link! #6567 obsoletes the PAKE context changes, but the addition of C++ pedantic application builds in this PR are still relevant. I'll rebase.

Good point.

Also, since #6557 fixed part of a known issue, I guess we should write a changelog entry. Or maybe we should wait for a full fix?

My understanding is that #7087 is composed of multiple issues/goals. It might be helpful to have a changelog entry specifically about resolving the Designated Initializers issue so that it is more easily found (I had to dig into git blame), while leaving #7087 open until all of its goals are achieved (if its scope is to remain as-is). That leaves:

  • the test script changes for building in pedantic mode (this PR)
  • fixing linkage with forward declarations

That said, I leave whether to write a changelog entry now to the discretion of you and your colleagues.

Copy link
Contributor

@mpg mpg left a comment

Choose a reason for hiding this comment

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

LGTM

@mpg
Copy link
Contributor

mpg commented May 23, 2023

This needs rebasing as pointed out previously.

Regarding the ChangeLog, I think we should have a bugfix entry here about the compilation failure in C++ mode (even though it was fixed in #6567 without noticing).

Regarding backport, I don't think the issue is present in 2.28, but the testing improvement should be backported of course.

@mpg mpg added needs-work needs-backports Backports are missing or are pending review and approval. and removed needs-ci Needs to pass CI tests labels May 23, 2023
@tom-cosgrove-arm tom-cosgrove-arm added the historical-reviewing Currently reviewing (for legacy PR/issues) label Jun 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component-platform Portability layer and build scripts historical-reviewing Currently reviewing (for legacy PR/issues) needs-backports Backports are missing or are pending review and approval. needs-work priority-medium Medium priority - this can be reviewed as time permits size-s Estimated task size: small (~2d)
Projects
Status: In Development
Development

Successfully merging this pull request may close these issues.

4 participants