Page MenuHomeFreeBSD

Fix C++ includability of crypto headers with static array sizes
ClosedPublic

Authored by asomers on Oct 18 2016, 3:02 PM.
Tags
None
Referenced Files
Unknown Object (File)
Thu, May 2, 4:10 PM
Unknown Object (File)
Wed, Apr 24, 7:22 PM
Unknown Object (File)
Wed, Apr 24, 7:21 PM
Unknown Object (File)
Tue, Apr 23, 4:25 AM
Unknown Object (File)
Fri, Apr 12, 2:27 PM
Unknown Object (File)
Apr 10 2024, 12:53 AM
Unknown Object (File)
Mar 8 2024, 8:30 PM
Unknown Object (File)
Mar 8 2024, 8:30 PM
Subscribers

Details

Summary

C99 allows array function parameters to use the static keyword for their
sizes. This tells the compiler that the parameter will have at least the
specified size, and calling code will fail to compile if that guarantee is
not met. However, this syntax is not legal in C++.

This commit reverts r300824, which worked around the problem for
sys/sys/md5.h only, and introduces a new macro: min_size(). min_size(x)
can be used in headers as a static array size, but will still compile in C++
mode.

Test Plan

Include all of the affected headers in an otherwise empty file, and compile
it in both C and C++ mode.

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

asomers retitled this revision from to Fix C++ includability of crypto headers with static array sizes.
asomers updated this object.
asomers edited the test plan for this revision. (Show Details)
asomers added reviewers: cem, ed.
ed edited edge metadata.
ed added inline comments.
sys/sys/cdefs.h
351 ↗(On Diff #21477)

Maybe we should also test for __STDC_VERSION__ here? Pre-C99 also doesn't support this.

This revision is now accepted and ready to land.Oct 18 2016, 3:04 PM
sys/sys/cdefs.h
354 ↗(On Diff #21477)

Is this correct in C++? Or should it just be an empty definition?

sys/sys/cdefs.h
354 ↗(On Diff #21477)

Yes, it is correct as it is right now.

cem edited edge metadata.
asomers edited edge metadata.

Use STDC_VERSION, even though clang allows static array sizes in c89 mode

This revision now requires review to proceed.Oct 18 2016, 5:56 PM
cem edited edge metadata.
This revision is now accepted and ready to land.Oct 18 2016, 5:58 PM
ed edited edge metadata.
ed added inline comments.
sys/sys/cdefs.h
351 ↗(On Diff #21477)

I'm not a fan of the extraneous parentheses, but it looks good enough to me. ;-)

This revision was automatically updated to reflect the committed changes.