Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Scott Snyder
coding-rules
Commits
95cba03a
Commit
95cba03a
authored
Dec 07, 2020
by
scott snyder
Browse files
Clarify that variable-length argument lists of varadic template functions are ok.
parent
9eeb35e4
Changes
1
Hide whitespace changes
Inline
Side-by-side
rules.org
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.
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment