Created on 2001-06-29.00:00:00 last changed 34 months ago
[Moved to DR at October 2002 meeting.]
Notes from April 2003 meeting:
Nathan Sidwell pointed out that some libraries use the inability to add const to a type T as a way of testing that T is a function type. He will get back to us if he has a proposal for a change.
Notes from 4/02 meeting:
Yes, the difference is intentional. There is no way to add cv-qualifiers other than those cases.
Proposed resolution (10/01):
In 9.3.4.6 [dcl.fct] paragraph 4, replace
The effect of a cv-qualifier-seq in a function declarator is not the same as adding cv-qualification on top of the function type, i.e., it does not create a cv-qualified function type. In fact, if at any time in the determination of a type a cv-qualified function type is formed, the program is ill-formed. [Example:bytypedef void F(); struct S { const F f; // ill-formed };-- end example]
The effect of a cv-qualifier-seq in a function declarator is not the same as adding cv-qualification on top of the function type. In the latter case, the cv-qualifiers are ignored. [Example:typedef void F(); struct S { const F f; // ok; equivalent to void f(); };-- end example]
Strike the last bulleted item in 13.10.3 [temp.deduct] paragraph 2, which reads
Attempting to create a cv-qualified function type.
Nathan Sidwell comments (18 Dec 2001 ): The proposed resolution simply states attempts to add cv qualification on top of a function type are ignored. There is no mention of whether the function type was introduced via a typedef or template type parameter. This would appear to allow
void (const *fptr) ();but, that is not permitted by the grammar. This is inconsistent with the wording of adding cv qualifiers to a reference type, which does mention typedefs and template parameters, even though
int &const ref;is also not allowed by the grammar.
Is this difference intentional? It seems needlessly confusing.
Suggested resolution:
Replace the quoted sentence from paragraph 4 in 9.3.4.6 [dcl.fct] with
cv-qualified functions are ill-formed, except when the cv-qualifiers are introduced through the use of a typedef or of a template type argument, in which case the cv-qualifiers are ignored.
Adjust the example following to reflect this.
This concerns the inconsistent treatment of cv qualifiers on reference types and function types. The problem originated with GCC bug report c++/2810. The bug report is available at http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view&pr=2810&database=gcc
9.3.4.3 [dcl.ref] describes references. Of interest is the statement (my emphasis)
Cv-qualified references are ill-formed except when the cv-qualifiers are introduced through the use of a typedef or of a template type argument, in which case the cv-qualifiers are ignored.
Though it is strange to ignore 'volatile' here, that is not the point of this defect report. 9.3.4.6 [dcl.fct] describes function types. Paragraph 4 states,
In fact, if at any time in the determination of a type a cv-qualified function type is formed, the program is ill-formed.
No allowance for typedefs or template type parameters is made here, which is inconsistent with the equivalent reference case.
The GCC bug report was template code which attempted to do,
template <typename T> void foo (T const &); void baz (); ... foo (baz);
in the instantiation of foo, T is `void ()' and an attempt is made to const qualify that, which is ill-formed. This is a surprise.
History | |||
---|---|---|---|
Date | User | Action | Args |
2022-02-18 07:47:23 | admin | set | messages: + msg6670 |
2008-10-05 00:00:00 | admin | set | status: wp -> cd1 |
2003-04-25 00:00:00 | admin | set | messages: + msg865 |
2003-04-25 00:00:00 | admin | set | status: dr -> wp |
2002-11-08 00:00:00 | admin | set | messages: + msg773 |
2002-11-08 00:00:00 | admin | set | status: ready -> dr |
2002-05-10 00:00:00 | admin | set | messages: + msg615 |
2002-05-10 00:00:00 | admin | set | status: review -> ready |
2001-11-09 00:00:00 | admin | set | messages: + msg553 |
2001-11-09 00:00:00 | admin | set | status: open -> review |
2001-06-29 00:00:00 | admin | create |