This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 119a. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.
2025-12-20
[Moved to DR at October 2002 meeting.]
This concerns the inconsistent treatment of cv qualifiers onreference types and function types. The problem originated withGCC bug report c++/2810. The bug report is available athttp://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view&pr=2810&database=gcc
9.3.4.3 [dcl.ref] describes references. Of interest isthe statement (my emphasis)
Cv-qualified references are ill-formedexcept whenthe cv-qualifiers are introduced through the use of a typedefor of a template type argument, in which case the cv-qualifiersare ignored.
Though it is strange to ignore 'volatile' here, that is not the pointof 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 acv-qualified function type is formed, the program is ill-formed.
No allowance for typedefs or template type parameters ismade 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 attemptis made to const qualify that, which is ill-formed. This is a surprise.
Suggested resolution:
Replace the quoted sentence from paragraph 4 in9.3.4.6 [dcl.fct] with
cv-qualified functions are ill-formed, except when thecv-qualifiers are introduced through the use of a typedef or ofa template type argument, in which case the cv-qualifiers areignored.
Adjust the example following to reflect this.
Proposed resolution (10/01):
In 9.3.4.6 [dcl.fct] paragraph 4, replace
The effect of acv-qualifier-seq in a function declarator isnot 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 atany time in the determination of a type a cv-qualified function typeis formed, the program is ill-formed. [Example: typedef void F(); struct S { const F f; // ill-formed };-- end example]byThe effect of acv-qualifier-seq in a function declarator isnot 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 qualificationon top of a function type are ignored. There is no mention of whetherthe 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 inconsistentwith the wording of adding cv qualifiers to a reference type, which doesmention typedefs and template parameters, even though
int &const ref;is also not allowed by the grammar.
Is this difference intentional? It seems needlessly confusing.
Notes from 4/02 meeting:
Yes, the difference is intentional. There is no way to add cv-qualifiersother than those cases.
Notes from April 2003 meeting:
Nathan Sidwell pointed out that some libraries use the inability toadd const to a type T as a way of testing that T is a functiontype. He will get back to us if he has a proposal for a change.