This is an archive of the discontinued LLVM Phabricator instance.

[PATCH] Add checker discouraging definition of variadic function definitions in C++
ClosedPublic

Authored by aaron.ballman on Oct 5 2015, 12:36 PM.

Details

Reviewers
alexfh
sbenza
Summary

C-style variadic functions (using an ellipsis) can be dangerous in C++ due to the inherit lack of type safety with argument passing. Better alternatives exist, such as function currying (like STL stream objects use), or function parameter packs. This patch adds a checker to diagnose definitions of variadic functions in C++ code, but still allows variadic function declarations, as those can be safely used to good effect for SFINAE patterns.

This patch corresponds to the CERT C++ Coding Standard rule: https://www.securecoding.cert.org/confluence/display/cplusplus/DCL50-CPP.+Do+not+define+a+C-style+variadic+function

Diff Detail

Event Timeline

aaron.ballman retitled this revision from to [PATCH] Add checker discouraging definition of variadic function definitions in C++.
aaron.ballman updated this object.
aaron.ballman added reviewers: alexfh, sbenza.
aaron.ballman added a subscriber: cfe-commits.
sbenza accepted this revision.Oct 5 2015, 1:07 PM
sbenza edited edge metadata.

See comment regarding //CHECKs

test/clang-tidy/cert-variadic-function-def.cpp
4

All other tests I've read/written put the //CHECK after the matched lines.
We should be consistent with that.

This revision is now accepted and ready to land.Oct 5 2015, 1:07 PM
aaron.ballman closed this revision.Oct 5 2015, 1:10 PM
aaron.ballman marked an inline comment as done.

Thank you for the note about checks -- I hadn't noticed that. I've fixed and committed in r249343.

Thank you for the quick review!

~Aaron

dberlin added inline comments.
docs/clang-tidy/checks/cert-variadic-function-def.rst
13

I'm sure this is oversight on CERT's part, but their website actually has terms of use (click the terms of use at the bottom of the page) that says this can't be copied/reused, and here you are, copying it.
It explicit says: "
Use of the Service. You may only display the content of the Service for your own personal use (i.e., non-commercial use) and may not otherwise copy, reproduce, alter, modify, create derivative works, or publicly display any content. "

Before this is accepted, someone should email cert and say "hey, uh, yeah, this seems bad", and get them to okay you doing this.
I'm sure they'll go and fix this.