Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
coding-rules
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Scott Snyder
coding-rules
Commits
95cba03a
Commit
95cba03a
authored
4 years ago
by
scott snyder
Browse files
Options
Downloads
Patches
Plain Diff
Clarify that variable-length argument lists of varadic template functions are ok.
parent
9eeb35e4
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
rules.org
+22
-4
22 additions, 4 deletions
rules.org
with
22 additions
and
4 deletions
rules.org
+
22
−
4
View file @
95cba03a
...
...
@@ -2278,10 +2278,8 @@ std::ostringstream ost;
- *Do not use the ellipsis notation for function arguments.* [<<no-ellipsis>>]
Functions with an unspecified number of arguments should not be used
because they are a common cause of bugs that are hard to find. But
=catch(...)= to catch any exception is acceptable (but should generally
not be used outside of framework code).
Prior to C++ 11, functions with an unspecified number of arguments
had to be declared and used in a type-unsafe manner:
#+BEGIN_EXAMPLE
// avoid to define functions like:
...
...
@@ -2290,6 +2288,24 @@ void error(int severity, ...) // "severity" followed by a
// of char*s
#+END_EXAMPLE
This method should be avoided.
As of C++ 11, one can accomplish something similar using varadic
templates:
#+BEGIN_EXAMPLE
template<typename ...ARGS>
void error(int severity, ARGS...)
#+END_EXAMPLE
This is fine, but should be used judiciously. It's appropriate
for forwarding arguments theough a template function. For other cases,
it's worth thinking if there might be a simpler way of doing things.
An ellipsis can also occur in a catch clause to catch any
exception: =catch(...)=. This is acceptable, but should generally
be restricted to framework-like code.
- *Do not use preprocessor macros to take the place of functions, or for defining constants.* [<<no-macro-functions>>]
...
...
@@ -3022,6 +3038,8 @@ The comment includes the fact that it is the perpendicular distance.
** Version 0.8
- Clarify that non-ascii characters should not be used in identifier names.
- Clarify that variable-length argument lists of varadic template functions
are ok.
** Version 0.7
- Minor cleanups and updates to take into acount that we now require C++17.
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment