You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It is of no concern to the caller whether a non-reference parameter is const or not. This matters in the function definition (it has to be non-const when, e.g., moving, or using the parameter as a local variable, and should be const when that is not required), but is useless clutter in the declaration; the compiler does not check consistency between the declaration and the definition, and even if consistency is maintained, this is an implementation detail.
Decision.
Definition (const pointer declarator).
A ptr-declarator is const pointer declarator if it is of any of the following forms:
* [attribute-specifier-seq] [cv-qualifier-seq] declarator-id [attribute-specifier-seq], where the cv-qualifier-seq contains const;
ptr-operatorptr-declarator, where the ptr-declarator is a const pointer declarator;
a noptr-declarator of any of the following forms:
noptr-declarator[[constant-expression]][attribute-specifier-seq], where the noptr-declarator is a const pointer declarator;
noptr-declaratorparameters-and-qualifiers, where the noptr-declarator is a const pointer declarator;
(ptr-declarator), where the ptr-declarator is a const pointer declarator.
Definition (const pointer abstract declarator).
A ptr-abstract-declarator is const pointer abstract declarator if it is of any of the following forms:
* [attribute-specifier-seq] [cv-qualifier-seq], where the cv-qualifier-seq does contains const;
ptr-operatorptr-abstract-declarator, where the ptr-abstract-declarator is a const pointer abstract declarator;
a noptr-abstract-declarator of any of the following forms:
noptr-abstract-declarator[[constant-expression]][attribute-specifier-seq], where the noptr-abstract-declarator is a const pointer abstract declarator;
noptr-abstract-declaratorparameters-and-qualifiers, where the noptr-abstract-declarator is a const pointer abstract declarator;
(ptr-abtract-declarator), where the ptr-abstract-declarator is a const pointer abstract declarator.
In the parameter-declaration-list of a function declarator that is not the declarator of a function-definition,
for parameter-declarations with a declarator which is a ptr-declarator, that ptr-declarator shall not be a const pointer declarator; further, if the declarator is of the form declarator-id [attribute-specifier-seq], the decl-specifier-seq of the parameter-declaration shall not contain const as one of its decl_specifiers.
for parameter-declarations with an abstract-declarator which is a ptr-abstract-declarator, that ptr-abstract-declarator shall not be a const pointer abstract declarator
for parameter-declarations which do not have a declarator or an abstract-declarator, the decl-specifier-seq of the parameter-declaration shall not contain const as one of its decl_specifiers.
In other words,
voidfoo(int x); // OK.voidfoo(int); // OK (though see the styleguide recommendations on// naming parameters in declarations).voidfoo(intconst); // No.voidfoo(intconst x); // No.voidfoo(intconst* x); // OK.voidfoo(intconst& x); // OK.voidfoo(int* const x); // No.voidfoo(int (* const x)()); // No. Really?voidfoo(int (*x)()); // You may want a type alias, but OK.voidfoo(intconst x[5]); // OK.voidfoo(intconst (* const x)[5]); // No!voidfoo(intconst (* constx())()); // Just say no.voidfoo(autox() -> int); // OK.
In the function definitions, const as much as possible.
The text was updated successfully, but these errors were encountered:
It is of no concern to the caller whether a non-reference parameter is const or not. This matters in the function definition (it has to be non-
const
when, e.g., moving, or using the parameter as a local variable, and should beconst
when that is not required), but is useless clutter in the declaration; the compiler does not check consistency between the declaration and the definition, and even if consistency is maintained, this is an implementation detail.Decision.
Definition (const pointer declarator).
A ptr-declarator is const pointer declarator if it is of any of the following forms:
*
[attribute-specifier-seq] [cv-qualifier-seq] declarator-id [attribute-specifier-seq], where the cv-qualifier-seq containsconst
;[
[constant-expression]]
[attribute-specifier-seq], where the noptr-declarator is a const pointer declarator;(
ptr-declarator)
, where the ptr-declarator is a const pointer declarator.Definition (const pointer abstract declarator).
A ptr-abstract-declarator is const pointer abstract declarator if it is of any of the following forms:
*
[attribute-specifier-seq] [cv-qualifier-seq], where the cv-qualifier-seq does containsconst
;[
[constant-expression]]
[attribute-specifier-seq], where the noptr-abstract-declarator is a const pointer abstract declarator;(
ptr-abtract-declarator)
, where the ptr-abstract-declarator is a const pointer abstract declarator.In the parameter-declaration-list of a function declarator that is not the declarator of a function-definition,
const
as one of itsdecl_specifier
s.const
as one of itsdecl_specifier
s.In other words,
In the function definitions, const as much as possible.
The text was updated successfully, but these errors were encountered: