C++ Standard Core Language
Defect Reports,
Revision
72

This document contains the C++ core language issues that have been
categorized as Defect Reports by the Committee (J16 +
WG21), that is, issues with status
"DR,"
"WP,"
"CD1,"
"CD2," and
"TC1,"
along with their proposed resolutions. ONLY RESOLUTIONS FOR
ISSUES WITH TC1 STATUS ARE PART OF THE INTERNATIONAL STANDARD
FOR C++. The other issues are provided for informational
purposes only, as an indication of the intent of the Committee.
They should not be considered definitive until or unless they
appear in an approved Technical Corrigendum or revised
International Standard for C++.

This document is part of a group of related documents that
together describe the issues that have been raised regarding the
C++ Standard. The other documents in the group are:

Active Issues List, which contains
explanatory material for the entire document group and a list of
the issues that have not yet been acted upon by the Committee.

Closed Issues List, which contains
the issues which the Committee has decided are not defects
in the International Standard, including a brief rationale
explaining the reason for the decision.

Table of Contents, which contains a
summary listing of all issues in numerical order.

Index by Section, which contains a
summary listing of all issues arranged in the order of the
sections of the Standard with which they deal most directly.

Index by Status, which contains a
summary listing of all issues grouped by status.

For more information, including a description of the meaning of
the issue status codes and instructions on reporting new issues,
please see the Active Issues List.

676.
static_assert-declarations and general requirements for declarations

3.1 [basic.def] makes statements about declarations that do
not appear to apply to static_assert-declarations. For example,
paragraph 1 says,

A declaration (clause 7 [dcl.dcl]) introduces names into a
translation unit or redeclares names introduced by previous
declarations. A declaration specifies the interpretation and
attributes of these names.

What name is being declared or described by
a static_assert-declaration?

Also, paragraph 2 lists the kinds of declarations that are not
definitions, and a static_assert-declaration is not among them.
Is it intentional that static_assert-declarations are
definitions?

Proposed resolution (March, 2010):

Change 3.1 [basic.def] paragraphs 1-2 as follows:

A declaration (Clause 7 [dcl.dcl]) may
introducesone or more names into a
translation unit or redeclares names introduced by
previous declarations. AIf so, the
declaration specifies the interpretation and attributes of these
names. A declaration may also have effects
including

a static assertion (Clause 7 [dcl.dcl]),

controlling template instantiation (14.7.2 [temp.explicit],

use of attributes (Clause 7 [dcl.dcl], or

nothing (in the case of an
empty-declaration).

A declaration is a definition unless it declares a function
without specifying the function's body (8.4 [dcl.fct.def]), it contains the extern specifier
(7.1.1 [dcl.stc]) or a
linkage-specification25 (7.5 [dcl.link]) and neither an initializer nor a
function-body, it declares a static data member in a class
definition (9.4 [class.static]), it is a class name
declaration (9.1 [class.name]), it is an
opaque-enum-declaration (7.2 [dcl.enum]), or it
is a typedef declaration (7.1.3 [dcl.typedef]), a
using-declaration (7.3.3 [namespace.udecl]), a
static_assert-declaration (Clause 7 [dcl.dcl]),
an attribute-declaration (Clause 7 [dcl.dcl]),
an empty-declaration (Clause 7 [dcl.dcl]), or a using-directive (7.3.4 [namespace.udir]). [Example:...

...but I don't see how any of the bullets in the list in paragraph
5 apply.

Proposed resolution (March, 2010):

Add a new bullet following 3.2 [basic.def.odr] paragraph 5,
second bullet:

...Given such an entity named D defined in more than one
translation unit, then

each definition of D shall consist of the
same sequence of tokens; and

in each definition of D, corresponding names,
looked up according to 3.4 [basic.lookup], shall refer to
an entity defined within the definition of D, or shall
refer to the same entity, after overload resolution (13.3 [over.match]) and after matching of partial template
specialization (14.8.3 [temp.over]), except that a name
can refer to a const object with internal or no linkage if the
object has the same literal type in all definitions of
D, and the object is initialized with a constant
expression (5.19 [expr.const]), and the value (but not
the address) of the object is used, and the object has the same
value in all definitions of D; and

in each definition of D, corresponding
entities shall have the same language linkage; and

The relevant citation from the standard is
3.4.6 [basic.lookup.udir]: "When looking up a
namespace-name in a using-directive or namespace-alias-definition, only
namespace names are considered." This statement could reasonably be
interpreted to apply only to the last element of a qualified name, and
that's the way EDG and Microsoft seem to interpret it.

However, since a class can't contain a namespace, it seems to me that this
interpretation is, shall we say, sub optimal. If the X qualifiers in the
above example are interpreted as referring to the struct X, an error of some
sort is inevitable, since there can be no namespace for the qualified name
to refer to. G++ apparently interprets 3.4.6 [basic.lookup.udir]
as applying to
nested-name-specifiers in those contexts as well, which makes a valid
interpretation of the test possible.

I'm thinking it might be worth
tweaking the words in 3.4.6 [basic.lookup.udir]
to basically mandate the more useful
interpretation. Of course a person could argue that the difference would
matter only to a perverse program. On the other hand, namespaces were
invented specifically to enable the building of programs that would
otherwise be considered perverse. Where name clashes are concerned, one
man's perverse is another man's real world.

Proposed Resolution (November, 2006):

Change 3.4.6 [basic.lookup.udir] paragraph 1 as follows:

When looking up a namespace-name in a using-directive or
namespace-alias-definition,In a using-directive
or namespace-alias-definition, during the lookup for a
namespace-name or for a name in a nested-name-specifier,
only namespace names are considered.

3.5 [basic.link] paragraph 10 certainly makes allowance
for declarations to differ in the presence or absence of a major array
bound. However, 3.1 [basic.def] paragraph 5 says that

A program is ill-formed if the definition of any object gives the
object an incomplete type (3.9 [basic.types]).

3.9 [basic.types] paragraph 7 says,

The declared type of an array object might be an array of unknown size
and therefore be incomplete at one point in a translation unit and
complete later on; the array types at those two points (“array
of unknown bound of T” and “array of
N T”) are different types.

This wording appears to make no allowance for the C concept of
“composite type;” instead, each declaration is said
to have its own type. By this interpretation, the example is
ill-formed, because the type declared by the definition of
S::a is incomplete.

If the example is intended to be well-formed, the Standard
needs explicit wording stating that an omitted array bound in a
declaration is implicitly taken from that of a visible
declaration of that object, if any.

Notes from the April, 2007 meeting:

The CWG agreed that this usage should be permitted.

Proposed resolution (June, 2008):

Change 8.3.4 [dcl.array] paragraph 1 as follows:

...IfExcept as noted below, if the constant expression
is omitted, the type of the identifier of D is
“derived-declarator-type-list array of unknown bound of
T,” an incomplete object type...

Change 8.3.4 [dcl.array] paragraph 3 as follows:

When several “array of” specifications are adjacent, a
multidimensional array is created; only the first of the
constant expressions that specify the bounds of the arrays canmay be omitted only for the first member of the
sequence. [Note: this elision is useful for function parameters
of array types, and when the array is external and the definition,
which allocates storage, is given elsewhere. —end
note]In addition to declarations in which an incomplete
object type is allowed, an array bound may be omitted in the
declaration of a function parameter (8.3.5 [dcl.fct]).The first constant-expression canAn array bound
may also be omitted when the declarator is followed by an
initializer (8.5 [dcl.init]). In this case the bound
is calculated from the number of initial elements (say, N)
supplied (8.5.1 [dcl.init.aggr]), and the type of the identifier
of D is “array of NT.”
Furthermore, if there is a visible declaration of the name declared
by the declarator-id (if any) in which the bound was specified,
an omitted array bound is taken to be the same as in that earlier
declaration.

Notes from the September, 2008 meeting:

The proposed resolution does not capture the result favored
by the CWG: array bound information should be accumulated across
declarations within the same scope, but a block extern declaration
in a nested scope should not inherit array bound information from
the outer declaration. (This is consistent with the treatment of
default arguments in function declarations.) For example:

int a[5];
void f() {
extern int a[];
sizeof(a);
}

Although there was some confusion about the C99 wording dealing
with this case, it is probably well-formed in C99. However, it
should be ill-formed in C++, because we want to avoid the
concept of “compatible types” as it exists in C.

Proposed resolution (March, 2010):

Change 8.3.4 [dcl.array] paragraph 1 as follows:

...IfExcept as noted below, if the constant expression
is omitted, the type of the identifier of D is
“derived-declarator-type-list array of unknown bound of
T,” an incomplete object type...

Change 8.3.4 [dcl.array] paragraphs 3-4 as follows:

When several “array of” specifications are
adjacent, a multidimensional array is created; only the
first of the constant expressions that specify the bounds
of the arrays canmay be omitted only
for the first member of the sequence. [Note: this elision
is useful for function parameters of array types, and when the
array is external and the definition, which allocates storage, is
given elsewhere. —end note]In addition
to declarations in which an incomplete object type is allowed, an
array bound may be omitted in some cases in the declaration of a
function parameter (8.3.5 [dcl.fct]).The
first constant-expression canAn array bound
may also be omitted when the declarator is followed by an
initializer (8.5 [dcl.init]). In this case the
bound is calculated from the number of initial elements (say,
N) supplied (8.5.1 [dcl.init.aggr]), and the type
of the identifier of D is “array of NT.” Furthermore, if there is a preceding
declaration of the entity in the same scope in which the bound
was specified, an omitted array bound is taken to be the same as
in that earlier declaration, and similarly for the definition of a
static data member of a class.

864.
braced-init-list in the range-based for statement

The intent is that the range-based for statement should
be able to be used with a braced-init-list as the range over
which to iterate. However, this does not work grammatically: a
braced-init-list is not an expression, as required by
the syntax in 6.5.4 [stmt.ranged] paragraph 1:

for (for-range-declaration : expression ) statement

Even if this were resolved, the “equivalent to” code
is not correct. It contains the declaration,

auto && __range = ( expression );

This has a similar problem, in that 7.1.6.4 [dcl.spec.auto]
paragraph 3 requires that the initializer have one of the forms

= assignment-expression( assignment-expression )

which does not allow for a braced-initializer-list. In
addition, although not allowed by the grammar, 7.1.6.4 [dcl.spec.auto]
paragraph 6 treats the braced-init-list specially, in order for
the type deduction to work correctly:

Obtain P from T by replacing the occurrences of
auto with either a new invented type template parameter
U or, if the initializer is a braced-init-list
(8.5.4 [dcl.init.list]), with
std::initializer_list<U>.

The problem here is that a parenthesized initializer, as in the
code expansion of the range-based for statement, is not
a braced-init-list.

Proposed resolution (June, 2010):

Change 6.5 [stmt.iter] paragraph 1 as follows:

Iteration statements specify looping.

iteration-statement:

while (condition)statement

dostatementwhile (expression) ;

for (for-init-statement conditionopt;expressionopt)statement

for (for-range-declaration:expressionfor-range-initializer)statement

for-init-statement:

expression-statement

simple-declaration

for-range-declaration:

type-specifier-seq attribute-specifieropt declarator

for-range-initializer:

expression

braced-init-list

[Note: a for-init-statement ends with a semicolon.
—end note]

Change 6.5.4 [stmt.ranged] paragraph 1 as follows:

TheFor a range-based for statement
of the form

for (for-range-declaration:expression)statement

let range-init be equivalent to the expression
surrounded by parentheses:

(expression)

[Footnote: this ensures that a top-level comma
operator cannot be reinterpreted as a delimiter between
init-declarators in the declaration of
__range. —end footnote] and for a
range-based for statement of the form

for (for-range-declaration:braced-init-list)statement

let range-init be equivalent to the
braced-init-list. In each case, a range-based
for statement is equivalent to

The formatting in the preceding change for
range-init follows that of the existing text for
begin-expr and end-expr. However, CWG is concerned
that this style makes all of these elements look too much like
grammar nonterminals and asks that the editor consider some other
formatting convention.

700.
Constexpr member functions of class templates

7.1.5 [dcl.constexpr] paragraph 5 applies only to “the
instantiated template specialization of a constexpr function
template;” it should presumably apply to non-template member
functions of a class template, as well.

Notes from the September, 2008 meeting:

This question is more involved than it might appear. For example,
a constexpr member function is implicitly const; if the
constexpr specifier is ignored, does that make the member
function non-const? Also, should this provision apply only to
dependent expressions in the function? Should it be an error if no
constexpr function can be instantiated from the template, along the
lines of the permission given in 14.6 [temp.res] paragraph 8
for an implementation to diagnose a template definition from which no
valid specialization can be instantiated?

Notes from the July, 2009 meeting:

The consensus of the CWG was that an “ignored”
constexpr specifier in this case simply means that the
specialization is not constexpr, not that it is not const. The
CWG also decided not to address the question of non-dependent
expressions that render a function template specialization
non-constexpr, leaving it to quality of implementation whether
a (warning) diagnostic is issued in such cases.

Proposed resolution (February, 2010):

Change 7.1.5 [dcl.constexpr] paragraph 5 as follows:

If the instantiated template specialization of a constexpr
function template or member function of a class
template would fail to satisfy the requirements for a
constexpr function or constexpr constructor, the
constexpr specifier is ignoredthat
specialization is not a constexpr function or constexpr
constructor. [Note: if the function is a
member function it will still be const as described
below. Implementations are encouraged to issue a warning if a
function was rendered not constexpr by a non-dependent
construct. —end note]

860.
Explicit qualification of constexpr member functions

A constexpr specifier for a non-static member function that is not a
constructor declares that member function to be const (9.3.1 [class.mfct.non-static]).

Is a const qualifier on such a member function redundant
or ill-formed?

Notes from the July, 2009 meeting:

The CWG agreed that a const qualifier on a constexpr
member function is simply redundant and not an error.

Proposed resolution (February, 2010):

Change 7.1.5 [dcl.constexpr] paragraph 6 as follows:

A constexpr specifier for a non-static member function
that is not a constructor declares that member function to be
const (9.3.1 [class.mfct.non-static]). [Note: the
constexpr specifier has no other effect on the function
type. —end note] The keyword const is
ignored if it appears in the cv-qualifier-seq of the
function declarator of the declaration of such a member
function. The class of which that function is a member
shall be a literal type (3.9 [basic.types]). [Example:...

892.
Missing requirements for constexpr constructors

The rules for constexpr constructors are missing some necessary
requirements. In particular, there is no requirement that a
brace-or-equal-initializer for a non-static data member be
a constant expression, and the requirement for constexpr constructors
for initializing non-static data members applies only to members
named in a mem-initializer, allowing a non-constexpr default
constructor to be invoked.

Proposed resolution (February, 2010):

Change 7.1.5 [dcl.constexpr] paragraph 4 as follows:

The definition of a constexpr constructor shall satisfy the
following constraints:

each of its parameter types shall be a literal type or a
reference to a literal type

its function-body shall not be a
function-try-block

the compound-statement of its function-body shall
be empty

every non-static data member and base class sub-object shall be
initialized (12.6.2 [class.base.init])

every constructor involved in initializing non-static data
members and base class sub-objects invoked by a
mem-initializer shall be a constexpr
constructor.

every constructor argument and full-expression in a
mem-initializer shall be a potential constant
expression

every assignment-expression that is an
initializer-clause appearing directly or indirectly within a
brace-or-equal-initializer for a non-static data member that is
not named by a mem-initializer-id shall be a constant
expression

every implicit conversion used in converting a constructor
argument to the corresponding parameter type and converting a
full-expression to the corresponding member type shall be one of those
allowed in a constant expression.

508.
Non-constructed value-initialized objects

According to the definition of value initialization
(8.5 [dcl.init] paragraph 5), non-union class types without
user-declared constructors are value-initialized by value-initializing
each of their members rather than by executing the (generated)
default constructor. However, a number of other items in the
Standard are described in relationship to the execution of the
constructor:

12.4 [class.dtor] paragraph 6: “Bases and
members are destroyed in the reverse order of the completion of their
constructor.” If a given base or member is value-initialized without
running its constructor, is it destroyed? (For that matter, paragraph
10 refers to “constructed” objects; is an object that is
value-initialized without invoking a constructor
“constructed?”)

15.2 [except.ctor] paragraph 2: “An object that is
partially constructed or partially destroyed will have destructors
executed for all of its fully constructed subobjects, that is, for
subobjects for which the constructor has completed
execution...”

3.8 [basic.life] paragraph 1: The lifetime of an
object begins when “the constructor call has completed.”
(In the TC1 wording — “if T is a class type
with a non-trivial constructor (12.1 [class.ctor]), the
constructor call has completed” — the lifetime of
some value-initialized objects never began; in the current wording
— “the constructor invoked to create the object is
non-trivial” — the lifetime begins before any of the
members are initialized.)

Proposed resolution (October, 2005):

Add the indicated words to 8.5 [dcl.init] paragraph 6:

A program that calls for default-initialization or
value-initialization of an entity of reference type is ill-formed. If
T is a cv-qualified type, the cv-unqualified version
of T is used for these definitions of zero-initialization,
default-initialization, and value-initialization. Even when
value-initialization of an object does not call that object's
constructor, the object is deemed to have been fully constructed once
its initialization is complete and thus subject to provisions of this
International Standard applying to “constructed” objects,
objects “for which the constructor has completed
execution,” etc.

Notes from April, 2006 meeting:

There was some concern about whether this wording covered (or
needed to cover) cases where an object is “partially
constructed.” Another approach might be simply to define
value initialization to be “construction.” Returned to
“drafting” status for further investigation.

Proposed resolution (February, 2010):

Change 8.5 [dcl.init] paragraph 7 as follows:

To value-initialize an object of type T means:

...

An object that is value-initialized is deemed to be constructed
and thus subject to provisions of this International Standard applying
to “constructed” objects, objects “for which the
constructor has completed,” etc., even if no constructor is invoked
for the object's initialization.

615.
Incorrect description of variables that can be initialized

Automatic, register, static, and external variables of namespace scope
can be initialized by arbitrary expressions involving literals and
previously declared variables and functions.

Both “automatic” and “static” are used to
describe storage durations, “register” is
a storage class specifier which indicates the object has
automatic storage duration, “external”
describes linkage, and “namespace scope” is a kind
of scope. Automatic, register, static and external, together
with namespace scope, are used to restrict the
“variables.”

Register objects are only a sub-set of automatic objects and thus
the word “register” is redundant and should be elided. If
register objects are to be emphasized, they should be mentioned like
“Automatic (including register)...”

Variables having namespace scope can never be automatic; they can
only be static, with either external or internal linkage. Therefore,
there are in fact no “automatic variables of namespace
scope,” and the “static” in “static variables
of namespace scope” is useless.

In fact, automatic and static variables already compose all
variables with either external linkage or not, and thus the
“external” becomes redundant, too, and the quoted sentence
seems to mean that all variables of namespace scope can be initialized
by arbitrary expressions. But this is not true because not all
internal variables of namespace scope can. Therefore, the restrictive
“external” is really necessary, not redundant.

As a result, the erroneous restrictive “automatic, register,
static” should be removed and the quoted sentence may be changed
to:

External variables of namespace scope can be initialized by arbitrary
expressions involving literals and previously declared variables and
functions.

Notes from the April, 2007 meeting:

This sentence is poorly worded, but the analysis given in
the issue description is incorrect. The intent is simply that
the storage class of a variable places no restrictions on the
kind of expression that can be used to initialize it (in contrast
to C, where variables of static storage duration can only be
initialized by constant expressions).

Proposed resolution (June, 2008):

Change 8.5 [dcl.init] paragraph 2 as follows:

Automatic, register, static, and external variables of namespace scopeVariables of automatic, thread, and static storage duration can
be initialized by arbitrary expressions involving literals and
previously declared variables and functions...

Notes from the September, 2008 meeting:

The existing wording is intended to exclude block-scope
extern declarations but to allow initializers in all
other forms of variable declarations. The best way to phrase
that is probably to say that all variable definitions (except for
function parameters, where the initializer syntax is used for
default arguments) can have arbitrary expressions as
initializers, regardless of storage duration.

Proposed resolution (February, 2010):

Change 8.5 [dcl.init] paragraph 2 as follows:

Automatic, register, thread_local, static, and
namespace-scoped external variables can be initialized byExcept for objects declared with the constexpr
specifier, for which see 7.1.5 [dcl.constexpr], an
initializer in the definition of a variable can consist
of arbitrary expressions involving literals and previously
declared variables and functions, regardless of the
variable's storage duration. [Example:...

741.
“plain” long long bit-fields

The type long long is missing from the list of bit-field
types in 9.6 [class.bit] paragraph 3 for which the
implementation can choose the signedness. This was presumably an
oversight. (If that is the case, we may want to reconsider the
handling of 4.5 [conv.prom] paragraph 3: a long long
bit-field that the implementation treats as unsigned will —
pending the outcome of issue 739 —
still promote to signed long long, which can lead to
unexpected results for bit-fields with the same number of bits as
long long.)

Proposed resolution (February, 2010):

Change 9.6 [class.bit] paragraph 3 as follows:

...It is implementation-defined whether a plain (neither
explicitly signed nor unsigned) char, short,
int or,long, or
long long bit-field is signed or unsigned...

738.
constexpr not permitted by the syntax of constructor declarations

According to 12.1 [class.ctor] paragraph 1, only
function-specifiers are permitted in the declaration of a
constructor, and constexpr is not a function-specifier.
(See also issue 263, in which the resolution
of a similar concern regarding the friend specifier did not
change 12.1 [class.ctor] paragraph 1 but perhaps should have
done so.)

Proposed resolution (February, 2010):

Change 12.1 [class.ctor] paragraph 1 as follows:

Constructors do not have names. A special declarator syntax
using an optional sequence of function-specifiers
(7.1.2 [dcl.fct.spec]) followed by the constructor's class
name followed by a parameter list is used to declare or define
the constructor. The syntax uses

an optional decl-specifier-seq in which each
decl-specifier is either a function-specifier or
constexpr,

the constructor's class name, and

a parameter list

in that order. In such a declaration, optional
parentheses around the constructor class name are
ignored. [Example:...

The expression-list in a mem-initializer is used to
initialize the base class or non-static data member subobject denoted
by the mem-initializer-id. The semantics of
a mem-initializer are as follows:

if the expression-list of the mem-initializer is
omitted, the base class or member subobject is value-initialized (see
8.5 [dcl.init]);

otherwise, the subobject indicated
by mem-initializer-id is direct-initialized using
expression-list as the initializer (see 8.5 [dcl.init]).

The initialization of each base and member constitutes a
full-expression. Any expression in a mem-initializer is
evaluated as part of the full-expression that performs the
initialization.

This paragraph deals only with subobjects; it needs to be made more
general to apply to the complete object as well when
the mem-initializer-id designates the constructor's class.

Proposed resolution (June, 2008):

Change 12.6.2 [class.base.init] paragraph 3 as follows:

The expression-list in a mem-initializer is used
to initialize the base class or non-static data member subobject
denoted by the mem-initializer-id. The semantics of a
mem-initializer areA mem-initializer in which the
mem-initializer-id names the constructor's class initializes the
object by invoking the selected target constructor with the
mem-initializer's expression-list. A
mem-initializer in which the mem-initializer-id names a base
class or non-static data member initializes the designated subobject
as follows:

if the expression-list of the mem-initializer
is omitted, the base class or member subobject is value-initialized
(see 8.5 [dcl.init]);

otherwise, the subobject indicated by mem-initializer-id is
direct-initialized using expression-list as the initializer (see
8.5 [dcl.init]).

...

The initialization of each base and memberperformed by
each mem-initializer constitutes a full-expression. Any
expression...

Notes from the September, 2008 meeting:

This text was significantly modified by N2756 (nonstatic data
member initializers) and needs to be reworked in light of those
changes.

Proposed resolution (February, 2010):

Change 12.6.2 [class.base.init] paragraph 7 as follows:

The expression-list or braced-init-list in a
mem-initializer is used to initialize the base class
or non-static data member subobject denoted by the
mem-initializer-iddesignated subobject (or, in
the case of a delegating constructor, the complete class
object) according to the initialization rules of
8.5 [dcl.init] for direct-initialization.

[Example: ...

—end example] The initialization of each base and
memberperformed by each mem-initializer
constitutes a full-expression...

Change 12.6.2 [class.base.init] paragraph 8 as
follows:

IfIn a non-delegating constructor, if a given
non-static data member or base class is not named by a
mem-initializer-id...

Change 12.6.2 [class.base.init] paragraph 10 as follows:

InitializationIn a non-delegating constructor,
initialization proceeds in the following order:

Change 12.6.2 [class.base.init] paragraph 12 as follows
(this is an unrelated change correcting an error noticed while
preparing the resolution of this issue):

Names in the expression-listor
braced-init-list of a mem-initializer are
evaluated in the scope of the constructor...

Change the next-to-last bullet of the note in 8.5.4 [dcl.init.list] paragraph 1 as follows:

as a base-or-member initializerin a
mem-initializer (12.6.2 [class.base.init])

If a template-parameter of a class template is a template
parameter pack, it shall be the last
template-parameter. [Note: These are not
requirements for function templates because template arguments
might be deduced (14.8.2 [temp.deduct])...

This restriction was only meant to apply to primary class
templates, not partial specializations.

Suggested resolution:

If a template-parameter of a primary class template
is a template parameter pack, it shall be the last
template-parameter. [Note: These are not
requirements for function templates or class template partial
specializations because template arguments might be deduced
(14.8.2 [temp.deduct])...

Proposed resolution (February, 2010):

Change 14.1 [temp.param] paragraph 11 as follows:

If a template-parameter of a class template has a default
template-argument, each subsequent
template-parameter shall either have a default
template-argument supplied or be a template parameter pack. If a
template-parameter of a primary class template
is a template parameter pack, it shall be the last
template-parameter. [Note: These are not
requirements for function templates or class template partial
specializations because template arguments
mightcan be deduced (14.8.2 [temp.deduct]). [Example:...

96.
Syntactic disambiguation using the template keyword

The following is the wording from
14.2 [temp.names]
paragraphs 4 and 5 that discusses the use of the "template" keyword following
. or -> and in qualified names.

When the name of a member template specialization appears after .
or -> in a postfix-expression, or after nested-name-specifier
in a qualified-id, and the postfix-expression or qualified-id
explicitly depends on a template-parameter
(14.6.2 [temp.dep]
),
the member template name must be prefixed by the keyword template.
Otherwise the name is assumed to name a non-template. [Example:

If a name prefixed by the keyword template is not the name
of a member template, the program is ill-formed.
[Note: the keyword template
may not be applied to non-template members of class templates. ]

The whole point of this feature is to say that the "template"
keyword is needed to indicate that a "<" begins a template
parameter list in certain contexts. The constraints in paragraph 5 leave
open to debate certain cases.

First, I think it should be made more clear that the template name must
be followed by a template argument list when the "template" keyword
is used in these contexts. If we don't make this clear, we would have to
add several semantic clarifications instead. For example, if you say "p->template
f()", and "f" is an overload set containing both templates
and nontemplates: a) is this valid? b) are the nontemplates in the overload
set ignored? If the user is forced to write "p->template f<>()"
it is clear that this is valid, and it is equally clear that nontemplates
in the overload set are ignored. As this feature was added purely to provide
syntactic guidance, I think it is important that it otherwise have no semantic
implications.

I propose that paragraph 5 be modified to:

If a name prefixed by the keyword template is not the name
of a member template, or an overload set containing one or more member
templates, the program is ill-formed. If the name prefixed by the template
keyword is not followed by a template-argument-list, the program
is ill-formed.

We reviewed John Spicer's paper N1528 and agreed with his
recommendations therein.

Proposed resolution (February, 2010):

Change 14.2 [temp.names] paragraph 5 as follows:

If aA name prefixed by the keyword
templateis not the name of a template,shall be a template-id or the name shall refer to a
class templatethe program is ill-formed.
[Note: the keyword template may not be applied to
non-template members of class templates. —end note]
[Note: as is the case with the typename prefix,
the template prefix is allowed in cases where it is not
strictly necessary; i.e., when the nested-name-specifier
or the expression on the left of the -> or .
is not dependent on a template-parameter, or the use does
not appear in the scope of a template. —end note]
[Example:

I am under the impression that this should compile without requiring
the insertion of the template keyword before get in the expression at
//#1. This notion is supported by this note excerpted from
14.2 [temp.names]/5:

[Note: just as is the case with the typename prefix, the template
prefix is allowed in cases where it is not strictly necessary;
i.e., when the expression on the left of the -> or ., or the
nested-name-specifier is not dependent on a template parameter.]

But 14.2 [temp.names]/4 contains this text:

When the name of a member template specialization appears after .
or -> in a postfix-expression, or after nested-name-specifier in
a qualified-id, and the postfix-expression or qualified-id
explicitly depends on a template-parameter (14.6.2), the member
template name must be prefixed by the keyword template. Otherwise
the name is assumed to name a non-template.

The only way that I can read this to support my assumption above is if
I assume that the phrase postfix-expression is used twice above with
different meaning. That is I read the first use as referring to the
full expression while the second use refers to the subexpression
preceding the operator. Is this the correct determination of intent? I
find this text confusing. Would it be an improvement if the second
occurrence of "postfix-expression" should be replaced by "the
subexpression preceding the operator". Of course that begs the
question "where is subexpression actually defined in the standard?"

John Spicer:
I agree that the code should work, and that we should tweak
the wording.

Proposed resolution (March, 2010):

Change 14.2 [temp.names] paragraph 4 as follows:

When the name of a member template specialization appears after
. or -> in a postfix-expression, or
after a nested-name-specifier in a qualified-id,
and the object or pointer expression of thepostfix-expression or the
nested-name-specifier in thequalified-idexplicitly depends on a
template-parametertemplate
parameter (14.6.2 [temp.dep]) but does not refer
to a member of the current instantiation (14.6.2.1 [temp.dep.type]), the member template name must be prefixed by
the keyword template. Otherwise the name is assumed to
name a non-template. [Example:...

773.
Parentheses in address non-type template arguments

According to 14.3.2 [temp.arg.nontype] paragraph 1, bullet 3, one
of the acceptable forms of a non-type, non-template template argument
is:

the address of an object or function... expressed as &id-expression where the & is optional if the name
refers to a function or array, or if the corresponding
template-parameter is a reference

It is not clear from this whether a template argument like
(&i) satisfies the requirement or not.

Notes from the March, 2009 meeting:

The consensus of the CWG was that the parentheses should be
allowed.

Proposed resolution (February, 2010):

Change 14.3.2 [temp.arg.nontype] paragraph 1 bullet 3 as follows:

the address of an object or function with external linkage,
including function templates and function template-ids but
excluding non-static class members, expressed (ignoring
parentheses) as &id-expression, except
thatwhere the &is optionalmay be omitted if the name refers to a function or
array, orand shall be omitted if the
corresponding template-parameter is a reference; or

[Drafting note: The change requiring the omission of the
& in the reference case fixes an existing problem that
is not related to this issue.]

674.
“matching specialization” for a friend declaration

if the name of the friend is a qualified-id and a
matching specialization of a function template is found in the
specified class or namespace, the friend declaration refers to that
function template specialization, otherwise,

The key is that the wording talks about a “matching
specialization,” which to me means that N::f<int> is befriended only
if that specialization existed in N before the friend declaration. So
it's ill-formed as written, but if we move the call to N::f<int> up to
a point before the definition of A, it's well-formed.

That seems surprising, especially given that the first bullet does
not require a pre-existing specialization. So I suggest replacing
bullet 3 with something like:

if the name of the friend is a qualified-id and a
matching function template is found in the specified class or
namespace, the friend declaration refers to the deduced specialization
of that function template, otherwise,

Proposed resolution (June, 2010):

Change 14.5.4 [temp.friend] paragraph 1 bullet 3 as follows:

...For a friend function declaration that is not a template
declaration:

...

if the name of the friend is a qualified-id and a
matching specialization of a function template is
found in the specified class or namespace, the friend declaration
refers to that function template specializationthe deduced specialization of that function template
(14.8.2.6 [temp.deduct.decl]),
otherwise,

...

(This resolution depends on that of issue 873; in particular, the cross-reference to 14.8.2.6
[temp.deduct.decl] refers to a new section added by the resolution
of that issue.)

How should we treat the implicit this parameter of #1 and the
explicit first parameter of #2?

Option 0: Make them unordered.

Option 1: If either function is a non-static member function, ignore
any this parameter and ignore the first parameter of any
non-member function. This option will select #2, as
“B<T>&” is more specialized than
“T&”.

Option 2: Treat the this parameter as if it were of
reference to object type, and then perform comparison to the first
parameter of the other function. The other function's first parameter
will either be another this parameter, or it will be a
by-value or by-reference object parameter. In the example above,
this option will also select #2.

The difference between option 1 and option 2 can be seen in the
following example:

Should this select #1, select #2, or be ambiguous? Option 1 will
select #2, because “A&” is more specialized
than “T&”. Option 2 will make this example
ambiguous, because “B<A>&” is more
specialized than “T&”.

the current rules would make these unordered. Option 2 thus seems
more consistent with this existing behavior.

Notes from the April, 2006 meeting:

The group favored option 2.

Proposed resolution (February, 2010):

Change 14.5.6.2 [temp.func.order] paragraph 3 as follows:

...and substitute it for each occurrence of that parameter in
the function type of the template. If only one of the
function templates is a non-static member, that function template
is considered to have a new first parameter inserted in its
function parameter list. The new parameter is of type
“reference to cvA,” where cv are
the cv-qualifiers of the function template (if any) and
A is the class of which the function template is a
member. [Note: This allows a non-static member to be
ordered with respect to a nonmember function and for the results
to be equivalent to the ordering of two equivalent
nonmembers. —end note] [Example:

The key issue is when "g" is looked up, i.e., whether both overloaded
template "g" functions are available at the call site or only the
first. Clearly, the entire postfix-expression "g<T>(j)" is dependent,
but when is the set of available template functions determined?

For consistency with the rules about when the set of available
overloads is determined when calling a function given by an
unqualified-id, I would think that we should postpone determining the
set of template functions if (and only if) any of the explicit
template arguments are dependent.

John Spicer:
I agree that there should be a core issue for this. The definition of
"dependent name" (14.6.2 [temp.dep] paragraph 1)
should probably be modified to cover this case. It
currently only handles cases where the function name is a simple
identifier.

Notes from the March 2004 meeting:

A related issue is a call with a qualified name and dependent
arguments, e.g., x::y(depa, depb).

Proposed resolution (June, 2010):

Change 14.6.2 [temp.dep] paragraph 1 as follows:

...In an expression of the form:

postfix-expression(expression-listopt)

where the postfix-expression is an
unqualified-idid-expression, the
unqualified-idid-expression denotes a dependent
name if and only if any of the expressions in
the expression-list is a type-dependent expression
(14.6.2.2 [temp.dep.expr]) or if the
unqualified-id of the id-expression is a
template-id in which any of the template arguments depends
on a template parameter. If an operand of an operator is a
type-dependent expression, the operator also denotes a dependent
name. Such names are unbound and are looked up at the point of
the template instantiation (14.6.4.1 [temp.point]) in
both the context of the template definition and the context of
the point of instantiation.

Change 14.6.4.2 [temp.dep.candidate] paragraph 1 as follows:

For a function call that depends on a template parameter, if
the function name is an unqualified-id
or if the function is called using operator
notation, the candidate functions are found using the usual
lookup rules (3.4.1 [basic.lookup.unqual], 3.4.2 [basic.lookup.argdep], 3.4.3 [basic.lookup.qual]) except
that:

For the part of the lookup using unqualified name
lookup (3.4.1 [basic.lookup.unqual]) or qualified name
lookup (3.4.3 [basic.lookup.qual]), only function
declarations from the template definition context are
found.

For the part of the lookup using associated
namespaces (3.4.2 [basic.lookup.argdep]), only function
declarations found in either the template definition context
or the template instantiation context are found.

If the function name is an unqualified-id
and the call would be ill-formed or would find a better
match had the lookup within the associated namespaces considered
all the function declarations with external linkage introduced in
those namespaces in all translation units, not just considering
those declarations found in the template definition and template
instantiation contexts, then the program has undefined
behavior.

Someone asked whether line #1 is well-formed and I responded "no"
based on my understanding of the rules in 14.6.1.
After a second looking, I've realized that the above case is currently
missing from the list.

But the case of a 'member template' is missing. I believe it should
follow the same rule as above. The reason is this.

In the case listed in 14.6.1 (having to do with members of classes),
the "algorithm" seems to be this:

put the "template parameter scope"[1] on the top of active
scope stack. That will make the template parameter
declarations the innermost bindings.

Enter the class scope. That will push more scopes on the stack.
In particular, any bindings from non-dependent base classes or
from the class definition will hide any previous bindings,
especially the template parameter declarations.

The above formulation uniformly covers paragraphs 5 and 7 of section
14.6.1 and gives a general view of how name lookup is supposed to
happen.

I believe that any rule, coherent with 14.6.1/5 and 14.6.1/7, for
covering the cases of member templates (example-1) will be described
by the above "algorithm".

Am I missing something?

[1] of course, the standard text does not formally speak of "template
parameter scope", but we all know that the template parameters
"live" somewhere. I'm using that terminology to designate the
declarative region of the template parameters.

Mike Miller:
I have a somewhat different perspective on this question. I
think your example-1 is fundamentally different from your
example-2 and example-3. Looking, for instance, at your
example-2, I see four nested scopes:

Here it seems clear to me that the template parameter hides the
class member.

It might help to look at the case where the function template is
defined inline in the class:

struct S {
int C;
template<class C> int f() {
C c; // #1
}
};

It would be pretty strange, I think, if the #1 C were the member
and not the template parameter. It would also be odd if the
name lookup were different between an inline definition and an
out-of-line definition.

Basically, the standard is okay. We think Gaby's desired
cases like #1 should be ill-formed.

There is a wording problem in 14.6.1 [temp.local] paragraph 7.
It says:

In the definition of a member of a class template that appears outside of the
class template definition, the name of a member of this template hides
the name of a template-parameter.

It should say "hides the name of a template-parameter of the class template
(but not a template-parameter of the member, if the member is itself a
template)" or words to that effect.

Proposed resolution (February, 2010):

Change 14.6.1 [temp.local] paragraph 8 as follows:

In the definition of a member of a class template that appears
outside of the class template definition, the name of a member of
thisthe class template hides the name of a
template-parameterof any enclosing class templates
(but not a template-parameter of the member, if the member
is a class or function template). [Example:

Is sizeof applied to a nested enumeration a
value-dependent expression (14.6.2.3 [temp.dep.constexpr])?

There are three distinct cases that might have different answers
to this question:

template<typename T> struct S {
enum E { e0 };
};

Here, the size of E is, in principle, known at the time
the template is defined.

template<short I> struct S {
enum E { e0 = I };
};

In this case, the minimum size required for E cannot be
determined until instantiation, but it is clear that the underlying
type need be no larger than short.

template<typename T> struct S {
enum E { e0 = T::e0; };
}

Here, nothing can be known about the size of E at the time
the template is defined.

14.6.2.3 [temp.dep.constexpr] paragraph 2 says that a
sizeof expression is value-dependent if the type of the
operand is type-dependent. Unless enumerations are given special
treatment, all three of these examples will have value-dependent
sizes. This could be surprising for the first case, at least, if not
the second as well.

Are nested enumerators value-dependent expressions?

Again the question of dependent initializers comes into play. As an
example, consider:

template<short I> struct S {
enum E { e0, e1 = I, e2 };
};

There seem to be three possible approaches as to whether the
enumerators of E are value-dependent:

The enumerators of a nested enumeration are all
value-dependent, regardless of whether they have a value-dependent
initializer or not. This is the current position of 14.6.2.3 [temp.dep.constexpr] paragraph 2, which says that an identifier is
value-dependent if it is a name declared with a dependent
type.

The enumerators of a nested enumeration are all value-dependent
if any of the enumeration's enumerators has a value-dependent
initializer. In this approach, e0 would be value-dependent,
even though it is clear that it has the value 0.

An enumerator of a nested enumeration is value-dependent only
if it has a value-dependent initializer (explict or implicit). This
approach would make e1 and e2 value-dependent, but
not e0.

With the normal treatment of enumerations, the type of a
might be either int[UINT_MAX+2] or int[1], depending
on whether the value of T::O was such that the underlying
type of E is unsigned int or long.

One possibility for addressing this problem under the third
approach would be to treat a given enumerator as having the type of
its initializer in such cases, rather than the enumeration type. This
would be similar to the way enumerators are treated within the
enumerator list, before the enumeration declaration is complete
(7.2 [dcl.enum] paragraph 5). The argument against this
is that it makes arithmetic using enumerators behave differently when
the enumeration is a member of a class template and when it is not.

Notes from the April, 2005 meeting:

The CWG agreed on the following positions:

Nested enumerations are dependent types.

The result of the sizeof operator applied to a
nested enumeration is value-dependent unless there are no
dependent initializers in its definition; the first case above
is not dependent, while the second and third are dependent.

The approach described in 3.C above is correct. This is
similar to the treatment of static const integral data members,
which are dependent only if their initializer is dependent.

Notes from the October, 2005 meeting:

There was no consensus among the CWG regarding question #3
(which enumerators should be considered value-dependent). The
argument in favor of 3.C is principally that the values of enumerators
with non-dependent initializers are known at definition time, so there
is no need to treat them as dependent.

One objection to 3.C is that, according to the consensus of the
CWG, the enumeration type is dependent and thus even the known values
of the enumeration would have a dependent type, which could affect the
results when such enumerations are used in expressions. A possible
response to this concern would be to treat non-dependent initializers
as having the type of the initializer rather than the enumeration
type, similar to the treatment of enumerators within
the enumerator-list (7.2 [dcl.enum] paragraph 5).
However, this approach would be inconsistent with the treatment of
other enumeration types. It would also interfere with overload
resolution (e.g., the call in the example under question #1 above
would resolve to f(int) with this approach rather
than f(S<int>::E)).

Those in favor of option 3.A also suggested that it would be simpler
and require less drafting: if all the enumerators have the (dependent)
type of the enumeration, 14.6.2.3 [temp.dep.constexpr] paragraph 2
already says that a name with a dependent type is value-dependent, so
nothing further would need to be said. Option 3.C would require
additional caveats to exempt some enumerators.

The proponents of 3.A also pointed out that there are many other
cases where a known value with a dependent type is treated as dependent:

static const T t = 0;
... A<t> ...

or

template <int I> void f() {
g(I-I);
}

With regard to current practice, g++ and MSVC++ implement 3.A, while
EDG implements 3.C.

Notes from the July, 2009 meeting:

The consensus of the CWG was that all the types and values are
dependent.

Proposed resolution (June, 2010):

Change 14.6.2.1 [temp.dep.type] paragraph 6 as
follows:

A type is dependent if it is

...

a nested class or enumeration that is a member
of the current instantiation,

...

546.
Explicit instantiation of class template members

Issue 470 specified the explicit
instantiation of members of explicitly-instantiated class templates.
In restricting the affected members to those “whose definition
is visible at the point of instantiation,” however, this
resolution introduced an incompatibility between explicitly
instantiating a member function or static data member and explicitly
instantiating the class template of which it is a member (14.7.2 [temp.explicit] paragraph 3 requires only that the class template
definition, not that of the member function or static data member, be
visible at the point of the explicit instantiation). It would be
better to treat the member instantiations the same, regardless of
whether they are directly or indirectly explicitly instantiated.

Notes from the April, 2006 meeting:

In forwarding document J16/06-0057 = WG21 N1987 to be approved by
the full Committee, the CWG reaffirmed its position that explicitly
instantiating a class template only explicitly instantiates those of
its members that have been defined before the point of the explicit
instantiation. The effect of the position advocated above would be to
require all non-exported member functions to be defined in the
translation unit in which the class template is explicitly
instantiated (cf paragraph 4), and we did not want to require that.
We did agree that the “visible” terminology should be
replaced by wording along the lines of “has been
defined.”

Proposed resolution (February, 2010):

Change 14.7.2 [temp.explicit] paragraph 8 as follows:

An explicit instantiation definition that names a class template
specialization explicitly instantiates the class template
specialization and is only an explicit instantiation definition
of members whose definition is visiblethat have
been defined at the point of instantiation.

Entities generated from a template with internal linkage are
distinct from all entities generated in other translation units.

But is the explicit specialization “generated
from” the primary template? Does it inherit the local
linkage? If so, where do I find a reference saying so
explicitly?

James Widman: Data points: EDG 3.8 inherits, GCC 4.0
does not.

Mike Miller: There's a pretty strong presumption that
the linkage of an explicit specialization cannot be different
from that of its primary template, given that storage class
specifiers cannot appear in an explicit specialization
(7.1.1 [dcl.stc] paragraph 1).

Notes from the April, 2007 meeting:

The CWG agreed that the linkage of an explicit specialization
must be that of the template. Gabriel dos Reis will investigate
the reason for the different behavior of g++.

Proposed resolution (March, 2010):

Change 14 [temp] paragraph 4 as follows:

...Entities generated fromSpecializations
(explicit or implicit) of a template withthat has internal linkage are distinct from all
entities generatedspecializations in other
translation units...

621.
Template argument deduction from function return types

It does not appear that the following example is well-formed,
although most compilers accept it:

template <typename T> T foo();
template <> int foo();

The reason is that 14.7.3 [temp.expl.spec] paragraph 11 only
allows trailing template-arguments to be omitted if they
“can be deduced from the function argument type,” and
there are no function arguments in this example.

14.7.3 [temp.expl.spec] should probably say “function
type” instead of “function argument type.” Also,
a subsection should probably be added to 14.8.2 [temp.deduct]
to cover “Deducing template arguments from declarative
contexts” or some such. It would be essentially the same as
14.8.2.2 [temp.deduct.funcaddr] except that the function type from
the declaration would be used as the type of P.

Proposed resolution (March, 2008):

Insert the following as a new subsection after
14.8.2.5 [temp.deduct.type]:

14.9.2.6 Deducing template arguments in a declaration
that names a specialization of a function template

[temp.deduct.funcdecl]

Template arguments can be deduced from the function type
specified when declaring a specialization of a function
template. [Note: this can occur in the context of an
explicit specialization, an explicit instantiation, or a
friend declaration. —end note] The function
template's function type and the declared type are used as
the types of P and A, and the deduction is
done as described in 14.8.2.5 [temp.deduct.type].

Change 14.7.3 [temp.expl.spec] paragraph 11 as
follows:

A trailing template-argument can be left unspecified in the
template-id naming an explicit function template specialization
provided it can be deduced from the function argument type
(14.9.2.6 [temp.deduct.funcdecl])...

Notes from the September, 2008 meeting:

The proposed resolution is probably more than is needed.
Instead of a complete new section, the material could become a
paragraph in 14.5.6 [temp.fct].

Proposed resolution (February, 2010):

Add the following paragraph at the end of 14.5.6 [temp.fct]:

In a declaration that names a specialization of a function
template, template arguments can be deduced from the function
type. [Note: this can occur in the context of an explicit
specialization, an explicit instantiation, or a friend
declaration. —end note] The function template's
function type and the declared type are used as the types of
P and A and the deduction is done as described
in 14.8.2.5 [temp.deduct.type].

941.
Explicit specialization of deleted function template

According to 14.7.3 [temp.expl.spec] paragraph 1, only non-deleted
function templates may be explicitly specialized. There doesn't appear to
be a compelling need for this restriction, however, and it could be useful
to forbid use of implicitly-instantiated specializations while still
allowing use of explicitly-specialized versions.

Proposed resolution (February, 2010):

Change 14.7.3 [temp.expl.spec] paragraph 1 as follows:

An explicit specialization of any of the following:

non-deleted function template

class template

non-deleted member function of a class template

static data member of a class template

member class of a class template

member class template of a class or class template

non-deleted member function template of a class or
class template

can be declared...

575.
Criteria for deduction failure

When all template arguments have been deduced or obtained from default
template arguments, all uses of template parameters in non-deduced
contexts are replaced with the corresponding deduced or default
argument values. If the substitution results in an invalid type, as
described above, type deduction fails.

Shouldn't the substitution occur for all uses of the parameters, so
that any of them could result in deduction failure?

Proposed resolution (October, 2006):

Change 14.8.2 [temp.deduct] paragraph 5 as follows:

...When all template arguments have been deduced or obtained from
default template arguments, all uses of template parameters in
non-deduced contextsthe function type are replaced with
the corresponding deduced or default argument values. If the
substitution results in an invalid type, as described above, type
deduction fails.

Notes from the September, 2008 meeting:

This issue was returned to "drafting" status in order to
coordinate the wording with the concepts proposal.

Proposed resolution (March, 2010):

Change 14.8.2 [temp.deduct] paragraph 5 as follows:

When all template arguments have been deduced or obtained from
default template arguments, all uses of template parameters in
non-deduced contextsthe template parameter list
of the template and the function type are replaced with the
corresponding deduced or default argument values. If the
substitution results in an invalid type, as described above, type
deduction fails.

709.
Enumeration names as nested-name-specifiers in deduction failure

The current rules in 14.8.2 [temp.deduct] say that type
deduction fails as a result of attempting to use a type that is
not a class type in a qualified name. However, it is now possible
to use enumeration names as nested-name-specifiers, so this
rule needs to be updated accordingly.

Proposed resolution (February, 2010):

Change the third bullet of the note in 14.8.2 [temp.deduct]
paragraph 8 as follows:

[Note: Type deduction may fail for the following reasons:

...

Attempting to use a type that is not a class or
enumeration type in a qualified
name. [Example:...

There need to be rules that deduce the template arguments for the
specializations in the same way that the arguments are deduced in the
calls.

Proposed resolution (February, 2010):

Change 14.8.2.5 [temp.deduct.type] paragraph 10 as
follows:

Similarly, if P has a form that contains
(T), then each parameter type
Pi of the respective
parameter-type-list of P is compared with the
corresponding parameter type Ai of the
corresponding parameter-type-list of A. If
P and A are function types that originated from
deduction when taking the address of a function template
(14.8.2.2 [temp.deduct.funcaddr]) or when deducing template
arguments from a function declaration ([temp.deduct.decl]) and
Pi and Ai
are parameters of the top-level parameter-type-list of
P and A, respectively, Pi
is adjusted if it is an rvalue reference to
a cv-unqualified template parameter and
Ai is an lvalue reference, in which case
the type of Pi is
changed to be the template parameter type (i.e.,
T&& is changed to simply
T). [Note: As a result, when
Pi is T&& and
Ai is X&, the adjusted
Pi will be T, causing
T to be deduced as X&. —end
note] [Example:

In a declaration whose declarator-id refers to a
specialization of a function template, template argument
deduction is performed to identify the specialization to which
the declaration refers. Specifically, this is done for explicit
instantiations (14.7.2 [temp.explicit]), explicit
specializations (14.7.3 [temp.expl.spec]), and certain friend
declarations (14.5.4 [temp.friend]). This is also done to
determine whether a function template specialization matches a
placement operator new (3.7.4.2 [basic.stc.dynamic.deallocation],
5.3.4 [expr.new]). In all these cases, P is the
type of the function template being considered as a potential
match and A is the function type from the
declaration. The deduction is done as described in 14.8.2.5 [temp.deduct.type].

If, for the set of function templates so considered, there is
either no match or more than one match after partial ordering has
been considered (14.5.6.2 [temp.func.order]), deduction fails
and the declaration is ill-formed.

475.
When is std::uncaught_exception() true? (take 2)

Given this piece of code and S having a user-defined
ctor, at precisely which point must
std::uncaught_exception() return true and where
false?

try { S s0; throw s0; } catch (S s2) { }

My understanding of the semantics of the code is as
follows:

The throw expression creates a temporary for a copy of
s0, say s1, using the copy ctor of
S. In this invocation of the copy ctor
uncaught_exception() must return true.

s0 is destroyed during stack unwinding. In the
invocation of S dtor uncaught_exception() must
still return true.

The variable s2 is initialized from s1 by
invoking the copy ctor of S. In this invocation
uncaught_exception() must also return
true.

s2 and s1 are destroyed. In the invocations
of S dtor uncaught_exception() must return
false.

Is my understanding correct?

15.1 [except.throw] paragraph 3 talks about “the
exception object” when describing the semantics of the
throw-expression:

a throw-expression initializes a temporary object, called
the exception object...

However, 15.5.1 [except.terminate] paragraph 1 talks about
“the expression to be thrown” when enumerating the
conditions under which terminate() is called:

when the exception handling mechanism, after completing
evaluation of the expression to be thrown but before the
exception is caught (15.1 [except.throw]), calls a user
function that exits via an uncaught exception...

And, 15.5.3 [except.uncaught] paragraph 1 refers to
“the object to be thrown” in the description of
uncaught_exception():

The function std::uncaught_exception() returns
true after completing evaluation of the object to be
thrown...

Are all these objects one and the same? I believe the answer
is important in case the construction of the temporary exception
object throws another exception.

Suppose they are the same. Then uncaught_exception()
invoked from the copy ctor for s1 (from the example
[above]) must return false and a new exception (e.g.,
bad_alloc) may be thrown and caught by a matching
handler (i.e., without calling terminate()).

But if they are not the same, then
uncaught_exception() invoked from the copy ctor for
s1 must return true and throwing another
exception would end up calling terminate(). This would,
IMO, have pretty severe consequences on writing exception safe
exception classes.

As in the first case, different compilers behave differently,
with most compilers not calling terminate() when the
ctor for the temporary exception object throws. Unfortunately,
the two compilers that I trust the most do call
terminate().

FWIW, my feeling is that it should be possible for the copy
ctor invoked to initialize the temporary exception object to
safely exit by throwing another exception, and that the new
exception should be allowed to be caught without calling
terminate.

Mike Miller: The way I see this, a throw-expression has an
assignment-expression as an operand. This expression is
“the expression to be thrown.” Evaluation of this
expression yields an object; this object is “the object to
be thrown.” This object is then copied to the exception
object.

Martin Sebor: Here's a survey of the return value from
uncaught_exception() in the various stages of exception
handling, implemented by current compilers:

expr

temp

unwind

handlr

2nd ex

HP aCC 6

0

0

1

0

OK

Compaq C++ 6.5

0

0

1

1

ABRT

EDG eccp 3.4

0

1

1

1

ABRT

g++ 3.4.2

0

0

1

0

OK

Intel C++ 7.0

0

0

1

0

OK

MIPSpro 7.4.1

0

0

1

1

ABRT

MSVC 7.0

0

0

1

0

OK

SunPro 5.5

1

1

1

0

OK

VisualAge 6.0

0

1

1

1

OK

In the table above:

expr

is the evaluation of the assignment-expression in the
throw-expression

temp

is the invocation of the copy ctor for the unnamed temporary
exception object created by the runtime.

unwind

is stack unwinding.

handlr

is the invocation of the copy ctor in the
exception-declaration in the catch handler.

2nd ex

describes the behavior of the implementation when the
invocation of the copy ctor for the unnamed temporary exception
object [temp] throws another exception.

Proposed resolution (October, 2004):

Change 15.1 [except.throw] paragraph 3 as
follows:

A throw-expression initializes a temporary object, called the
exception object, theby copying the thrown
object (i.e., the result of evaluating its
assignment-expression operand) to it. The type of
whichthe exception object is determined by
removing any top-level cv-qualifiers from the static type
of the operand of throw and adjusting the type from
“array of T” or “function returning
T” to “pointer to T” or
“pointer to function returning T,”
respectively. [Note: the temporary object created forby a throw-expressionthatwhose
operand is a string literal is never of type char*
or wchar_t*; that is, the special conversions for string
literals from the types “array of const
char” and “array of const
wchar_t” to the types “pointer to
char” and “pointer to
wchar_t,” respectively (4.2 [conv.array]), are never applied to the operand of a
throw-expression. —end note] The temporary is
an lvalue and is used to initialize the variable named in the
matching handler (15.3 [except.handle]). The type of the
operand of athrow-expression shall not be an
incomplete type, or a pointer to an incomplete type other than
(possibly cv-qualified) void. [...]

Change the note in 15.3 [except.handle] paragraph 3
as follows:

[Note: a throw-expressionoperand thatwhich is an integral constant expression of integer type
that evaluates to zero does not match a handler of pointer type;
that is, the null pointer constant conversions (4.10 [conv.ptr], 4.11 [conv.mem]) do not
apply. —end note]

Change 15.5.1 [except.terminate] paragraph 1 bullet 1
as follows:

when the exception handling mechanism, after completing
evaluation of the expression to be thrownoperand of
throw but before the exception is caught
(15.1 [except.throw]), calls a user function that exits
via an uncaught exception,

Change 15.5.3 [except.uncaught] paragraph 1 as
follows:

The function std::uncaught_exception() returns
true after completing evaluation of the object to be
thrownoperand of throw until completing the
initialization of the exception-declaration in the
matching handler (18.8.4 [uncaught]).

Change 18.8.4 [uncaught] paragraph 1 by adding
the indicated words:

Returns:true after completing evaluation of
the operand of a throw-expression until either
completing initialization of the exception-declaration in
the matching handler or entering unexpected() due to the
throw; or after entering terminate() for any reason
other than an explicit call to terminate().
[Note: This includes stack unwinding (15.2 [except.ctor]). —end note]

Notes from the April, 2005 meeting:

The CWG discussed this resolution both within the group and with
other interested parties. Among the points that were made:

Martin Sebor pointed to a
posting
in which he argues that writing copy constructors is more difficult if
an exception during the copy to the exception object will result in a
call to std::terminate().

In response to a question about why the copy to the exception
object is different from the copy from the exception object to the
object in the exception-declaration, it was observed that the
writer of the handler can avoid the second copy (by using a reference
declaration), but the first copy is unavoidable.

John Spicer observed that not exiting via exception should be a
design constraint for copy constructors in exception objects,
regardless of whether std::terminate() is called or
not.

Adopting the position that uncaught_exception()
returns false during the copy to the exception object would
reduce the differences between the case where that copy is elided and
the case where it is performed.

Jason Merrill observed that making uncaught_exception()
return false during the copy to the exception object would
simplify the code generated by g++; as it currently stands, the
compiler must generate code to catch exceptions during that copy so
std::terminate() can be called.

Bjarne Stroustrup worried that allowing the copy constructor to
throw an exception during the copy to the exception object could
result in a serious and specific exception being silently transformed
into a more trivial and generic one (although the CWG later noted that
this risk already exists if something in the expression being thrown
throws an exception before the expression completes).

The CWG felt that more input from a wider audience was necessary
before a decision could be made on the appropriate resolution.

Notes from the April, 2006 meeting:

The CWG agreed with the position that std::uncaught_exception()
should return false during the copy to the exception object
and that std::terminate() should not be called if that
constructor exits with an exception. The issue was returned to
“drafting” status for rewording to reflect this position.

Additional notes (September, 2007):

Although this issue deals primarily with when
std::uncaught_exception() begins to return true, the
specification of when it begins to return false is also
problematic. There are two parallel sections that define the meaning
of std::uncaught_exception() and each has a different
problem. 15.5.3 [except.uncaught] reads,

The function std::uncaught_exception() returns true
after completing evaluation of the object to be thrown until
completing the initialization of the exception-declaration in
the matching handler (18.8.4 [uncaught]).

The problem here is that whether an exception is considered
caught (the underlying condition tested by the function) is here
presented in terms of having initialized the exception-declaration,
while in other places it is specified by having an active handler for
the exception, e.g., 15.1 [except.throw] paragraph 6:

An exception is considered caught when a handler for that exception
becomes active (15.3 [except.handle]).

This distinction is important because of 15.3 [except.handle]
paragraph 3:

A handler is considered active when initialization is complete for the
formal parameter (if any) of the catch clause. [Note: the
stack will have been unwound at that point. —end note]
Also, an implicit handler is considered active
when std::terminate() or std::unexpected() is
entered due to a throw.

Note that there is no exception-declaration to be
initialized for the std::terminate() and
std::unexpected() cases; nevertheless, according to
18.8.4 [uncaught], std::uncaught_exception()
is supposed to return false when one of those two functions
is entered.

The specification in 18.8.4 [uncaught] is not well
phrased, however, and is open to misinterpretation. It reads,

Returns:true after completing evaluation of a
throw-expression until either completing initialization of the
exception-declaration in the matching handler or entering
unexpected() due to the throw; or after
entering terminate() for any reason other than an explicit
call to terminate().

The problem here is lack of parallelism: does “after
entering terminate” refer to the condition for returning
true or false? This would be better phrased along
the lines of

Returns:true after completing evaluation of a
throw-expression until a handler for the exception becomes
active (15.3 [except.handle]).

Proposed resolution (March, 2010):

Change 15.5.1 [except.terminate] paragraph 1 bullet 1 as
follows:

In the following situations exception handling must be
abandoned for less subtle error handling techniques:

when the exception handling mechanism, after
completing evaluation of the expression to be thrownthe initialization of the exception object but before
the exception is caughtactivation of a handler
for the exception (15.1 [except.throw]), calls a
function that exits via an uncaught exception, [Footnote:
For example, if the object being thrown is of a class with a copy
constructor, std::terminate() will be called if that
copy constructor exits with an exception during a
throwthe initialization of the formal
parameter of a catch clause. —end
footnote]

...

Change 15.5.3 [except.uncaught] paragraph 1 as follows:

The function std::uncaught_exception() returns
true after completing evaluation of the object to
be thrownthe initialization of the exception object
(15.1 [except.throw]) until completing the
initialization of the exception-declaration in the
matching handleractivation of a handler for the
exception (15.3 [except.handle],
18.8.4 [uncaught])...

Change 18.8.4 [uncaught] paragraph 1 as follows:

Returns:true after completing evaluation of a
throw-expressioninitializing an exception
object 15.1 [except.throw] until either
completing initialization of the exception-declaration in
the matching handler or entering unexpected() due to the
throw; or after entering terminate() for any reason
other than an explicit call to terminate()a
handler for the exception (including unexpected() or
terminate()) is activated (15.3 [except.handle]). [Note: This includes stack unwinding
(15.2 [except.ctor]). —end note]

Issues with "WP" Status

Issues with "CD1" Status

663.
Valid Cyrillic identifier characters

The C99 and C++ Standards disagree about the validity of two
Cyrillic characters for use in identifiers. C++ (_N2691_.E [extendid]) says that 040d is valid in an identifier but that 040e is
not; C99 (Annex D) says exactly the opposite. In fact, both
characters should be accepted in identifiers; see
the
Unicode chart.

Proposed resolution (February, 2008):

The reference in paragraph 2 should be changed to ISO/IEC TR 10176:2003
and the table should be changed to conform to the one in that document
(beginning on page 34).

357.
Definition of signature should include name

Section 1.3 [intro.defs], definition of "signature"
omits the function name as part of the signature. Since the name participates
in overload resolution, shouldn't it be included in the definition?
I didn't find a definition of signature in the ARM,
but I might have missed it.

Fergus Henderson:
I think so. In particular, 17.6.3.3.2 [global.names]
reserves certain "function
signatures" for use by the implementation, which would be wrong
unless the signature includes the name.

-2- Each global function signature declared with external linkage in a
header is reserved to the implementation to designate that function
signature with external linkage.

-5- Each function signature from the Standard C library declared with
external linkage is reserved to the implementation for use as a
function signature with both extern "C" and extern "C++" linkage,
or as a name of namespace scope in the global namespace.

Other uses of the term "function signature" in the description of the
standard library also seem to assume that it includes the name.

James Widman:

Names don't participate in overload resolution; name lookup is
separate from overload resolution. However, the word
“signature” is not used in clause 13 [over].
It is used in linkage and declaration matching (e.g.,
14.5.6.1 [temp.over.link]). This suggests that the name
and scope of the function should be part of its signature.

Proposed resolution (October, 2006):

Replace 1.3 [intro.defs] “signature”
with the following:

the name and the parameter-type-list (8.3.5 [dcl.fct])
of a function, as well as the class or namespace of which it is a
member. If a function or function template is a class member its
signature additionally includes the cv-qualifiers (if any) on
the function or function template itself. The signature of a function
template additionally includes its return type and its template
parameter list. The signature of a function template specialization
includes the signature of the template of which it is a specialization
and its template arguments (whether explicitly specified or deduced).
[Note: Signatures are used as a basis for name-mangling and
linking. —end note]

Delete paragraph 3 and replace the first sentence of
14.5.6.1 [temp.over.link] as follows:

The signature of a function template specialization consists of the
signature of the function template and of the actual template
arguments (whether explicitly specified or deduced).

The signature of a function template consists of its function
signature, its return type and its template parameter listis
defined in 1.3 [intro.defs]. The names
of the template parameters are significant...

537.
Definition of “signature”

The standard defines “signature” in two places:
1.3 [intro.defs] and 14.5.6.1 [temp.over.link]
paragraphs 3-4. The former seems to be meant as a formal definition
(I think it's the only place covering the nontemplate case), yet it
lacks some bits mentioned in the latter (specifically, the notion of a
“signature of a function template,” which is part of every
signature of the associated function template specializations).

Also, I think the 1.3 [intro.defs] words “the
information about a function that participates in overload
resolution” isn't quite right either. Perhaps, “the
information about a function that distinguishes it in a set of
overloaded functions?”

Eric Gufford:

In 1.3 [intro.defs] the definition states that
“Function signatures do not include return type, because that
does not participate in overload resolution,” while 14.5.6.1 [temp.over.link] paragraph 4 states “The signature of a
function template consists of its function signature, its return type
and its template parameter list.” This seems inconsistent and
potentially confusing. It also seems to imply that two identical
function templates with different return types are distinct
signatures, which is in direct violation of 13.3 [over.match]. 14.5.6.1 [temp.over.link] paragraph 4 should be
amended to include verbiage relating to overload resolution.

Either return types are included in function signatures, or they're
not, across the board. IMHO, they should be included as they are an
integral part of the function declaration/definition irrespective of
overloads. Then verbiage should be added about overload resolution to
distinguish between signatures and overload rules. This would help
clarify things, as it is commonly understood that overload
resolution is based on function signature.

In short, the term “function signature” should be made
consistent, and removed from its (implicit, explicit or otherwise)
linkage to overload resolution as it is commonly understood.

James Widman:

The problem is that (a) if you say the return type is part of the
signature of a non-template function, then you have overloading but
not overload resolution on return types (i.e., what we have now with
function templates). I don't think anyone wants to make the language
uglier in that way. And (b) if you say that the return type is not
part of the signature of a function template, you will break code.
Given those alternatives, it's probably best to maintain the status
quo (which the implementors appear to have rendered faithfully).

513.
Non-class “most-derived” objects

The standard uses “most derived object” in some places
(for example, 1.3 [intro.defs] “dynamic
type,” 5.3.5 [expr.delete]) to refer to objects of
both class and non-class type. However, 1.8 [intro.object] only
formally defines it for objects of class type.

an object of a most derived class type is called a most derived object

to

an object of a most derived class type, or of non-class type, is called
a most derived object

Proposed resolution (October, 2005):

Add the indicated words to 1.8 [intro.object] paragraph 4:

If a complete object, a data member (9.2 [class.mem]), or
an array element is of class type, its type is considered the most
derived class, to distinguish it from the class type of any base
class subobject; an object of a most derived class type, or of a
non-class type, is called a most derived object.

637.
Sequencing rules and example disagree

In 1.9 [intro.execution] paragraph 16, the following expression is
still listed as an example of undefined behavior:

i = ++i + 1;

However, it appears that the new sequencing rules make this expression
well-defined:

The assignment side-effect is required to be sequenced
after the value computations of both its LHS and RHS
(5.17 [expr.ass] paragraph 1).

The LHS (i) is an lvalue, so its value
computation involves computing the address
of i.

In order to value-compute the RHS (++i + 1), it is necessary to
first value-compute the lvalue expression ++i and then do an
lvalue-to-rvalue conversion on the result. This guarantees that the
incrementation side-effect is sequenced before the computation of the
addition operation, which in turn is sequenced before the assignment
side effect. In other words, it yields a well-defined order and final
value for this expression.

It should be noted that a similar expression

i = i++ + 1;

is still not well-defined, since the incrementation side-effect remains
unsequenced with respect to the assignment side-effect.

It's unclear whether making the expression in the example
well-defined was intentional or just a coincidental byproduct of
the new sequencing rules. In either case either the example
should be fixed, or the rules should be changed.

Clark Nelson: In my opinion, the poster's argument is
perfectly correct. The rules adopted reflect the CWG's desired
outcome for issue 222. At the Portland
meeting, I presented (and still sympathize with) Tom Plum's case
that these rules go a little too far in nailing down required
behavior; this is a consequence of that.

One way or another, a change needs to be made, and I think we
should seriously consider weakening the resolution of issue 222 to keep this example as having
undefined behavior. This could be done fairly simply by having
the sequencing requirements for an assignment expression depend
on whether it appears in an lvalue context.

James Widman: How's this for a possible re-wording?

In all cases, the side effect of the assignment expression is
sequenced after the value computations of the right and left
operands. Furthermore, if the assignment expression appears in a
context where an lvalue is required, the side effect of the
assignment expression is sequenced before its value computation.

Notes from the February, 2008 meeting:

There was no real support in the CWG for weakening the resolution
of issue 222 and returning the example to
having undefined behavior. No one knew of an implementation that
doesn't already do the (newly) right thing for such an example, so
there was little motivation to go out of our way to increase the
domain of undefined behavior. So the proposed resolution is to change
the example to one that definitely does have undependable behavior in
existing practice, and undefined behavior under the new rules.

Also, the new formulation of the sequencing rules approved in
Oxford contained the wording that by and large resolved issue 222, so with the resolution of this issue, we
can also close issue 222.

Proposed resolution (March, 2008):

Change the example in 1.9 [intro.execution] paragraph 16 as
follows:

i = v[i++]; // the behavior is undefined
i = 7, i++, i++; //i becomes 9
i = ++ii++ + 1; // the behavior is undefined
i = i + 1; // the value of i is incremented

If a side effect on a scalar object is unsequenced relative to
either a different side effect on the same scalar object or a
value computation using the value of the same scalar object, the
behavior is undefined.

It's not clear to me whether the two side-effects in n=--n
are “different.” As far as I can tell, it seems that both
side-effects involve the assignment of -1 to n, which in a sense
makes them non-“different.” But I don't know if that's the
intent. Would it be better to say “another” instead of
“a different?”

...If a side effect on a scalar object is unsequenced
relative to either a differentanother side effect
on the same scalar object or a value computation using the value
of the same scalar object, the behavior is
undefined. [Example:

362.
Order of initialization in instantiation units

Should this program do what its author obviously expects? As far as
I can tell, the standard says that the point of instantiation for
Fib<n-1>::Value is the same as the point of instantiation as the
enclosing specialization, i.e., Fib<n>::Value. What in the standard
actually says that these things get initialized in the right order?

John Spicer:
My opinion is that the standard does not specify
the behavior of this program.
I thought there was a core issue related to this, but I could not find it.
The issue that I recall proposed tightening up the static initialization
rules to make more cases well defined.

Your comment about point of instantiation is correct, but I don't think that
really matters. What matters is the order of execution of the initialization
code at execution time. Instantiations don't really live in
"translation units"
according to the standard. They live in "instantiation units", and the
handling of instantiation units in initialization is unspecified (which should
probably be another core issue). See 2.2 [lex.phases]
paragraph 8.

Notes from October 2002 meeting:

We discussed this and agreed that we really do mean the the order
is unspecified. John Spicer will propose wording on handling of
instantiation units in initialization.

Proposed resolution (April 2003):

TC1 contains the following text in 3.6.2 [basic.start.init]
paragraph 1:

Objects with static storage duration defined in namespace scope in the
same translation unit and dynamically initialized shall be initialized
in the order in which their definition appears in the translation
unit.

Dynamic initialization of an object is either ordered or unordered.
Explicit specializations and definitions
of class template static data members have ordered
initialization. Other class template static data member instances have
unordered initialization. Other objects defined in namespace scope
have ordered initialization. Objects defined within a single
translation unit and with ordered initialization shall be initialized
in the order of their definitions in the translation unit. The order
of initialization is unspecified for objects with unordered
initialization and for objects defined in different translation units.

This addresses this issue but while reviewing this issue some
additional changes were suggested for the above wording:

Dynamic initialization of an object is either ordered or unordered.
Definitions of explicitly specializedExplicit specializations and definitions of
class template static data members have ordered
initialization. Other class template static data members (i.e.,
implicitly or explicitly instantiated specializations)instances have
unordered initialization. Other objects defined in namespace scope
have ordered initialization. Objects defined within a single
translation unit and with ordered initialization shall be initialized
in the order of their definitions in the translation unit. The order
of initialization is unspecified for objects with unordered
initialization and for objects defined in different translation units.

558.
Excluded characters in universal character names

C99 and C++ differ in their approach to universal character
names (UCNs).

Issue 248 already covers the differences
in UCNs allowed for identifiers, but a more fundamental issue is that
of UCNs that correspond to codes reserved by ISO 10676 for surrogate
pair forms.

Specifically, C99 does not allow UCNs whose short names
are in the range 0xD800 to 0xDFFF. I think C++ should
have the same constraint. If someone really wants to
place such a code in a character or string literal,
they should use a hexadecimal escape sequence instead,
for example:

505.
Conditionally-supported behavior for unknown character escapes

If the character following a backslash is not one of those specified,
the behavior is undefined.

Paper J16/04-0167=WG21 N1727 suggests that such character escapes
be ill-formed. In discussions at the Lillehammer meeting, however,
the CWG felt that the newly-approved category of
conditionally-supported behavior would be more appropriate.

309.
Linkage of entities whose names are not simply identifiers, in introduction

3 [basic] paragraph 8, while not incorrect, does not
allow for linkage of operators and conversion functions. It says:

An identifier used in more than one translation unit can potentially
refer to the same entity in these translation units depending on the
linkage (3.5 [basic.link]) of the identifier specified in each
translation unit.

485.
What is a “name”?

A name is a use of an identifier (2.11 [lex.name])
that denotes an entity or label (6.6.4 [stmt.goto],
6.1 [stmt.label]).

Just three paragraphs later, it says

Two names are the same if

they are identifiers composed of the same character sequence;
or

they are the names of overloaded operator functions formed with
the same operator; or

they are the names of user-defined conversion functions formed
with the same type.

The last two bullets contradict the definition of name
in paragraph 4 because they are not identifiers.

This definition affects other parts of the Standard, as well.
For example, in 3.4.2 [basic.lookup.argdep] paragraph 1,

When an unqualified name is used as the postfix-expression
in a function call (5.2.2 [expr.call]), other
namespaces not considered during the usual unqualified lookup
(3.4.1 [basic.lookup.unqual]) may be searched, and in those
namespaces, namespace-scope friend function declarations
(11.4 [class.friend]) not otherwise visible may be found.

With the current definition of name, argument-dependent
lookup apparently does not apply to function-notation calls to
overloaded operators.

Another related question is whether a template-id is a
name or not and thus would trigger an argument-dependent lookup.
Personally, I have always viewed a template-id as a name,
just like operator+.

A name is a use of
an identifieridentifier (2.11 [lex.name]), operator-function-id (13.5 [over.oper]), conversion-function-id (12.3.2 [class.conv.fct]), or template-id (14.2 [temp.names])
that denotes an entity or label (6.6.4 [stmt.goto],
6.1 [stmt.label]). A variable is introduced by the
declaration of an object. The variable’s name denotes the object.

Every name that denotes an entity is introduced by a
declaration. Every name that denotes a label is introduced
either by a goto statement (6.6.4 [stmt.goto]) or
a labeled-statement (6.1 [stmt.label]).

A variable is introduced by the
declaration of an object. The variable's name denotes the
object.

Some names denote types, classes,
enumerations, or templates. In general, it is necessary to
determine whether or not a name denotes one of these entities before
parsing the program that contains it. The process that determines this
is called name lookup (3.4 [basic.lookup]).

Two names are the same if

they are identifiersidentifiers composed
of the same character sequence; or

they are the names of overloaded operator functionsoperator-function-ids formed with the same operator;
or

they are the names of user-defined conversion functionsconversion-function-ids formed with the same
type., or

they are template-ids that refer to the same class
or function (14.4 [temp.type]).

An identifierA name used in more than one
translation unit can potentially refer to the same entity in these
translation units depending on the linkage (3.5 [basic.link])
of the identifiername specified in each translation
unit.

Change 3.3.7 [basic.scope.class] paragraph 1 item 5 as follows:

The potential scope of a declaration that extends to or past the end
of a class definition also extends to the regions defined by its
member definitions, even if the members are defined lexically outside
the class (this includes static data member definitions, nested class
definitions, member function definitions (including the member
function body and any portion of the declarator part of such
definitions which follows
the identifierdeclarator-id, including a
parameter-declaration-clause and any default arguments
(8.3.6 [dcl.fct.default]).

[Drafting note: This last change is not really mandated by the
issue, but it's another case of “identifier” confusion.]

261.
When is a deallocation function "used?"

3.2 [basic.def.odr] paragraph 2 says that a deallocation
function is "used" by a new-expression or
delete-expression appearing in a potentially-evaluated
expression. 3.2 [basic.def.odr] paragraph 3 requires only that
"used" functions be defined.

This wording runs afoul of the typical implementation technique for
polymorphic delete-expressions in which the deallocation
function is invoked from the virtual destructor of the most-derived
class. The problem is that the destructor must be defined, because
it's virtual, and if it contains an implicit reference to the
deallocation function, the deallocation function must also be defined,
even if there are no relevant new-expressions or
delete-expressions in the program.

Is it required that D::operator delete(void*) be defined,
even if no B or D objects are ever created or
deleted?

Suggested resolution: Add the words "or if it is found by
the lookup at the point of definition of a virtual destructor
(12.4 [class.dtor])" to the specification in 3.2 [basic.def.odr] paragraph 2.

Notes from 04/01 meeting:

The consensus was in favor of requiring that any declared
non-placement operator delete member function be
defined if the destructor for the class is defined (whether
virtual or not), and similarly for a non-placement
operator new if a constructor is defined.

Proposed resolution (10/01):

In 3.2 [basic.def.odr] paragraph 2, add the indicated text:

An allocation or deallocation function for a class is
used by a new expression appearing in a potentially-evaluated
expression as specified in 5.3.4 [expr.new]
and 12.5 [class.free].
A deallocation function for a class is used by a delete expression
appearing in a potentially-evaluated expression as specified in
5.3.5 [expr.delete] and 12.5 [class.free].
A non-placement allocation or deallocation function for a
class is used by the definition of a constructor of that class. A
non-placement deallocation function for a class is used by the
definition of the destructor of that class, or by being selected by
the lookup at
the point of definition of a virtual destructor (12.4 [class.dtor]).
[Footnote: An implementation is not required to call
allocation and deallocation functions from constructors or
destructors; however, this is a permissible implementation
technique.]

Does (1) introduce U as a visible name in the surrounding
namespace scope?

If not, then (2) could presumably be an error since the
"union U" in that definition does not find the same type
as the declaration (1).

If yes, then (3) is OK too. However, we have gone through
much trouble to allow template implementations that do not
pre-parse the template definitions, but requiring (1) to
be visible would change that.

There was consensus that example 1 should be allowed.
(Compilers already parse declarations in templates; even MSVC++ 6.0
accepts this case.) The vote was 7-2.

Example 2, on the other hand, is wrong; the union name goes
into a block scope anyway.

Proposed resolution:

In 3.3.2 [basic.scope.pdecl]
change the second bullet of paragraph 5 as follows:

for an elaborated-type-specifier of the form

class-key identifier

if the elaborated-type-specifier is used in the
decl-specifier-seq or parameter-declaration-clause
of a function defined in namespace scope, the identifier is declared
as a class-name in the namespace that contains the
declaration; otherwise, except as a friend declaration, the identifier
is declared in the smallest non-class, non-function-prototype scope
that contains the declaration. [Note: These rules also apply within
templates.] [Note: ...]

Most (all?) compilers reject this code because
D is handled as a template name rather than as
the injected class name.

9 [class]/2 says that the injected class
name is "inserted into the scope of the class."

3.3.7 [basic.scope.class]/1 seems to be the text
intended to describe
what "scope of a class" means, but it assumes that
every name in that scope was introduced using a
"declarator". For an implicit declaration such
as the injected-class name it is not clear what
that means.

So my questions:

Should the injected class name be available
in the base class specifiers?

John Spicer:
I do not believe the injected class name should be available in the base
specifier. I think the semantics of injected class names should be as
if a magic declaration were inserted after the opening "{" of the class
definition. The injected class name is a member of the class and
members don't exist at the point where the base specifiers are scanned.

Do you agree the wording should be clarified
whatever the answer to the first question?

John Spicer:
I believe the 3.3.7 [basic.scope.class] wording should be
updated to reflect the fact that not all names come from declarators.

1) The potential scope of a name declared in a class consists not only of the
declarative region following the name's point of declarationdeclarator,
but also of all function
bodies, default arguments, and constructor ctor-initializers
in that class (including such things in nested classes).
The point of declaration of an injected-class-name
(clause 9 [class]) is
immediately following the opening brace of the class definition.

The question here is whether the lookup for i in the
initializer of N::j finds the declaration in namespace
N or not. Implementations differ on this question.

If N::j were a static data member of a class, the
answer would be clear: both 3.4.1 [basic.lookup.unqual]
paragraph 12 and 8.5 [dcl.init] paragraph 11 say that
the initializer “is in the scope of the member's
class.” There is no such provision for namespace
members defined outside the namespace, however.

The reasoning given in 3.4.1 [basic.lookup.unqual] may be
instructive:

A name used in the definition of a static data member of
class X (9.4.2 [class.static.data]) (after the
qualified-id of the static member) is looked up as if the name
was used in a member function of X.

It is certainly the case that a name used in a function that is
a member of a namespace is looked up in that namespace
(3.4.1 [basic.lookup.unqual] paragraph 6), regardless of whether
the definition is inside or outside that namespace. Initializers
for namespace members should probably be looked up the same way.

Proposed resolution (April, 2006):

Add a new paragraph following 3.4.1 [basic.lookup.unqual]
paragraph 12:

If a variable member of a namespace is defined outside of the scope
of its namespace then any name used in the definition of the variable
member (after the declarator-id) is looked up as if the
definition of the variable member occurred in its
namespace. [Example:

143.
Friends and Koenig lookup

When an unqualified name is used as the postfix-expression
in a function call
(5.2.2 [expr.call]
)... namespace-scope
friend function declarations
(11.4 [class.friend]
) not otherwise
visible may be found... the set of declarations found
by the lookup of the function name [includes] the set
of declarations found in the... classes associated with
the argument types.

The most straightforward reading of this wording is that if a function of
namespace scope (as opposed to a class member function) is
declared as a friend in a class, and that class is an
associated class in a function call, the friend function will
be part of the overload set, even if it is not visible to
normal lookup.

This example would seem to satisfy the criteria from
3.4.2 [basic.lookup.argdep]
:
A::S is an associated class of the argument, and
A::S has a
friend declaration of the namespace-scope function
B::f(A::S),
so Koenig lookup should include B::f(A::S) as part of the
overload set in the call.

Another interpretation is that, instead of finding the friend
declarations in associated classes, one only looks for namespace-scope
functions, visible or invisible, in the namespaces of which the the
associated classes are members; the only use of the friend
declarations in the associated classes is to validate whether an
invisible function declaration came from an associated class or not
and thus whether it should be included in the overload set or not.
By this interpretation, the call f(s) in the example will
fail, because B::f(A::S) is not a member of namespace
A and thus is not found by the lookup.

Notes from 10/99 meeting: The second interpretation
is correct. The wording should be revised to make clear that Koenig
lookup works by finding "invisible" declarations in namespace scope
and not by finding friend declarations in associated
classes.

Proposed resolution (04/01): The "associated classes"
are handled adequately under this interpretation by
3.4.2 [basic.lookup.argdep] paragraph 3, which describes the
lookup in the associated namespaces as including the friend
declarations from the associated classes. Other mentions of the
associated classes should be removed or qualified to avoid the
impression that there is a lookup in those classes:

In 3.4.2 [basic.lookup.argdep], change

When an unqualified name is used as the postfix-expression
in a function call (5.2.2 [expr.call]), other
namespaces not considered during the usual unqualified lookup
(3.4.1 [basic.lookup.unqual]) may be searched, and
namespace-scope friend function declarations
(11.4 [class.friend]) not otherwise visible may be found.

to

When an unqualified name is used as the postfix-expression
in a function call (5.2.2 [expr.call]), other
namespaces not considered during the usual unqualified lookup
(3.4.1 [basic.lookup.unqual]) may be searched, and
in those namespaces,
namespace-scope friend function declarations
(11.4 [class.friend]) not otherwise visible may be found.

In 3.4.2 [basic.lookup.argdep] paragraph 2, delete
the words and classes in the following two sentences:

If the ordinary unqualified lookup of the name finds the
declaration of a class member function, the associated namespaces
and classes are not considered. Otherwise the
set of declarations found by the lookup of the function name is
the union of the set of declarations found using ordinary
unqualified lookup and the set of declarations found in the
namespaces and classes associated with the
argument types.

218.
Specification of Koenig lookup

The original intent of the Committee when Koenig lookup was added
to the language was apparently something like the following:

The name in the function call expression is looked up like any
other unqualified name.

If the ordinary unqualified lookup finds nothing or finds the
declaration of a (non-member) function, function template, or overload
set, argument-dependent lookup is done and any functions found in
associated namespaces are added to the result of the ordinary
lookup.

This approach is not reflected in the current wording of the
Standard. Instead, the following appears to be the status quo:

Lookup of an unqualified name used as the
postfix-expression in the function call syntax always performs
Koenig lookup (3.4.1 [basic.lookup.unqual] paragraph 3).

Unless ordinary lookup finds a class member function, the result
of Koenig lookup always includes the declarations found in associated
namespaces (3.4.2 [basic.lookup.argdep] paragraph 2), regardless of
whether ordinary lookup finds a declaration and, if so, what kind of
entity is found.

The declarations from associated namespaces are not limited to
functions and template functions by anything in 3.4.2 [basic.lookup.argdep]. However, if Koenig lookup results in more than one
declaration and at least one of the declarations is a non-function,
the program is ill-formed (7.3.4 [namespace.udir], paragraph 4;
although this restriction is in the description of the
using-directive, the wording applies to any lookup that spans
namespaces).

John Spicer: Argument-dependent lookup was created to solve
the problem of looking up function names within templates where you
don't know which namespace to use because it may depend on the
template argument types (and was then expanded to permit use in
nontemplates). The original intent only concerned functions. The
safest and simplest change is to simply clarify the existing wording
to that effect.

Bill Gibbons: I see no reason why non-function declarations
should not be found. It would take a special rule to exclude
"function objects", as well as pointers to functions, from
consideration. There is no such rule in the standard and I see no
need for one.

There is also a problem with the wording in 3.4.2 [basic.lookup.argdep] paragraph 2:

If the ordinary unqualified lookup of the name finds the declaration
of a class member function, the associated namespaces and classes are
not considered.

This implies that if the ordinary lookup of the name finds the
declaration of a data member which is a pointer to function or
function object, argument-dependent lookup is still done.

My guess is that this is a mistake based on the incorrect
assumption that finding any member other than a member function would
be an error. I would just change "class member function" to "class
member" in the quoted sentence.

Mike Miller: In light of the issue of "short-circuiting"
Koenig lookup when normal lookup finds a non-function, perhaps it
should be written as "...finds the declaration of a class member, an
object, or a reference, the associated namespaces..."?

Andy Koenig: I think I have to weigh in on the side of
extending argument-dependent lookup to include function objects and
pointers to functions. I am particularly concerned about [function
objects], because I think that programmers should be able to replace
functions by function objects without changing the behavior of their
programs in fundamental ways.

Bjarne Stroustrup: I don't think we could seriously argue
from first principles that [argument-dependent lookup should find only
function declarations]. In general, C++ name lookup is designed to be
independent of type: First we find the name(s), then, we consider
its(their) meaning. 3.4 [basic.lookup] states "The name
lookup rules apply uniformly to all names ..." That is an important
principle.

Thus, I consider text that speaks of "function call" instead of
plain "call" or "application of ()" in the context of koenig lookup an
accident of history. I find it hard to understand how 5.2.2 [expr.call] doesn't either disallow all occurrences of
x(y) where x is a class object (that's clearly not
intended) or requires koenig lookup for x independently of
its type (by reference from 3.4 [basic.lookup]). I suspect
that a clarification of 5.2.2 [expr.call] to mention
function objects is in order. If the left-hand operand of () is a
name, it should be looked up using koenig lookup.

John Spicer: This approach causes otherwise well-formed
programs to be ill-formed, and it does so by making names visible that
might be completely unknown to the author of the program.
Using-directives already do this, but argument-dependent lookup is
different. You only get names from using-directives if you actually
use using-directives. You get names from argument-dependent
lookup whether you want them or not.

This basically breaks an important reason for having namespaces.
You are not supposed to need any knowledge of the names used by a
namespace.

But this example breaks if argument-dependent lookup finds
non-functions and if the translation unit includes the <list>
header somewhere.

This really makes namespaces of questionable value if you still
need to avoid using the same name as an entity in another namespace to
avoid problems like this.

Erwin Unruh: Before we really decide on this topic, we should
have more analysis on the impact on programs. I would also like to see
a paper on the possibility to overload functions with function
surrogates (no, I won't write one). Since such an extension is bound
to wait until the next official update, we should not preclude any
outcome of the discussion.

I would like to have a change right now, which leaves open several
outcomes later. I would like to say that:

Koenig lookup will find non-functions as well. If it finds a variable, the
program is ill-formed.
If the primary lookup finds a variable, Koenig lookup is done. If the result
contains both functions and variables, the program is ill-formed.
[Note: A future standard will assign semantics to such a program.]

I myself are not comfortable with this as a long-time result, but it
prepares the ground for any of the following long term solutions:

Do overloading on mixed function/variable sets.

Ignore variables on Koenig lookup.

Don't do Koenig lookup if the primary lookup finds a variable.

Find variables on Koenig lookup and give an error if there is a
variable/function mix.

The note is there to prevent compiler vendors to put their own
extensions in here.

Although many agreed that there were valid concerns motivating a
desire for Koenig lookup to find non-function declarations, there was
also concern that supporting this capability would be more dangerous
than helpful in the absence of overload resolution for mixed function
and non-function declarations.

A straw poll of the group revealed 8 in favor of Koenig lookup
finding functions and function templates only, while 3 supported the
broader result.

Notes from the 10/01 meeting:

There was unanimous agreement on one less controversial point:
if the normal lookup of the identifier finds a non-function, argument-dependent
lookup should not be done.

On the larger issue, the primary point of consensus is that making
this change is
an extension, and therefore it should wait until the point at
which we are considering extensions (which could be very soon).
There was also consensus on the fact that the standard as it
stands is not clear: some introductory text suggests that
argument-dependent lookup finds only functions, but the more
detailed text that describes the lookup does not have any
such restriction.

It was also noted that some existing implementations (e.g., g++) do
find some non-functions in some cases.

The issue at this point is whether we should (1) make a small change
to make the standard clear (presumably in the direction of not
finding the non-functions in the lookup), and revisit the issue
later as an extension, or (2) leave the standard alone for now and
make any changes only as part of considering the extension.
A straw vote favored option (1) by a strong majority.

Additional Notes (September, 2006):

Recent discussion of this issue
has emphasized the following points:

The concept of finding function pointers and function objects
as part of argument-dependent lookup is not currently under active
discussion in the Evolution Working Group.

The major area of concern with argument-dependent lookup is
finding functions in unintended namespaces. There are current
proposals to deal with this concern either by changing the
definition of “associated namespace” so that fewer
namespaces are considered or to provide a mechanism for enabling
or disabling ADL altogether. Although this concern is conceptually
distinct from the question of whether ADL finds function pointers
and function objects, it is related in the sense that the current
rules are perceived as finding too many functions (because of
searching too many namespaces), and allowing function pointers
and function objects would also increase the number of entities
found by ADL.

Any expansion of ADL to include function pointers and
function objects must necessarily update the overloading rules
to specify how they interact with functions and function
templates in the overload set. Current implementation experience
(g++) is not helpful in making this decision because, although
it performs a uniform lookup and finds non-function entities, it
diagnoses an error in overload resolution if non-function entities
are in the overload set.

There is a possible problem if types are found by ADL: it
is not clear that overloading between callable entities
(functions, function templates, function pointers, and function
objects) and types (where the postfix syntax means a cast or
construction of a temporary) is reasonable or useful.

James Widman:

There is a larger debate here about whether ADL should find object
names; the proposed wording below is only intended to answer the
request for wording to clarify the status quo (option 1 above) and
not to suggest the outcome of the larger debate.

Proposed Resolution (October, 2006):

Replace the normative text in 3.4.2 [basic.lookup.argdep]
paragraph 3 with the following (leaving the text
of the note and example unchanged):

Let X be the lookup set produced by unqualified lookup
(3.4.1 [basic.lookup.unqual]) and let Y be the lookup set
produced by argument dependent lookup (defined as follows). If X
contains

a declaration of a class member, or

a block-scope function declaration that is not
a using-declaration, or

a declaration that is neither a function nor a function template

then Y is empty. Otherwise Y is the set of declarations
found in the namespaces associated with the argument types as
described below. The set of declarations found by the lookup of
the name is the union of X and Y.

Change 3.4.1 [basic.lookup.unqual] paragraph 4 as
indicated:

When considering an associated namespace, the lookup is the same
as the lookup performed when the associated namespace is used as
a qualifier (3.4.3.2 [namespace.qual]) except that:

Any using-directives in the associated namespace are
ignored.

Any namespace-scope friend functions or friend function
templates declared in associated classes are visible within their
respective namespaces even if they are not visible during an
ordinary lookup (11.4 [class.friend]).

All names except those of (possibly overloaded) functions
and function templates are ignored.

403.
Reference to a type as a template-id

If T is a template-id, its associated namespaces and classes are the
namespace in which the template is defined; for member templates,
the member template's class; the namespaces and classes associated
with the types of the template arguments provided for template type
parameters (excluding template template parameters); the namespaces
in which any template template arguments are defined; and the
classes in which any member templates used as template template
arguments are defined. [Note: non-type template arguments do not
contribute to the set of associated namespaces. ]

There is a problem with the term "is a template-id". template-id
is a syntactic construct and you can't really talk about a type being a
template-id. Presumably, this is intended to mean "If T is the type of a
class template specialization ...".

557.
Does argument-dependent lookup cause template instantiation?

One might assume from 14.7.1 [temp.inst] paragraph 1
that argument-dependent lookup would require instantiation of any
class template specializations used in argument types:

Unless a class template specialization has been explicitly
instantiated (14.7.2 [temp.explicit]) or explicitly specialized
(14.7.3 [temp.expl.spec]), the class template specialization is
implicitly instantiated when the specialization is referenced in a
context that requires a completely-defined object type or when the
completeness of the class type affects the semantics of the program.

A complete class type is required to determine the associated
classes and namespaces for the argument type (to determine the class's
bases) and to determine the friend functions declared by the class, so
the completeness of the class type certainly “affects the
semantics of the program.”

This conclusion is reinforced by the second bullet of
3.4.2 [basic.lookup.argdep] paragraph 2:

If T is a class type (including unions), its associated
classes are: the class itself; the class of which it is a member, if
any; and its direct and indirect base classes. Its associated
namespaces are the namespaces in which its associated classes are
defined.

A class template specialization is a class type, so the second
bullet would appear to apply, requiring the specialization to be
instantiated in order to determine its base classes.

However, bullet 8 of that paragraph deals explicitly with class
template specializations:

If T is a class template specialization its
associated namespaces and classes are the namespace in which the
template is defined; for member templates, the member template’s
class; the namespaces and classes associated with the types of the
template arguments provided for template type parameters (excluding
template template parameters); the namespaces in which any template
template arguments are defined; and the classes in which any member
templates used as template template arguments are
defined.

Note that the class template specialization itself is not
listed as an associated class, unlike other class types, and there is
no mention of base classes. If bullet 8 were intended as a supplement
to the treatment of class types in bullet 2, one would expect phrasing
along the lines of, “In addition to the associated namespaces
and classes for all class types...” or some such; instead,
bullet 8 reads like a self-contained and complete specification.

If argument-dependent lookup does not cause implicit
instantiation, however, examples like the following fail:

If T is a class type (including unions), its associated
classes are: the class itself; the class of which it is a member, if
any; and its direct and indirect base classes. Its associated
namespaces are the namespaces inof which its associated
classes are definedmembers. Furthermore,
if T is a class template specialization, its associated
namespaces and classes also include: the namespaces and classes
associated with the types of the template arguments provided for
template type parameters (excluding template template parameters); the
namespaces of which any template template arguments are members; and
the classes of which any member templates used as template template
arguments are members. [Note: Non-type template arguments do not
contribute to the set of associated namespaces. —end
note]

Delete bullet 8 of 3.4.2 [basic.lookup.argdep] paragraph 2:

If T is a class template specialization its associated
namespaces and classes are the namespace in which the template is
defined; for member templates, the member template’s class; the
namespaces and classes associated with the types of the template
arguments provided for template type parameters (excluding template
template parameters); the namespaces in which any template template
arguments are defined; and the classes in which any member templates
used as template template arguments are defined. [Note: non-type
template arguments do not contribute to the set of associated
namespaces. —end note]

Suggested answer: Yes. All the compilers I tried accept the test case.

Proposed resolution (10/01):

In 3.4.3.1 [class.qual] paragraph 1 add the indicated text:

If the nested-name-specifier of a qualified-id nominates
a class, the
name specified after the nested-name-specifier is looked up in the
scope of the class (10.2 [class.member.lookup]), except for the cases
listed below. The name shall represent one or more members of that
class or of one of its base classes (clause 10 [class.derived]).
If the class-or-namespace-name of the nested-name-specifier
names a cv-qualified class type, it nominates the underlying class
(the cv-qualifiers are ignored).

Notes from 4/02 meeting:

There is a problem in that class-or-namespace-name does not
include typedef names for cv-qualified class types. See
7.1.3 [dcl.typedef] paragraph 4:

Argument and text removed from proposed resolution
(October 2002):

7.1.3 [dcl.typedef] paragraph 5:

Here's a good question: in this example, should X
be used as a name-for-linkage-purposes (FLP name)?

typedef class { } const X;

Because a type-qualifier is parsed as a
decl-specifier, it isn't possible to declare cv-qualified
and cv-unqualified typedefs for a type in a single declaration.
Also, of course, there's no way to declare a typedef for the
cv-unqualified version of a type for which only a cv-qualified version
has a name.
So, in the above example, if X isn't used as the FLP name,
then there can be no FLP name.
Also note that a FLP name usually represents a parameter type, where
top-level cv-qualifiers are usually irrelevant anyway.

Data points: for the above example, Microsoft uses X as the
FLP name; GNU and EDG do not.

My recommendation: for consistency with the direction we're going on
this issue, for simplicity of description (e.g., "the first
class-name declared by the declaration"), and for (very
slightly) increased utility, I think Microsoft has this right.

If the typedef declaration defines an unnamed class type (or
enum type), the first typedef-name declared by the
declaration to behave that class type
(or enum type)or a cv-qualified version thereof
is used to denote the class type (or enum type) for linkage purposes
only (3.5 [basic.link]).
[Example: ...

Proposed resolution (October 2002):

3.4.4 [basic.lookup.elab] paragraphs 2 and 3:

This sentence is deleted twice:

...
If this name lookup finds a typedef-name, the
elaborated-type-specifier is ill-formed.
...

Note that the above changes are included in
N1376 as part of the resolution of issue 245.

5.1.1 [expr.prim.general] paragraph 7:

This is only a note, and it is at least incomplete (and quite possibly
inaccurate), despite (or because of) its complexity.
I propose to delete it.

...
[Note: a typedef-name that names a class is a
class-name (9.1 [class.name]).
Except as the identifier in the declarator for a constructor
or destructor definition outside of a class
member-specification (12.1 [class.ctor],
12.4 [class.dtor]), a typedef-name
that names a class may be used in a qualified-id to refer to
a constructor or destructor. ]

7.1.3 [dcl.typedef] paragraph 4:

My first choice would have been to make this the primary statement about
the equivalence of typedef-name and class-name,
since the equivalence comes about as a result of a typedef declaration.
Unfortunately, references to class-name point to
9.1 [class.name], so it
would seem that the primary statement should be there instead.
To avoid the possiblity of conflicts in the future, I propose to make
this a note.

[Note:
A typedef-name that names a class type, or a cv-qualified
version thereof, is also a class-name
(9.1 [class.name]).
If a typedef-name is used following the
class-key in an elaborated-type-specifier
(7.1.6.3 [dcl.type.elab]),
or in the class-head of a class declaration (9 [class]),
or is used as the identifier in the declarator for a
constructor or destructor declaration (12.1 [class.ctor],
12.4 [class.dtor]),to identify the subject of an elaborated-type-specifier
(7.1.6.3 [dcl.type.elab]),
class declaration (clause 9 [class]),
constructor declaration (12.1 [class.ctor]),
or destructor declaration (12.4 [class.dtor]),
the program is ill-formed.
]
[Example: ...

7.1.6.3 [dcl.type.elab] paragraph 2:

This is the only remaining (normative) statement that a
typedef-name can't be used in an
elaborated-type-specifier.
The reference to template type-parameter is deleted by the
resolution of issue 283.

...
If the identifier resolves to a typedef-nameor a template type-parameter, the
elaborated-type-specifier is ill-formed.
[Note: ...

8 [dcl.decl] grammar rule declarator-id:

When I looked carefully into the statement of the rule prohibiting a
typedef-name in a constructor declaration, it appeared to me
that this grammar rule (inadvertently?) allows something that's always
forbidden semantically.

declarator-id:

id-expression::opt nested-name-specifieropttype-nameclass-name

9.1 [class.name] paragraph 5:

Unlike the prohibitions against appearing in an
elaborated-type-specifier or constructor or destructor
declarator, each of which was expressed more than once, the prohibition
against a typedef-name appearing in a class-head
was previously stated only in 7.1.3 [dcl.typedef].
It seems to me that that prohibition belongs here instead.
Also, it seems to me important to clarify that a typedef-name
that is a class-name is still a typedef-name.
Otherwise, the various prohibitions can be argued around easily, if
perversely ("But that
isn't a typedef-name, it's a class-name; it says
so right there in 9.1 [class.name].")

A typedef-name (7.1.3 [dcl.typedef])
that names a class type or a
cv-qualified version thereof is
also a class-name, but shall not be used
in an elaborated-type-specifier; see also
7.1.3 [dcl.typedef].as the identifier in a class-head.

12.1 [class.ctor] paragraph 3:

The new nonterminal references are needed to really nail down what we're
talking about here.
Otherwise, I'm just eliminating redundancy.
(A typedef-name that doesn't name a class type is no more
valid here than one that does.)

A typedef-name that names a class is a
class-name (7.1.3 [dcl.typedef]); however, aAtypedef-namethat names a class shall not be
used as the identifierclass-name in the declaratordeclarator-id for a constructor declaration.

12.4 [class.dtor] paragraph 1:

The same comments apply here as to 12.1 [class.ctor].

...
A typedef-name that names a class is a
class-name (7.1.3); however, aAtypedef-namethat names a class shall not be
used as the identifierclass-name
following the ~ in the declarator for a destructor
declaration.

318.
struct A::A should not name the constructor of A

A use of an injected-class-name in an elaborated-type-specifier
should not name the constructor of the class, but rather the class itself,
because in that context we know that we're looking for a type.
See issue 147.

Proposed Resolution (revised October 2002):

This clarifies the changes made in the TC for issue 147.

In 3.4.3.1 [class.qual] paragraph 1a replace:

If the nested-name-specifier nominates a class C, and the name
specified after the nested-name-specifier, when looked up in C, is the
injected class name of C (clause 9 [class]), the name is instead
considered to name the constructor of class C.

with

In a lookup in which the constructor is an acceptable lookup result,
if the nested-name-specifier nominates a class C and the name
specified after the nested-name-specifier, when looked up in C, is the
injected class name of C (clause 9 [class]), the name is
instead considered to name the constructor of class C.
[Note: For example, the constructor is not an acceptable lookup result in an
elaborated type specifier so the constructor would not be used in place
of the injected class name.]

I can't find anything in the standard that says definitively what this
means. 7.3.3 [namespace.udecl] says that a using-declaration shall
name "a member of a base class" -- but here we have two members, the
data member A::i and the class A::i.

Personally, I'd find it more attractive if this code did not work. I'd
like "using A::i" to mean "lookup A::i in the usual way and bind B::i to
that", which would mean that while "i = 3" would be valid in D::f,
"struct i x" would not be. However, if there were no A::i data member,
then "A::i" would find the struct and the code in D::f would be valid.

John Spicer:
I agree with you, but unfortunately the standard committee did not.

I remembered that this was discussed by the committee and that a
resolution was adopted that was different than what I hoped for, but I
had a hard time finding definitive wording in the standard.

I went back though my records and found the paper that proposed a
resolution and the associated committee motion that adopted the
proposed resolution The paper is N0905, and "option 1" from that paper
was adopted at the Stockholm meeting in July of 1996. The resolution
is that "using A::i" brings in everything named i from A.

3.4.3.2 [namespace.qual] paragraph 2 was modified to
implement this resolution, but interestingly
that only covers the namespace case and not the class case. I think
the class case was overlooked when the wording was drafted. A core
issue should be opened to make sure the class case is handled
properly.

Notes from April 2003 meeting:

This is related to issue 11.
7.3.3 [namespace.udecl] paragraph 10 has an example
for namespaces.

Proposed resolution (October 2003):

Add a bullet to the end of 3.4.3.1 [class.qual]
paragraph 1:

the lookup for a name specified in a using-declaration
(7.3.3 [namespace.udecl])
also finds class or enumeration names hidden within the same scope
(3.3.10 [basic.scope.hiding]).

Change the beginning of 7.3.3 [namespace.udecl] paragraph 4 from

A
using-declaration
used as a
member-declaration
shall refer to a member of a base class of the class being defined,
shall refer to a member of an anonymous union that is a member of a base class
of the class being defined, or
shall refer to an enumerator for an enumeration type that is a member of a base
class of the class being defined.

to

In a using-declaration used as a
member-declaration, the nested-name-specifier
shall name a base class of the class being defined. Such a
using-declaration introduces the set of declarations found by member
name lookup (10.2 [class.member.lookup],
3.4.3.1 [class.qual]).

245.
Name lookup in elaborated-type-specifiers

I have some concerns with the description of name lookup for
elaborated type specifiers in 3.4.4 [basic.lookup.elab]:

Paragraph 2 has some parodoxical statements concerning looking up
names that are simple identifers:

If the elaborated-type-specifier refers to an enum-name
and this lookup does not find a previously declared enum-name,
the elaborated-type-specifier is ill-formed. If the
elaborated-type-specifier refers to an [sic]class-name and this lookup does not find a previously declared
class-name... the elaborated-type-specifier is a
declaration that introduces the class-name as described in
3.3.2 [basic.scope.pdecl]."

It is not clear how an elaborated-type-specifier can refer
to an enum-name or class-name given that the lookup does
not find such a name and that class-name and enum-name
are not part of the syntax of an elaborated-type-specifier.

The second sentence quoted above seems to suggest that the name found
will not be used if it is not a class name. typedef-name names
are ill-formed due to the sentence preceding the quote. If lookup
finds, for instance, an enum-name then a new declaration will
be created. This differs from C, and from the enum case, and can have
surprising effects:

Was this really the intent? If this is the case then some more
work is needed on 3.4.4 [basic.lookup.elab]. Note that the
section does not make finding a type template formal ill-formed, as is
done in 7.1.6.3 [dcl.type.elab]. I don't see anything that
makes a type template formal name a class-name. So the example
in 7.1.6.3 [dcl.type.elab] of friend class T; where
T is a template type formal would no longer be ill-formed
with this interpretation because it would declare a new class
T.

As given in N1376=02-0034. Note that the inserts and strikeouts in
that document do not display
correctly in all browsers; <del> --> <strike>
and <ins> --> <b>, and the
similar changes for the closing delimiters,
seem to do the trick.

254.
Definitional problems with elaborated-type-specifiers

The text in 3.4.4 [basic.lookup.elab] paragraph 2 twice
refers to the possibility that an elaborated-type-specifier
might have the form

class-key identifier;

However, the grammar for elaborated-type-specifier does
not include a semicolon.

In both 3.4.4 [basic.lookup.elab] and
7.1.6.3 [dcl.type.elab], the text asserts that an
elaborated-type-specifier that refers to a typedef-name
is ill-formed. However, it is permissible for the form of
elaborated-type-specifier that begins with typename
to refer to a typedef-name.

This problem is the result of adding the typename form
to the elaborated-type-name grammar without changing the
verbiage correspondingly. It could be fixed either by updating the
verbiage or by moving the typename syntax into its own
production and referring to both nonterminals when needed.

(See also issue 180. If this
issue is resolved in favor of a separate nonterminal in the
grammar for the typename forms, the wording in that
issue's resolution must be changed accordingly.)

Notes from 04/01 meeting:

The consensus was in favor of moving the typename
forms out of the elaborated-type-specifier grammar.

141.
Non-member function templates in member access expressions

In a class member access expression
(5.2.5 [expr.ref]
), if the . or
-> token is immediately followed by an identifier
followed by a <, the identifier must be looked up to
determine whether the < is the beginning of a template
argument list
(14.2 [temp.names]
) or a less-than
operator. The identifier is first looked up in the class of the
object expression. If the identifier is not found, it is then looked
up in the context of the entire postfix-expression and shall
name a class or function template.

There do not seem to be any circumstances in which use of a
non-member template function would be well-formed as the
id-expression of a class member access expression.

Proposed Resolution (November, 2006):

Change 3.4.5 [basic.lookup.classref] paragraph 1 as follows:

In a class member access expression (5.2.5 [expr.ref]), if
the . or -> token is immediately followed by an
identifier followed by a <, the identifier must be looked
up to determine whether the < is the beginning of a
template argument list (14.2 [temp.names]) or a less-than
operator. The identifier is first looked up in the class of the object
expression. If the identifier is not found, it is then looked up in
the context of the entire postfix-expression and shall name a
class or function template...

The problem is that 3.4.5 [basic.lookup.classref] says that you have to look
up A in both the context of the pointed-to-type (i.e.,
::A), and
in the context of the postfix-expression (i.e., the body of C::f), and
that if the name is found in both places it must name the same type in
both places.

The EDG front end does not issue an error about this program, though.

Am I reading the standardese incorrectly?

John Spicer: I think you are reading it correctly. I think
I've been hoping that this would
get changed. Unlike other dual lookup contexts, this is one in which the
compiler already knows the right answer (the type must match that of the left
hand of the -> operator). So I think that if either of the types
found matches
the one required, it should be sufficient. You can't say a->~::A(),
which
means you are forced to say a->::A::~A(), which disables the virtual
mechanism. So you would have to do something like create a local typedef
for the desired type.

If the id-expression in a class member access (5.2.5 [expr.ref]) is an unqualified-id, and the type of the
object expression is of a class type C(or of pointer to a
class type C), the unqualified-id is looked up in
the scope of class C...

Change 3.4.5 [basic.lookup.classref] paragraph 3 as indicated:

If the unqualified-id is ~type-name,
the type-name is looked up in the context of the entire
postfix-expression.andIf the
type T of the object expression is of a class
type C(or of pointer to a class type C),
the type-name is also looked up in the context of the
entire postfix-expression and in the scope of
class C. The type-name shall refer to
a class-name. If type-name is found in both contexts,
the name shall refer to the same class type. If the type of the object
expression is of scalar type, the type-name is looked up in the
scope of the complete postfix-expression.At least one
of the lookups shall find a name that refers to (possibly
cv-qualified)
T. [Example:

381.
Incorrect example of base class member lookup

The example in 3.4.5 [basic.lookup.classref] paragraph 4
is wrong (see 11.2 [class.access.base] paragraph 5; the cast to the
naming class can't be done) and needs to be corrected.
This was noted when the final version of the algorithm for
issue 39 was checked against it.

Proposed Resolution (October 2003):

Remove the entire note at the end of
3.4.5 [basic.lookup.classref] paragraph 4, including the
entire example.

414.
Multiple types found on destructor lookup

By 3.4.5 [basic.lookup.classref] paragraph 3, the following is
ill-formed because the two lookups of the destructor name (in
the scope of the class of the object and in the surrounding
context) find different Xs:

struct X {};
int main() {
X x;
struct X {};
x.~X(); // Error?
}

This is silly, because the compiler knows what the type has
to be, and one of the things found matches that. The lookup
should require only that one of the lookups finds the required
class type.

However, the same prohibition was not made for class scope types. Indeed,
3.5 [basic.link] paragraph 5 says:

In addition, a member function, static data member, class or
enumeration of class scope has external linkage if the name of the
class has external linkage.

That allows for:

struct S {
typedef enum { e1 } *MPE;
void mf(MPE) {}
};

My guess is that this is an unintentional consequence of
3.5 [basic.link] paragraph 5, but I would like confirmation
on that.

Proposed resolution:

Change text in 3.5 [basic.link] paragraph 5 from:

In addition, a member function, static data member, class or
enumeration of class scope has external linkage if the name of the
class has external linkage.

to:

In addition, a member function, a static data member, a named class or
enumeration of class scope, or an unnamed class or enumeration defined
in a class-scope typedef declaration such that the class or
enumeration has the typedef name for linkage purposes
(7.1.3 [dcl.typedef]),
has external linkage if the name of the class has external linkage.

Paragraph 8 of Section 3.5 [basic.link] contains the following
sentences: "A name with no linkage shall not be used to declare an
entity with linkage. If a declaration uses a typedef name, it is the
linkage of the type name to which the typedef refers that is
considered."

The problem with this wording is that it doesn't cover cases where the
type to which a typedef-name refers has no name. As a result it's not
clear whether, for example, the following program is well-formed:

My feeling is that the rules for whether or not a typedef-name used in
a declaration shall be treated as having or not having linkage ought
to be modelled after those for dependent types, which are explained in
14.6.2.1 [temp.dep.type].

Add the following text at the end of Paragraph 8 of Section
3.5 [basic.link] and replace the following example:

In case of the type referred to by a typedef declaration not having a name,
the newly declared typedef-name has linkage if and only if its referred type
comprises no names of no linkage excluding local names that are eligible for
appearance in an integral constant-expression (5.19 [expr.const]).
[Note: if the referred
type contains a typedef-name that does not denote an unnamed class, the
linkage of that name is established by the recursive application of this
rule for the purposes of using typedef names in declarations.] [Example:

Paragraph 2 of Section 14.3.1 [temp.arg.type] is inaccurate and
unnecessarily prohibits a few important cases; it says "A local type, a type
with no linkage, an unnamed type or a type compounded from any of these
types shall not be used as a template-argument for a template-parameter."
The inaccuracy stems from the fact that it is not a type but its name that
can have a linkage.

For example based on the current wording of 14.3.1 [temp.arg.type],
the following example is ill-formed.

Replace the whole second paragraph of Section 14.3.1 [temp.arg.type]
with the following wording:

A type whose name does not have a linkage or a type compounded from any such
type shall not be used as a template-argument for a template-parameter. In
case of a type T used as a template type argument not having a name,
T
constitutes a valid template type argument if and only if the name of an
invented typedef declaration referring to T would have linkage;
see 3.5.
[Example:

389.
Unnamed types in entities with linkage

A name with no linkage (notably, the name of a class or enumeration
declared in a local scope (3.3.3 [basic.scope.local])) shall not
be used to declare an entity with linkage.
If a declaration uses a typedef name, it is the linkage of the type
name to which the typedef refers that is considered.

The problem here is that most implementations must generate the same
mangled name
for "f" in two translation units. The quote from the standard above
isn't quite
clear, unfortunately: There is no type name to which the typedef refers.

A related situation is the following:

enum { no, yes } answer;

The variable "answer" is declared as having external linkage, but it is
declared
with an unnamed type. Section 3.5 [basic.link]
talks about the linkage of names, however,
and does therefore not prohibit this. There is no implementation issue
for most
compilers because they do not ordinarily mangle variable names, but I
believe
the intent was to allow that implementation technique.

Finally, these problems are much less relevant when declaring names
with internal
linkage. For example, I would expect there to be few problems with:

typedef struct {} *UP;
static void g(UP);

I recently tried to interpret 3.5 [basic.link] paragraph 8
with the assumption that types with no names
have no linkage. Surprisingly, this resulted in many diagnostics on
variable declarations (mostly like "answer" above).

I'm pretty sure the standard needs clarifying words in this matter, but
which way should it go?

There was agreement that this check is not needed for variables
and functions with extern "C" linkage, and a change there is
desirable to allow use of legacy C headers. The check is also not needed for
entities with internal linkage, but there was no strong sentiment
for changing that case.

We also considered relaxing this requirement for extern "C++"
variables but decided that we did not want to change that case.

We noted that if extern "C" functions are allowed an additional
check is needed when such functions are used as arguments in calls
of function templates. Deduction will put the type of the extern "C"
function into the type of the template instance, i.e., there would
be a need to mangle the name of an unnamed type. To plug that hole
we need an additional requirement on the template created in
such a case.

A name with no linkage (notably, the name of a class or enumeration
declared in a local scope (3.3.3 [basic.scope.local]))
shall not be used to declare an
entity with linkage. If a declaration uses a typedef name, it is
the linkage of the type name to which the typedef refers that is
considered.

to

A type is said to have linkage if and only if

it is a class or enumeration type that is named (or has a name for
linkage purposes (7.1.3 [dcl.typedef]))
and the name has linkage; or

it is a specialization of a class template (14 [temp])
[Footnote: a class template always has external linkage, and
the requirements of 14.3.1 [temp.arg.type]
and 14.3.2 [temp.arg.nontype]
ensure that the template arguments will also have appropriate linkage]; or

it is a fundamental type (3.9.1 [basic.fundamental]); or

it is a compound type (3.9.2 [basic.compound])
other than a class or enumeration,
compounded exclusively from types that have linkage; or

it is a cv-qualified (3.9.3 [basic.type.qualifier])
version of a type that has linkage.

A type without linkage shall not be used as the type of a variable or
function with linkage, unless the variable or function has extern "C"
linkage (7.5 [dcl.link]).
[Note: in other words, a type without linkage contains
a class or enumeration that cannot be named outside
of its translation unit. An entity with external linkage
declared using such a type could not correspond to any other entity
in another translation unit of the program and is thus not permitted.
Also note that classes with linkage may contain members whose types do
not have linkage, and that typedef names are ignored in the determination of
whether a type has linkage.]

Change 14.3.1 [temp.arg.type] paragraph 2 from (note:
this is the wording as updated by issue 62)

The following types shall not be used as a template-argument
for a template type-parameter:

a type whose name has no linkage

an unnamed class or enumeration type that has no name for
linkage purposes (7.1.3 [dcl.typedef])

a cv-qualified version of one of the types in this list

a type created by application of declarator operators to one
of the types in this list

a function type that uses one of the types in this list

to

A type without linkage (3.5 [basic.link])
shall not be used as a template-argument
for a template type-parameter.

Once this issue is ready, issue 319
should be moved back to ready as well.

When a block scope declaration of an entity with linkage is not
found to refer to some other declaration, then that entity is a
member of the innermost enclosing namespace.

The question then is whether N is an “enclosing
namespace” for the local declaration of g()?

Proposed resolution (October 2004):

Add the following text as a new paragraph at the end of
7.3.1 [namespace.def]:

The enclosing namespaces of a declaration are those
namespaces in which the declaration lexically appears, except for
a redeclaration of a namespace member outside its original
namespace (e.g., a definition as specified in 7.3.1.2 [namespace.memdef]). Such a redeclaration has the same enclosing
namespaces as the original declaration. [Example:

270.
Order of initialization of static data members of class templates

The Standard does not appear to address how the rules for order
of initialization apply to static data members of class templates.

Suggested resolution: Add the following verbiage to either
3.6.2 [basic.start.init] or 9.4.2 [class.static.data]:

Initialization of static data members of class templates shall be
performed during the initialization of static data members for the
first translation unit to have static initialization performed for
which the template member has been instantiated. This requirement
shall apply to both the static and dynamic phases of initialization.

Notes from 04/01 meeting:

Enforcing an order of initialization on static data members of
class templates will result in substantial overhead on access to such
variables. The problem is that the initialization be required as the
result of instantiation in a function used in the initialization of a
variable in another translation unit. In current systems, the order of
initialization of static data data members of class templates is not
predictable. The proposed resolution is to state that the order of
initialization is undefined.

Proposed resolution (04/01, updated slightly 10/01):

Replace the following sentence in 3.6.2 [basic.start.init]
paragraph 1:

Objects with static storage duration defined in namespace scope in the
same translation unit and dynamically initialized shall be initialized
in the order in which their definition appears in the translation
unit.

with

Dynamic initialization of an object is either ordered or unordered.
Explicit specializations and definitions
of class template static data members have ordered
initialization. Other class template static data member instances have
unordered initialization. Other objects defined in namespace scope
have ordered initialization. Objects defined within a single
translation unit and with ordered initialization shall be initialized
in the order of their definitions in the translation unit. The order
of initialization is unspecified for objects with unordered
initialization and for objects defined in different translation units.

The sentinel list node is used to represent "nil" (the null pointer
cannot be used with my implementation, for reasons which are immaterial
to this discussion). All of the List's non-static member functions and
constructors depend upon the value of the sentinel. Under the proposed
resolution for issue #270, Lists cannot be safely instantiated before
main() begins, as the sentinel's initialization is "unordered".

(Some readers may propose that I should use the "singleton pattern" in the
List class. This is undesirable, for reasons I shall describe at the
end of this post at the location marked "[*]". For the moment, indulge
me by assuming that "singleton" is not an adequate solution.)

Though this is a particular example from my own experience, I believe it
is representative of a general class of examples. It is common to use
static data members of a class to represent the "distinguished values"
which are important to instances of that class. It is imperative that
these values be initialized before any instances of the class are
created, as the instances depend on the values.

In a comp.std.c++ posting on 28 Jul 2001, Brian McNamara proposes
the following alternative resolution:

Replace the following sentence in 3.6.2 [basic.start.init]
paragraph 1:

Objects with static storage duration defined in namespace scope in
the same translation unit and dynamically initialized shall be
initialized in the order in which their definition appears in the
translation unit.

with

Objects with static storage duration defined in namespace scope
shall be initialized in the order described below.

and then after paragraph 1, add this text:

Dynamic initialization is either ordered or quasi-ordered. Explicit
specializations of class template static data members have ordered
initialization. Other class template static data member instances have
quasi-ordered initialization. All other objects defined in namespace
scope have ordered initialization. The order of initialization is
specified as follows:

Objects that are defined within a single translation unit and
that have ordered initialization shall be initialized in the
order of their definitions in the translation unit.

Objects that are defined only within a single translation unit
and that have quasi-ordered initialization shall also be
initialized in the order of their definitions in the translation
unit -- that is, as though these objects had ordered initialization.

Objects that are defined within multiple translation units (which,
therefore, must have quasi-ordered initialization) shall be
initialized as follows: in exactly one translation unit
(which one is unspecified), the object shall be treated as
though it has ordered initialization; in the other translation
units which define the object, the object will be initialized
before all other objects that have ordered initialization in
those translation units.

For any two objects, "X" and "Y", with static storage duration
and defined in namespace scope, if the previous bullets do not
imply a relationship for the initialization ordering between "X"
and "Y", then the relative initialization order of these objects
is unspecified.

along with a non-normative note along the lines of

[ Note: The intention is that translation units can each be compiled
separately with no knowledge of what objects may be re-defined in
other translation units. Each translation unit can contain a method
which initializes all objects (both quasi-ordered and ordered) as
though they were ordered. When these translation units are linked
together to create an executable program, all of these objects can
be initialized by simply calling the initialization methods (one
from each translation unit) in any order. Quasi-ordered objects
require some kind of guard to ensure that they are not initialized
more than once (the first attempt to initialize such an object
should succeed; any subsequent attempts should simply be ignored). ]

Erwin Unruh replies:
There is a point which is not mentioned with this posting.
It is the cost for implementing the scheme. It requires that each
static template variable is instantiated in ALL translation units
where it is used. There has to be a flag for each of these variables
and this flag has to be checked in each TU where the instantiation
took place.

I would reject this idea and stand with the proposed resolution of
issue 270.

There just is no portable way to ensure the "right" ordering of
construction.

Notes from 10/01 meeting:

The Core Working Group reaffirmed its previous decision.

441.
Ordering of static reference initialization

I have a couple of questions about 3.6.2 [basic.start.init],
"Initialization of
non-local objects." I believe I recall some discussion of
related topics, but I can't find anything relevant in the issues
list.

The first question arose when I discovered that different
implementations treat reference initialization differently.
Consider, for example, the following (namespace-scope) code:

Because "int&" is not a POD type, there is no requirement that it
be initialized before dynamic initialization is performed, and
implementations differ in this regard. Using a function called
during dynamic initialization to print the values of "ip" and
"&ir", I found that g++, Sun, HP, and Intel compilers initialize
ir before dynamic initialization and the Microsoft compiler does
not. All initialize ip before dynamic initialization. I believe
this is conforming (albeit inconvenient :-) behavior.

So, my first question is whether it is intentional that a
reference of static duration, initialized with a reference
constant expression, need not be initialized before dynamic
initialization takes place, and if so, why?

The second question is somewhat broader. As
3.6.2 [basic.start.init] is currently
worded, it appears that there are no requirements on when ir is
initialized. In fact, there is a whole category of objects --
non-POD objects initialized with a constant expression -- for
which no ordering is specified. Because they are categorized as
part of "static initialization," they are not subject to the
requirement that they "shall be initialized in the order in which
their definition appears in the translation unit." Because they
are not POD types, they are not required to be initialized before
dynamic initialization occurs. Am I reading this right?

My preference would be to change
3.6.2 [basic.start.init] paragraph 1 so that 1) references
are treated like POD objects with respect to initialization, and
2) "static initialization" applies only to POD objects and
references. Here's some sample wording to illustrate:

Suggested resolution:

Objects with static storage duration (3.7.1) shall be
zero-initialized (8.5) before any other initialization takes
place. Initializing a reference, or an object of POD
type, of static storage duration with a constant expression
(5.19) is called constant initialization. Together,
zero-initialization and constant initialization are called
static initialization; all other initialization is dynamic
initialization. Static initialization shall be performed
before any dynamic initialization takes place. [Remainder
unchanged.]

Proposed Resolution:

Change 3.6.2 [basic.start.init] paragraph 1 as follows:

Objects with static storage duration (3.7.1) shall be
zero-initialized (8.5) before any other initialization takes
place. Initializing a reference, or an object of POD type, of
static storage duration with a constant expression (5.19) is
called constant initialization. Together,
zero-initialization and constant initialization are
Zero-initialization and initialization with a
constant expression are collectively called static
initialization; all other initialization is dynamic
initialization. Static initialization shall be performed
Objects of POD types (3.9) with static storage
duration initialized with constant expressions (5.19) shall be
initialized before any dynamic initialization takes
place.

688.
Constexpr constructors and static initialization

[Voted into the WP at the September, 2008 meeting (resolution
in paper N2757).]

Given this literal type,

struct X {
constexpr X() { }
};

and this definition,

static X x;

the current specification does not require that x be
statically initialized because it is not “initialized with
a constant expression” (3.6.1 [basic.start.main]
paragraph 1).

Lawrence Crowl:

This guarantee is essential for atomics.

Jens Maurer:

Suggestion:

A reference with static storage duration or an object of literal
type with static storage duration can be initialized with a
constant expression (5.19 [expr.const]) or with a
constexpr constructor; this is called constant initialization.

In addition, there is a need to enforce static initialization
for non-literal types: std::shared_ptr,
std::once_flag, and std::atomic_* all have
nontrivial copy constructors, making them non-literal types.
However, we need a way to ensure that a constexpr constructor
called with constant expressions will guarantee static
initialization, regardless of the nontriviality of the copy
constructor.

Proposed resolution (April, 2008):

Change 3.6.2 [basic.start.init] paragraph 1 as follows:

...A reference with static storage duration and an object of
trivial or literal type with static storage duration can be
initialized with a constant expression (5.19 [expr.const]); thisIf a reference with static storage
duration is initialized with a constant expression (5.19 [expr.const]) or if the initialization of an object with static
storage duration satisfies the requirements for the object being
declared with constexpr (7.1.5 [dcl.constexpr]),
that initialization is called constant
initialization...

Change 6.7 [stmt.dcl] paragraph 4 as follows:

...A local object of trivial or literal type (3.9 [basic.types]) with static storage duration initialized with
constant-expressions is initializedConstant
initialization (3.6.2 [basic.start.init]) of a local entity
with static storage duration is performed before its block is
first entered...

Change 7.1.5 [dcl.constexpr] paragraph 7 as follows:

A constexpr specifier used in an object declaration
declares the object as const. Such an object shall be
initialized, and every expression that appears in its initializer
(8.5 [dcl.init]) shall be a constant expression. Every
implicit conversion used in converting the initializer
expressions and every constructor call used for the
initialization shall be one of those allowed in a constant
expression (5.19 [expr.const])...

Replace 8.5.1 [dcl.init.aggr] paragraph 14 as
follows:

When an aggregate with static storage duration is initialized
with a brace-enclosed initializer-list, if all the member
initializer expressions are constant expressions, and the
aggregate is a trivial type, the initialization shall be done
during the static phase of initialization (3.6.2 [basic.start.init]); otherwise, it is unspecified whether the
initialization of members with constant expressions takes place
during the static phase or during the dynamic phase of
initialization.[Note: The order of initialization
for aggregates with static storage duration is specified in
3.6.2 [basic.start.init] and 6.7 [stmt.dcl].
—end note]

(Note: the change to 3.6.2 [basic.start.init] paragraph 1
needs to be reconciled with the conflicting change in
issue 684.)

28.
'exit', 'signal' and static object destruction

The C++ standard has inherited the definition of the 'exit' function
more or less unchanged from ISO C.

However, when the 'exit' function is called, objects of static extent
which have been initialised, will be destructed if their types posses a
destructor.

In addition, the C++ standard has inherited the definition of the 'signal'
function and its handlers from ISO C, also pretty much unchanged.

The C standard says that the only standard library functions that may
be called while a signal handler is executing, are the functions 'abort',
'signal' and 'exit'.

This introduces a bit of a nasty turn, as it is not at all unusual for
the destruction of static objects to have fairly complex destruction semantics,
often associated with resource release. These quite commonly involve apparently
simple actions such as calling 'fclose' for a FILE handle.

Having observed some very strange behaviour in a program recently which
in handling a SIGTERM signal, called the 'exit' function as indicated by
the C standard.

But unknown to the programmer, a library static object performed some
complicated resource deallocation activities, and the program crashed.

The C++ standard says nothing about the interaction between signals,
exit and static objects. My observations, was that in effect, because the
destructor called a standard library function other than 'abort', 'exit'
or 'signal', while transitively in the execution context of the signal
handler, it was in fact non-compliant, and the behaviour was undefined
anyway.

This is I believe a plausible judgement, but given the prevalence of
this common programming technique, it seems to me that we need to say something
a lot more positive about this interaction.

Curiously enough, the C standard fails to say anything about the analogous
interaction with functions registered with 'atexit' ;-)

Proposed Resolution (10/98):

The current Committee Draft of the next version of the ISO C standard
specifies that the only standard library function that may be called while
a signal handler is executing is 'abort'. This would solve the above problem.

[This issue should remain open until it has been decided that the next
version of the C++ standard will use the next version of the C standard
as the basis for the behavior of 'signal'.]

Notes (November, 2006):

C89 is slightly contradictory here: It allows any signal handler to
terminate by calling abort, exit,
longjmp, but (for asynchronous signals, i.e. not those
produced by abort or raise) then makes calling any
library function other than signal with the current signal
undefined behavior (C89 7.7.1.1). For synchronous signals, C99 forbids
calls to raise, but imposes no other restrictions. For
asynchronous signals, C99 allows only calls
to abort, _Exit, and signal with the
current signal (C99 7.14.1.1). The current C++ WP refers to
“plain old functions” and “conforming C
programs” (18.10 [support.runtime] paragraph 6).

Proposed Resolution (November, 2006):

Change the footnote in 18.10 [support.runtime] paragraph 6 as
follows:

In particular, a signal handler using exception handling is very
likely to have problems. Also, invoking std::exit may
cause destruction of objects, including those of the standard library
implementation, which, in general, yields undefined behavior in a
signal handler (see 1.9 [intro.execution]).

Any other allocation function that fails to allocate storage shall
only indicate failure by throwing an exception of
class std::bad_alloc (18.6.2.1 [bad.alloc]) or a
class derived from std::bad_alloc.

Shouldn't this statement have the usual requirements for an
unambiguous and accessible base class?

Proposed resolution (April, 2006):

Change the last sentence of 3.7.4.1 [basic.stc.dynamic.allocation]
paragraph 3 as indicated:

Any other allocation function that fails to allocate storage shall
only indicate failure only by throwing an exception of
class std::bad_alloc (18.6.2.1 [bad.alloc]) or a
class derived from std::bad_alloca type that would
match a handler (15.3 [except.handle]) of type
std::bad_alloc (18.6.2.1 [bad.alloc]).

348.
delete and user-written deallocation functions

Standard is clear on behaviour of default allocation/deallocation
functions.
However, it is surpisingly vague on requirements to the behaviour
of user-defined deallocation function and an interaction between
delete-expression and deallocation function.
This caused a heated argument on fido7.su.c-cpp newsgroup.

Resume:

It is not clear if user-supplied deallocation function is called from
delete-expr when the operand of delete-expr is the null
pointer (5.3.5 [expr.delete]).
If it is, standard does not specify what user-supplied
deallocation function shall do with
the null pointer operand (18.6.1 [new.delete]).
Instead, Standard uses the term "has no effect", which meaning
is too vague in context given (5.3.5 [expr.delete]).

Argument passed to delete-expression is valid - it is the result
of a call to the non-throwing version of ::new, which has been failed.
5.3.5 [expr.delete] paragraph 1 explicitly prohibit us to pass 0
without having the ::new failure.

Standard does NOT specify whether user-defined deallocation function
should be called in this case, or not.

Specifically, standard says in 5.3.5 [expr.delete] paragraph 2:

...if the value of the operand of delete is the null pointer the operation
has no effect.

Standard doesn't specify term "has no effect".
It is not clear from this context, whether the called deallocation function
is required to have no effect, or delete-expression shall not call
the deallocation function.

If the delete-expression calls the implementation deallocation
function (3.7.4.2 [basic.stc.dynamic.deallocation]),
if the operand of the delete expression is not
the null pointer constant, ...

Why it is so specific on interaction of default deallocation function
and delete-expr?

If "has no effect" is a requirement to the deallocation function,
then it should be stated in 3.7.4.2 [basic.stc.dynamic.deallocation],
or in 18.6.1.1 [new.delete.single] and
18.6.1.2 [new.delete.array],
and it should be stated explicitly.

Furthermore, standard does NOT specify what actions shall
be performed by user-supplied deallocation function if NULL
is given (18.6.1.1 [new.delete.single] paragraph 12):

Required behaviour: accept a value of ptr that is null or that was
returned by an earlier call to the default
operator new(std::size_t)
or operator new(std::size_t, const std::nothrow_t&).

The same corresponds to ::delete[] case.

Expected solution:

Make it clear that delete-expr will not call deallocation function
if null pointer is given (in 5.3.5 [expr.delete]).

Specify what user deallocation function shall do when null is given
(either in 3.7.4.2 [basic.stc.dynamic.deallocation], or
in 18.6.1.1 [new.delete.single], and
18.6.1.2 [new.delete.array]).

Notes from October 2002 meeting:

We believe that study of 18.6.1.1 [new.delete.single] paragraphs
12 and 13, 18.6.1.2 [new.delete.array] paragraphs 11 and 12, and
3.7.4.2 [basic.stc.dynamic.deallocation] paragraph 3 shows that the
system-provided operator delete functions must accept a null pointer and
ignore it. Those sections also show that a user-written replacement
for the system-provided operator delete functions must accept a
null pointer. There is no requirement that such functions ignore
a null pointer, which is okay -- perhaps the reason for replacing the
system-provided functions is to do something special
with null pointer values (e.g., log such calls and return).

We believe that the standard should not require an implementation
to call a delete function with a null pointer, but it must allow
that. For the system-provided delete functions or replacements
thereof, the standard already makes it clear that the delete
function must accept a null pointer. For class-specific delete
functions, we believe the standard should require that such
functions accept a null pointer, though it should not mandate
what they do with null pointers.

5.3.5 [expr.delete] needs to be updated to say that
it is unspecified whether or not the operator delete function is
called with a null pointer, and 3.7.4.2 [basic.stc.dynamic.deallocation]
needs to be updated to say that any deallocation function must
accept a null pointer.

Proposed resolution (October, 2004):

Change 5.3.5 [expr.delete] paragraph 2 as
indicated:

If the operand has a class type, the operand is converted to a
pointer type by calling the above-mentioned conversion function,
and the converted operand is used in place of the original
operand for the remainder of this section. In either alternative,
if the value of the operand of deleteis the
null pointer the operation has no effectmay be a null
pointer value. If it is not a null pointer value, inIn the first alternative (delete object), the value
of the operand of delete shall be a pointer to a
non-array object or a pointer to a sub-object (1.8 [intro.object]) representing a base class of such an object
(clause 10 [class.derived])...

Change 5.3.5 [expr.delete] paragraph 4 as
follows (note that the old wording reflects the changes proposed
by issue 442:

The cast-expression in a delete-expression shall
be evaluated exactly once. If the delete-expression calls the
implementation deallocation function (3.7.4.2 [basic.stc.dynamic.deallocation]), and if the value of the operand of the
delete expression is not a null pointer, the deallocation
function will deallocate the storage referenced by the pointer
thus rendering the pointer invalid. [Note: the value of a
pointer that refers to deallocated storage is
indeterminate. —end note]

Change 5.3.5 [expr.delete] paragraphs 6-7 as
follows:

TheIf the value of the operand of the
delete-expression is not a null pointer value, thedelete-expression will invoke the destructor (if any) for
the object or the elements of the array being deleted. In the
case of an array, the elements will be destroyed in order of
decreasing address (that is, in reverse order of the completion
of their constructor; see 12.6.2 [class.base.init]).

TheIf the value of the operand of the delete-expression is not a
null pointer value, thedelete-expression will call a
deallocation function (3.7.4.2 [basic.stc.dynamic.deallocation]). Otherwise, it is unspecified
whether the deallocation function will be called. [Note: The
deallocation function is called regardless of whether the
destructor for the object or some element of the array throws an
exception. —end note]

The value of the first argument supplied to one of thea
deallocation functions provided in the standard library may be a
null pointer value; if so, and if the deallocation function is
one supplied in the standard library, the call to the
deallocation function has no effect. Otherwise, the value
supplied to operator delete(void*) in the standard library shall
be one of the values returned by a previous invocation of either
operator new(std::size_t) or operator new(std::size_t, const
std::nothrow_t&) in the standard library, and the value supplied
to operator delete[](void*) in the standard library shall be one
of the values returned by a previous invocation of either
operator new[](std::size_t) or operator new[](std::size_t, const
std::nothrow_t&) in the standard library.

In the code above, class S does have a non-trivial constructor, the
default constructor generated by the compiler. According the text
above, the lifetime of the auto s would never begin because a
constructor for S is never called. I think the second case in the
text needs to include aggregate initialization.

Mike Miller:
I see a couple of ways of fixing the problem. One way would be
to change "the constructor call has completed" to "the object's
initialization is complete."

Another would be to add following "a class type with a non-trivial
constructor" the phrase "that is not initialized with the brace
notation (8.5.1 [dcl.init.aggr]
)."

The first formulation treats aggregate initialization like a
constructor call; even POD-type members of an aggregate could
not be accessed before the aggregate initialization completed.
The second is less restrictive; the POD-type members of the
aggregate would be usable before the initialization, and the
members with non-trivial constructors (the only way an
aggregate can acquire a non-trivial constructor) would be
protected by recursive application of the lifetime rule.

Proposed resolution (04/01):

In 3.8 [basic.life] paragraph 1, change

If T is a class type with a non-trivial constructor
(12.1 [class.ctor]), the constructor call has
completed.

to

If T is a class type with a non-trivial constructor
(12.1 [class.ctor]), the initialization is complete.
[Note: the initialization can be performed by a
constructor call or, in the case of an aggregate with an
implicitly-declared non-trivial default constructor, an
aggregate initialization (8.5.1 [dcl.init.aggr]).]

The wording in 3.8 [basic.life] paragraph 6 allows an
lvalue designating an out-of-lifetime object to be used as the
operand of a static_cast only if the conversion is
ultimately to "char&" or "unsigned char&".
This description excludes the possibility of using a cv-qualified
version of these types for no apparent reason.

Notes on 04/01 meeting:

The wording should be changed to allow cv-qualified char
types.

Proposed resolution (04/01):

In 3.8 [basic.life] paragraph 6 change the third bullet:

the lvalue is used as the operand of a static_cast
(5.2.9 [expr.static.cast])
(except when the conversion is ultimately to char& or unsigned
char&), or

to read:

the lvalue is used as the operand of a static_cast
(5.2.9 [expr.static.cast])
except when the conversion is ultimately to cv char& or
cv unsigned char&, or

594.
Coordinating issues 119 and 404 with delegating constructors

In ISO/IEC 14882:2003, the second bullet of 3.8 [basic.life] paragraph 1 reads,

if T is a class type with a non-trivial constructor
(12.1 [class.ctor]), the constructor call has completed.

Issue 119 pointed out that
aggregate initialization can be used with some classes with a
non-trivial implicitly-declared default constructor, and that
in such cases there is no call to the object's constructor.
The resolution for that issue was to change the previously-cited
wording to read,

If T is a class type with a non-trivial constructor
(12.1 [class.ctor], the initialization is complete.

Later (but before the WP was revised with the wording from
the resolution of issue 119),
issue 404 changed the 2003 wording to
read,

If T is a class type and the constructor invoked to
create the object is non-trivial (12.1 [class.ctor]),
the constructor call has completed.

thus reversing the effect of issue 119,
whose whole purpose was to cover objects with non-trivial constructors
that are not invoked.

Through an editorial error, the post-Redmond draft (N1905)
still contained the original 2003 wording that should have been
replaced by the resolution of issue 119, in addition to the new wording from the
resolution:

if T is a class type and the constructor invoked to
create the object is non-trivial (12.1 [class.ctor]),
the constructor call has completed. the initialization is
complete.

Finally, during the application of the edits for delegating
constructors (N1986), this editing error was “fixed”
by retaining the original 2003 wording (which was needed for the
application of the change specified in N1986), so that the
current draft (N2009) reads,

if T is a class type and the constructor invoked to
create the object is non-trivial (12.1 [class.ctor]),
the principal constructor call 12.6.2 [class.base.init]) has
completed.

Because the completion of the call to the principal constructor
corresponds to the point at which the object is “fully
constructed” (15.2 [except.ctor] paragraph 2), i.e.,
its initialization is complete, I believe that the exact wording
of the issue 119 resolution would be
correct and should be restored verbatim.

Proposed resolution (June, 2008):

Change 3.8 [basic.life] paragraph 1 as follows:

The lifetime of an object is a runtime property of the
object. An object is said to have non-trivial initialization if it
is of a class or aggregate type and it or one of its members is
initialized by a constructor other than a trivial default
constructor. [Note: Initialization by a trivial copy
constructor is non-trivial initialization. —end note]
The lifetime of an object of type T begins when:

storage with the proper alignment and size for type
T is obtained, and

if T is a class type and the constructor invoked to
create the object is non-trivial (12.1 [class.ctor]), the
principal constructor call (12.6.2 [class.base.init]) has
completed. [Note: the initialization can be performed by a
constructor call or, in the case of an aggregate with an
implicitly-declared non-trivial default constructor, an aggregate
initialization 8.5.1 [dcl.init.aggr]. —end note]the object has non-trivial initialization, its initialization is
complete.

The lifetime of an object of type T ends when...

644.
Should a trivial class type be a literal type?

The original proposed wording for 3.9 [basic.types]
paragraph 11 required a constexpr constructor for a literal class
only “if the class has at least one user-declared
constructor.” This wording was dropped during the
review by CWG out of a desire to ensure that literal types not
have any uninitialized members. Thus, a class like

struct pixel {
int x, y;
};

is not a literal type. However, if an object of that type is
aggregate-initialized or value-initialized, there can be no
uninitialized members; the missing wording should be restored in
order to permit use of expressions like pixel().x as
constant expressions.

Proposed resolution (February, 2008):

Change 3.9 [basic.types] paragraph 10 as follows:

A type is a literal type if it is:

a scalar type; or

a class type (clause 9 [class]) with

a trivial copy constructor,

a trivial destructor,

a trivial default constructor or at least one constexpr
constructor other than the copy constructor,

no virtual base classes, and

all non-static data members and base classes of literal types; or

an array of literal type.

158.
Aliasing and qualification conversions

3.10 [basic.lval] paragraph 15 lists the types via which
an lvalue can be used to access the stored value of an object; using
an lvalue type that is not listed results in undefined behavior. It
is permitted to add cv-qualification to the actual type of the object
in this access, but only at the top level of the type ("a cv-qualified
version of the dynamic type of the object").

However, 4.4 [conv.qual] paragraph 4 permits a
"conversion [to] add cv-qualifiers at levels other than the first in
multi-level pointers." The combination of these two rules
allows creation of pointers that cannot be dereferenced without
causing undefined behavior. For instance:

int* jp;
const int * const * p1 = &jp;
*p1; // undefined behavior!

The reason that *p1 results in undefined behavior
is that the type of the lvalue is const int * const",
which is not "a cv-qualified version of" int*.

Since the conversion is permitted, we must give it defined
semantics, hence we need to fix the wording in 3.10 [basic.lval] to include all possible conversions of the type via
4.4 [conv.qual].

Proposed resolution (04/01):

Add a new bullet to 3.10 [basic.lval] paragraph 15,
following "a cv-qualified version of the dynamic type of the
object:"

A type similar (as defined in 4.4 [conv.qual]) to
the dynamic type of the object,

649.
Optionally ill-formed extended alignment requests

The requirements on an implementation when presented with an
alignment-specifier not supported by that implementation in
that context are contradictory: 3.11 [basic.align] paragraph 9
says,

If a request for a specific extended alignment in a specific context
is not supported by an implementation, the implementation may reject
the request as ill-formed. The implementation may also silently ignore
the requested alignment.

In contrast, 7.6.2 [dcl.align] paragraph 2, bullet 4
says simply,

if the constant expression evaluates to an extended alignment and
the implementation does not support that alignment in the context of
the declaration, the program is ill-formed

with no provision to “silently ignore” the requested
alignment. These two passages need to be reconciled.

If the outcome of the reconciliation is to grant implementations
the license to accept and ignore extended alignment requests, the
specification should be framed in terms of mechanisms that already
exist in the Standard, such as undefined behavior and/or
conditionally-supported constructs; “ill-formed” is a
category that is defined by the Standard, not something that an
implementation can decide.

Notes from the February, 2008 meeting:

The consensus was that such requests should be ill-formed and
require a diagnostic. However, it was also observed that an
implementation need not reject an ill-formed program; the only
requirement is that it issue a diagnostic. It would thus be
permissible for an implementation to “noisily ignore”
(as opposed to “silently ignoring”) an unsupported
alignment request.

Proposed resolution (June, 2008):

Change 3.11 [basic.align] paragraph 9 as follows:

If a request for a specific extended alignment in a specific context
is not supported by an implementation, the implementation may
reject the request asprogram is ill-formed. The
implementation may also silently ignore the requested
alignment. [Note: aAdditionally, a request for runtime
allocation of dynamic memorystorage for which the
requested alignment cannot be honored mayshall be
treated as an allocation failure. —end note]

The null pointer value is converted to the null pointer value of the
destination type.

Add the following sentence to 5.2.9 [expr.static.cast]
paragraph 10:

The null pointer value (4.10 [conv.ptr]) is converted
to the null pointer value of the destination type.

Proposed resolution (October, 2005):

Add the indicated words to 4.10 [conv.ptr]
paragraph 2:

An rvalue of type “pointer to cvT,” where
T is an object type, can be converted to an rvalue of type “pointer to
cvvoid”. The result of converting a “pointer to
cvT” to a “pointer
to cvvoid” points to the start of the storage
location where the object of type T resides, as if the object
is a most derived object (1.8 [intro.object]) of
type T (that is, not a base class subobject). The null
pointer value is converted to the null pointer value of the
destination type.

Add the indicated words to 5.2.9 [expr.static.cast]
paragraph 11:

An rvalue of type “pointer to cv1void”
can be converted to an rvalue of type “pointer
to cv2T,” where T is an object type
and cv2 is the same cv-qualification as, or greater
cv-qualification than, cv1. The null pointer value is
converted to the null pointer value of the destination type. A
value of type pointer to object converted to “pointer
to cvvoid” and back, possibly with different
cv-qualification, shall have its original value...

654.
Conversions to and from nullptr_t

In the interest of promoting use of nullptr instead of the
integer literal 0 as the null pointer constant, the proposal accepted
by the Committee does not provide for converting a zero-valued integral
constant to type std::nullptr_t. However, this omission reduces
the utility of the feature for use in the library for smart pointers.
In particular, the addition of that conversion (along with a converting
constructor accepting a std::nullptr_t) would allow smart
pointers to be used just like ordinary pointers in expressions like:

The existing use of the “unspecified bool type” idiom
supports this usage, but being able to use std::nullptr_t
instead would be simpler and more elegant.

Jason Merrill: I have another reason to support the
conversion as well: it seems to me very odd for nullptr_t to
be more restrictive than void*. Anything we can do with an
arbitrary pointer, we ought to be able to do with nullptr_t
as well. Specifically, since there is a standard conversion from
literal 0 to void*, and there is a standard conversion
from void* to bool, nullptr_t should
support the same conversions.

480.
Is a base of a virtual base also virtual?

When the Standard refers to a virtual base class, it should be
understood to include base classes of virtual bases. However,
the Standard doesn't actually say this anywhere, so when
4.11 [conv.mem] (for example) forbids casting to a
derived class member pointer from a virtual base class member
pointer, it could be read as meaning:

...If B is an inaccessible (clause 11 [class.access]),
ambiguous (10.2 [class.member.lookup]) or virtual (10.1 [class.mi]) base class of D, or a base class of a
virtual base class of D, a program that necessitates this
conversion is ill-formed...

Change 5.2.9 [expr.static.cast] paragraph 2 as indicated:

...and B is notneither a virtual base class
of Dnor a base class of a virtual base class
of D...

Change 5.2.9 [expr.static.cast] paragraph 9 as indicated:

...and B is notneither a virtual base class
of Dnor a base class of a virtual base class of
D...

222.
Sequence points and lvalue-returning operators

I believe that the committee has neglected to take into
account one of the differences between C and C++ when defining
sequence points. As an example, consider

(a += b) += c;

where a, b, and c all have type
int. I believe that this expression has undefined behavior,
even though it is well-formed. It is not well-formed in C, because +=
returns an rvalue there. The reason for the undefined behavior is
that it modifies the value of `a' twice between sequence
points.

Expressions such as this one are sometimes genuinely useful.
Of course, we could write this particular example as

All of the potential rewrites involve multiply-evaluating
p[i] or unobvious circumlocations like creating references
to the array element.

One way to deal with this issue would be to include built-in operators
in the rule that puts a sequence point between evaluating a function's
arguments and evaluating the function itself. However, that might
be overkill: I see no reason to require that in

x[i++] = y;

the contents of `i' must be incremented before the
assignment.

A less stringent alternative might be to say that when a built-in
operator yields an lvalue, the implementation shall not subsequently
change the value of that object as a consequence of that operator.

I find it hard to imagine an implementation that does not do this
already. Am I wrong? Is there any implementation out there that
does not `do the right thing' already for (a += b) += c?

5.17 [expr.ass] paragraph 1 says,

The result of the assignment operation is the value stored in the left
operand after the assignment has taken place; the result is an lvalue.

What is the normative effect of the words "after the assignment has
taken place"? I think that phrase ought to mean that in addition to
whatever constraints the rules about sequence points might impose on
the implementation, assignment operators on built-in types have the
additional constraint that they must store the left-hand side's new
value before returning a reference to that object as their result.

One could argue that as the C++ standard currently stands, the
effect of x = y = 0; is undefined. The reason is that it
both fetches and stores the value of y, and does not fetch
the value of y in order to compute its new value.

I'm suggesting that the phrase "after the assignment has taken
place" should be read as constraining the implementation to set
y to 0 before yielding the value of y as the result
of the subexpression y = 0.

Note that this suggestion is different from asking that there be a
sequence point after evaluation of an assignment. In particular, I am
not suggesting that an order constraint be imposed on any side effects
other than the assignment itself.

Francis Glassborow:

My understanding is
that for a single variable:

Multiple read accesses without a write are OK

A single read access followed by a single write (of a value
dependant on the read, so that the read MUST happen first) is OK

A write followed by an actual read is undefined behaviour

Multiple writes have undefined behaviour

It is the 3) that is often ignored because in practice the compiler
hardly ever codes for the read because it already has that value but
in complicated evaluations with a shortage of registers, that is not
always the case. Without getting too close to the hardware, I think we
both know that a read too close to a write can be problematical on
some hardware.

So, in x = y = 0;, the implementation must NOT fetch a
value from y, instead it has to "know" what that value will
be (easy because it has just computed that in order to know what it
must, at some time, store in y). From this I deduce that
computing the lvalue (to know where to store) and the rvalue to know
what is stored are two entirely independent actions that can occur in
any order commensurate with the overall requirements that both
operands for an operator be evaluated before the operator is.

Erwin Unruh:

C
distinguishes between the resulting value of an assignment and putting the
value in store. So in C a compiler might implement the statement
x=y=0;
either as x=0;y=0; or as y=0;x=0;
In C the statement (x += 5) += 7; is not allowed because the first += yields
an rvalue which is not allowed as left operand to +=.
So in C an assignment is not a sequence of write/read because the result is
not really "read".

In C++ we decided to make the result of assignment an lvalue. In
this case we do not have the option to specify the "value" of the
result. That is just the variable itself (or its address in a
different view). So in C++, strictly speaking, the statement
x=y=0; must be implemented as y=0;x=y; which makes a
big difference if y is declared volatile.

Furthermore, I think undefined behaviour should not be the result of a
single mentioning of a variable within an expression. So the statement
(x +=5) += 7; should NOT have undefined behaviour.

In my view the semantics could be:

if the result of an assignment is used as an rvalue, its value is that of
the variable after assignment. The actual store takes place before the next
sequence point, but may be before the value is used. This is consistent with
C usage.

if the result of an assignment is used as an lvalue to store another
value, then the new value will be stored in the variable before the next
sequence point. It is unspecified whether the first assigned value is stored
intermediately.

if the result of an assignment is used as an lvalue to take an address,
that address is given (it doesn't change). The actual store of the new value
takes place before the next sequence point.

Jerry Schwarz:

My recollection is different from Erwin's. I am confident that the
intention when we decided to make assignments lvalues was not to
change the semantics of evaluation of assignments. The semantics was
supposed to remain the same as C's.

Ervin seems to assume that because assignments are lvalues, an
assignment's value must be determined by a read of the location. But
that was definitely not our intention. As he notes this has a
significant impact on the semantics of assignment to a volatile
variable. If Erwin's interpretation were correct we would have no way
to write a volatile variable without also reading it.

Lawrence Crowl:

For x=y=0, lvalue semantics implies an lvalue to rvalue
conversion on the result of y=0, which in turn implies a
read. If y is volatile, lvalue semantics implies
both a read and a write on y.

The standard apparently doesn't state whether there is a value
dependence of the lvalue result on the completion of the assignment.
Such a statement in the standard would solve the non-volatile C
compatibility issue, and would be consistent with a user-implemented
operator=.

Another possible approach is to state that primitive assignment
operators have two results, an lvalue and a corresponding
"after-store" rvalue. The rvalue result would be used when an rvalue
is required, while the lvalue result would be used when an lvalue is
required. However, this semantics is unsupportable for user-defined
assignment operators, or at least inconsistent with all
implementations that I know of. I would not enjoy trying to write
such two-faced semantics.

Erwin Unruh:

The intent was for assignments to behave the
same as in C. Unfortunately the change of the result to lvalue did not keep
that. An "lvalue of type int" has no "int" value! So there is a difference
between intent and the standard's wording.

So we have one of several choices:

live with the incompatibility (and the problems it has for volatile
variables)

make the result of assignment an rvalue (only builtin-assignment, maybe
only for builtin types), which makes some presently valid programs
invalid

make a special rule for assignment to a volatile lvalue of builtin
type

I think the last one has the least impact on existing programs, but it is an
ugly solution.

Andrew Koenig:

Whatever we may have intended, I do not think that there is any clean
way of making

volatile int v;
int i;
i = v = 42;

have the same semantics in C++ as it does in C. Like it or not, the
subexpression v = 42 has the type ``reference to volatile int,''
so if this statement has any meaning at all, the meaning must be to store 42
in v and then fetch the value of v to assign it to i.

Indeed, if v is volatile, I cannot imagine a
conscientious programmer
writing a statement such as this one. Instead, I would expect to see

v = 42;
i = v;

if the intent is to store 42 in v and then fetch the (possibly
changed) value of v, or

v = 42;
i = 42;

if the intent is to store 42 in both v and i.

What I do want is to ensure that expressions such as ``i = v = 42''
have well-defined semantics, as well as expressions such as
(i = v) = 42 or, more realistically, (i += v) += 42 .

I wonder if the following resolution is sufficient:

Append to 5.17 [expr.ass] paragraph 1:

There is a sequence point between assigning the new value to
the left operand and yielding the result of the assignment
expression.

I believe that this proposal achieves my desired effect of not
constraining when j is incremented in x[j++] = y,
because I don't
think there is a constraint on the relative order of incrementing j
and executing the assignment. However, I do think it allows expressions
such as (i += v) += 42, although with different semantics from C if
v is volatile.

Notes on 10/01 meeting:

There was agreement that adding a sequence point is probably the
right solution.

Notes from the 4/02 meeting:

The working group reaffirmed the sequence-point solution, but
we will look for any counter-examples where efficiency would be harmed.

For drafting, we note that ++x is defined in 5.3.2 [expr.pre.incr] as equivalent to x+=1 and is therefore
affected by this change. x++ is not affected. Also, we
should update any list of all sequence points.

Notes from October 2004 meeting:

Discussion centered around whether a sequence point “between
assigning the new value to the left operand and yielding the result of
the expression” would require completion of all side effects of
the operand expressions before the value of the assignment expression
was used in another expression. The consensus opinion was that it
would, that this is the definition of a sequence point. Jason Merrill
pointed out that adding a sequence point after the assignment is
essentially the same as rewriting

b += a

as

b += a, b

Clark Nelson expressed a desire for something like a
“weak” sequence point that would force the assignment to
occur but that would leave the side effects of the operands
unconstrained. In support of this position, he cited the following
expression:

j = (i = j++)

With the proposed addition of a full sequence point after the
assignment to i, the net effect is no change to j.
However, both g++ and MSVC++ behave differently: if the previous value
of j is 5, the value of the expression is 5 but j
gets the value 6.

Clark Nelson will investigate alternative approaches and report
back to the working group.

351.
Sequence point error: unspecified or undefined?

Between the previous and next sequence point a scalar object shall
have its stored value modified at most once by the evaluation of an
expression. Furthermore, the prior value shall be accessed only to
determine the value to be stored. The requirements of this
paragraph shall be met for each allowable ordering of the
subexpressions of a full expression; otherwise the behavior is
undefined. Example:

i = v[i++]; // the behavior is unspecified
i = 7, i++, i++; // i becomes 9
i = ++i + 1; // the behavior is unspecified
i = i + 1; // the value of i is incremented

--end example]

So which is it, unspecified or undefined?

Notes from October 2002 meeting:

We should find out what C99 says and do the same thing.

Proposed resolution (April 2003):

Change the example in clause 5 [expr], paragraph 4 from

[Example:

i = v[i++]; // the behavior is unspecified
i = 7, i++, i++; //i becomes 9
i = ++i + 1; // the behavior is unspecified
i = i + 1; // the value of i is incremented

--- end example]

to (changing "unspecified" to "undefined" twice)

[Example:

i = v[i++]; // the behavior is undefined
i = 7, i++, i++; //i becomes 9
i = ++i + 1; // the behavior is undefined
i = i + 1; // the value of i is incremented

--- end example]

451.
Expressions with invalid results and ill-formedness

If during the evaluation
of an expression, the result is not mathematically defined or not in
the range of representable values for its type, the behavior is
undefined, unless such an expression is a constant expression (5.19),
in which case the program is ill-formed.

Well, we do know that except in some contexts (e.g. controlling
expression of a #if, array bounds), a compiler is not required to
evaluate constant-expressions in compile time, right?

Now, let us consider, the following simple snippet:

if (a && 1/0)
...

with a, to fix our attention, being *not* a constant expression. The
quote above seems to say that since 1/0 is a constant
(sub-)expression, the program is ill-formed. So, is it the intent that
such ill-formedness is diagnosable at run-time? Or is it the intent
that the above gives undefined behavior (if 1/0 is evaluated) and is
not ill-formed?

I think the intent is actually the latter, so I propose the following
rewording of the quoted section:

If an expression is evaluated but its result is not mathematically
defined or not in the range of representable values
for its type the behavior is undefined, unless such an expression
is a constant expression (5.19) that shall be evaluated during
program translation, in which case the program is ill-formed.

Rationale (March, 2004):

We feel the standard is clear enough. The quoted sentence
does begin "If during the evaluation of an expression, ..."
so the rest of the sentence does not apply to an expression
that is not evaluated.

Note (September, 2004):

Gennaro Prota feels that the CWG missed the point of his
original comment: unless a constant expression appears in a
context that requires a constant expression, an
implementation is permitted to defer its evaluation to runtime.
An evaluation that fails at runtime cannot affect the
well-formedness of the program; only expressions that are
evaluated at compile time can make a program ill-formed.

The status has been reset to “open” to allow
further discussion.

Proposed resolution (October, 2004):

Change paragraph 5 of 5 [expr] as
indicated:

If during the evaluation of an expression, the result is not
mathematically defined or not in the range of representable
values for its type, the behavior is undefined, unless such an
expression is a constant expressionappears where an
integral constant expression is required (5.19 [expr.const]), in which case the program is ill-formed.

122.
template-ids as unqualified-ids

A template-id shall be used as an unqualified-id only
as specified in
14.7.2 [temp.explicit]
,
14.7 [temp.spec]
, and
14.5.5 [temp.class.spec]
.

What uses of template-ids
as unqualified-ids is this supposed to prevent? And is the
list of referenced sections correct/complete? For instance,
what about 14.8.1 [temp.arg.explicit],
"Explicit template argument specification?"
Does its absence from the list in
5.1.1 [expr.prim.general] paragraph 11 mean that
"f<int>()" is ill-formed?

This is even more confusing when you recall that unqualified-ids
are contained in qualified-ids:

qualified-id:
::optnested-name-specifiertemplateoptunqualified-id

Is the wording intending to say "used as an unqualified-id
that is not part of a qualified-id?" Or something else?

Here, it is not clear whether the friend declaration denotes
A B::C() or A::B C(), yet the standard does not resolve this
ambiguity.

The ambiguity arises since both the simple-type-specifier
(7.1.6.2 [dcl.type.simple]
paragra 1) and an
init-declararator
(8 [dcl.decl]
paragraph 1)
contain an optional :: and an optional
nested-name-specifier
(5.1.1 [expr.prim.general]
paragraph 1).
Therefore, two different ways to analyse this code are
possible:

Since it is a friend declaration, the init-declarator may be
qualified, and start with a global scope.

Suggested Resolution: In the definition of
nested-name-specifier, add a
sentence saying that a :: token immediately following a
nested-name-specifier is always considered as part of the
nested-name-specifier. Under this interpretation, the example is
ill-formed, and should be corrected as either

friend A (::B::C)(); //or
friend A::B (::C)();

An alternate suggestion — changing
7.1 [dcl.spec]
to say that

The longest sequence of tokens that could possibly be a type
name is taken as the decl-specifier-seq of a declaration.

— is undesirable because it would make the example well-formed
rather than requiring the user to disambiguate the declaration
explicitly.

Proposed resolution (04/01):

(See below for problem with this, from 10/01 meeting.)

In 5.1.1 [expr.prim.general] paragraph 7,

Before the grammar for qualified-id, start a new
paragraph 7a with the text

A qualified-id is an id-expression that contains the
scope resolution operator ::.

Following the grammar fragment, insert the following:

The longest sequence of tokens that could form a qualified-id
constitutes a single qualified-id. [Example:

It was pointed out that the proposed resolution does not deal with
cases like X::Y where X is a type but not a class type.
The working group reaffirmed its decision that the disambiguation should
be syntactic only, i.e., it should depend only on whether or not the name is a
type.

Jason Merrill
:

At the Seattle meeting, I suggested that a solution might be to change the
class-or-namespace-name in the nested-name-specifier
rule to just be
"identifier"; there was some resistance to this idea. FWIW, I've tried
this in g++. I had to revise the idea so that only the second and
subsequent names were open to being any identifier, but that seems to work
just fine.

Or some equivalent but right-associative formulation, if people feel that's
important, but it seems irrelevant to me.

Clark Nelson
:

Personally, I prefer the left-associative rule. I think it makes it easier
to understand. I was thinking about this production a lot at the meeting,
considering also some issues related to 301.
My formulation was getting kind
of ugly, but with a left-associative rule, it gets a lot nicer.

Your proposal isn't complete, however, as it doesn't allow template
arguments without an explicit template keyword. You probably want to add an
alternative for:

nested-name-specifier type-or-namespace-name::

There is admittedly overlap between this alternative and

nested-name-specifier identifier::

but I think they're both necessary.

Notes from the 4/02 meeting:

The changes look good. Clark Nelson will merge the two proposals
to produce a single proposed resolution.

Proposed resolution (April 2003):

nested-name-specifier is currently defined in
5.1.1 [expr.prim.general] paragraph 7 as:

Issue 215
is addressed by using type-name instead of class-name in the first alternative.
Issue 125 (this issue)
is addressed by using identifier instead of anything more specific in the third alternative.
Using left association instead of right association helps eliminate the need for class-or-namespace-name (or type-or-namespace-name, as suggested for issue 215).

It should be noted that this formulation also rules out the possibility of A::template B::, i.e. using the template keyword without any template arguments.
I think this is according to the purpose of the template keyword, and that the former rule allowed such a construct only because of the difficulty of formulation of a right-associative rule that would disallow it.
But I wanted to be sure to point out this implication.

113.
Visibility of called function

If no declaration of the called function is visible from the scope of
the call the program is ill-formed.

I think nothing there or in the previous paragraph indicates that
this does not apply to calls through pointer or virtual calls.

Mike Miller:
"The called function" is unfortunate phraseology; it makes it
sound as if it's referring to the function actually called, as
opposed to the identifier in the postfix expression. It's
wrong with respect to Koenig lookup, too (the declaration need
not be visible if it can be found in a class or namespace
associated with one or more of the arguments).

In fact, this paragraph should be a note. There's a general
rule that says you have to find an unambiguous declaration of
any name that is used
(3.4 [basic.lookup]
paragraph 1);
the only reason this paragraph
is here is to contrast with C's implicit declaration of called
functions.

Proposed resolution:

Change section 5.2.2 [expr.call] paragraph 2 from:

If no declaration of the called function is visible from the
scope of the call the program is ill-formed.

to:

[Note: if a function or member function name is used,
and name lookup (3.4 [basic.lookup]) does not find a
declaration of that name,
the program is ill-formed. No function is implicitly declared by such
a call. ]

118.
Calls via pointers to virtual member functions

Martin O'Riordan:
Having gone through all the relevant references in the IS, it is not
conclusive that a call via a pointer to a virtual member function
is polymorphic at all, and could legitimately be
interpreted as being static.

Consider 5.2.2 [expr.call]
paragraph 1:

The function called in a member function call is normally selected
according to the static type of the object expression (clause
10 [class.derived]
), but if that function is
virtual and is not specified using a qualified-id then
the function actually called will be the final overrider
(10.3 [class.virtual]
) of the selected
function in the dynamic type of the object expression.

Here it is quite specific that you get the polymorphic call only if you use
the unqualified syntax. But, the address of a member function is "always"
taken using the qualified syntax, which by inference would indicate that
call with a PMF is static and not polymorphic! Not what was intended.

Yet other references such as
5.5 [expr.mptr.oper]
paragraph 4:

If the dynamic type of the object does not contain the member to which
the pointer refers, the behavior is undefined.

indicate that the opposite may have been intended, by stating that it is the
dynamic type and not the static type that matters. Also,
5.5 [expr.mptr.oper]
paragraph 6:

If the result of .* or ->* is a function,
then that result can be used
only as the operand for the function
call operator (). [Example:

(ptr_to_obj->*ptr_to_mfct)(10);

calls the member function denoted by ptr_to_mfct
for the object pointed
to by ptr_to_obj. ]

which also implies that it is the object pointed to that determines both the
validity of the expression (the static type of 'ptr_to_obj'
may not have a
compatible function) and the implicit (polymorphic) meaning. Note too,
that this is stated in the non-normative example text.

Andy Sawyer:
Assuming the resolution is what I've assumed it is for the
last umpteen years (i.e. it does the polymorphic thing), then
the follow on to that is "Should there also be a way of selecting
the non-polymorphic behaviour"?

Mike Miller:
It might be argued that the current wording of
5.2.2 [expr.call]
paragraph 1 does give
polymorphic behavior to simple calls via pointers to members.
(There is no qualified-id in obj.*pmf, and the IS says
that if the function is not specified using a qualified-id, the
final overrider will be called.) However, it clearly says the wrong
thing when the pointer-to-member itself is specified using a
qualified-id (obj.*X::pmf).

Bill Gibbons:
The phrase qualified-id in
5.2.2 [expr.call]
paragraph 1 refers to the
id-expression and not to the "pointer-to-member expression"
earlier in the paragraph:

For a member function call, the postfix expression shall be an
implicit (9.3.1 [class.mfct.non-static]
,
9.4 [class.static]
) or explicit class member
access (5.2.5 [expr.ref]
) whose
id-expression is a function member name, or a pointer-to-member
expression (5.5 [expr.mptr.oper]
) selecting
a function member.

This was moved back to open for lack of a champion. Martin O'Riordan
is not expected to be attending meetings.

Proposed resolution (February, 2008):

Change 5.2.2 [expr.call] paragraph 1 as follows:

... For a member function call, the postfix expression shall be an
implicit (9.3.1 [class.mfct.non-static], 9.4 [class.static]) or
explicit class member access (5.2.5 [expr.ref]) whose
id-expression is a function member name, or a pointer-to-member
expression (5.5 [expr.mptr.oper]) selecting a function member.
The first expression in the postfix expression is then called the
object expression, and; the call is as a member of
the object pointed to or referred to by the object expression
(5.2.5 [expr.ref], 5.5 [expr.mptr.oper]). In the
case of an implicit class member access, the implied object is the one
pointed to by this. [Note: a member function call of
the form f() is interpreted as (*this).f() (see
9.3.1 [class.mfct.non-static]). —end note] If a function or
member function name is used, the name can be overloaded (clause
13 [over]), in which case the appropriate function shall
be selected according to the rules in 13.3 [over.match]. The function called in a member function call is
normally selected according to the static type of the object
expression (clause 10 [class.derived]), but if that function
is virtual and is not specified using a qualified-id
then the function actually called will be the final overrider
(10.3 [class.virtual]) of the selected function in the dynamic
type of the object expressionIf the selected function is
non-virtual, or if the id-expression in the class member access
expression is a qualified-id, that function is called.
Otherwise, its final overrider (10.3 [class.virtual]) in the
dynamic type of the object expression is called. ...

Change 5.5 [expr.mptr.oper] paragraph 4 as follows:

The first operand is called the object expression. If
the dynamic type of the object expression does not contain the
member to which the pointer refers, the behavior is undefined.

When there is no parameter for a given argument, the argument is
passed in such a way that the receiving function can obtain the
value of the argument by invoking va_arg
(18.10 [support.runtime]). The lvalue-to-rvalue
(4.1 [conv.lval]), array-to-pointer
(4.2 [conv.array]), and function-to-pointer
(4.3 [conv.func]) standard conversions are performed
on the argument expression. After these conversions, if the
argument does not have arithmetic, enumeration, pointer,
pointer to member, or class type, the program is ill-formed.
If the argument has a non-POD class type (clause
9 [class]), the behavior is undefined.

Paper J16/04-0167=WG21 N1727 suggests that passing a non-POD
object to ellipsis be ill-formed. In discussions at the
Lillehammer meeting, however, the CWG felt that the newly-approved
category of conditionally-supported behavior would be more
appropriate.

Proposed resolution (October, 2005):

Change 5.2.2 [expr.call] paragraph 7 as indicated:

...After these conversions, if the argument does not have arithmetic,
enumeration, pointer, pointer to member, or class type, the program is
ill-formed. If the argument has a non-POD class type (clause 9),
the behavior is undefined.Passing an argument of non-POD class
type (clause 9) with no corresponding parameter is
conditionally-supported, with implementation-defined semantics.

Issue 506 changed passing a non-POD
class type to an ellipsis from undefined behavior to
conditionally-supported behavior. As a result, an implementation could
conceivably reject code like the following:

This technique has become popular in template metaprogramming,
and no non-POD object is actually passed at runtime. Concepts
will eliminate much (perhaps not all) of the need for this
kind of programming, but legacy code will persist.

Perhaps this technique should be officially supported by allowing
implementations to reject passing a non-POD type to ellipsis only if
it appears in a potentially-evaluated expression?

Notes from the July, 2007 meeting:

The CWG agreed with the suggestion to allow such calls in
unevaluated contexts.

466.
cv-qualifiers on pseudo-destructor type

The type designated by the pseudo-destructor-name shall be the same
as the object type.

and also:

The cv-unqualified versions of the object type and of the type
designated by the pseudo-destructor-name shall be the same type.

Which is it? "The same" or "the same up to cv-qualifiers"? The
second sentence is more generous than the first. Most compilers seem
to implement the less restrictive form, so I guess that's what I think
we should do.

The left-hand side of the dot operator shall be of scalar type. The
left-hand side of the arrow operator shall be of pointer to scalar
type. This scalar type is the object type. The type designated by the
pseudo-destructor-name shall be the same as the object
type.The cv-unqualified versions of
the object type and of the type designated by the
pseudo-destructor-name shall be the same type. Furthermore,
the two type-names in a pseudo-destructor-name of the
form

::opt nested-name-specifieropt type-name ::~ type-name

shall designate the same scalar type. The cv-unqualified versions of
the object type and of the type designated by the
pseudo-destructor-name shall be the same type.

492.
typeid constness inconsistent with example

There is an inconsistency between the normative text in
section 5.2.8 [expr.typeid] and
the example that follows.

Here is the relevant passage (starting with paragraph 4):

When typeid is applied to a type-id, the result
refers to a std::type_info object representing the type of the
type-id. If the type of the type-id is a reference
type, the result of the typeid expression refers to a
std::type_info object representing the referenced type.

The top-level cv-qualifiers of the lvalue expression or the
type-id that is the operand of typeid are always
ignored.

and the example:

typeid(D) == typeid(const D&); // yields true

The second paragraph above says the “type-id that is
the operand”. This would be const D&. In
this case, the const is not at the top-level (i.e.,
applied to the operand itself).

By a strict reading, the above should yield false.

My proposal is that the strict reading of the normative test is correct.
The example is wrong. Different compilers here give different
answers.

Proposed resolution (April, 2005):

Change the second sentence of 5.2.8 [expr.typeid]
paragraph 4 as follows:

If the type of the type-id is a reference to a possibly
cv-qualified type, the result of the typeid expression
refers to a std::type_info object representing the
cv-unqualified referenced type.

54.
Static_cast from private base to derived class

Is it okay to use a static_cast to cast from a private base
class to a derived class? That depends on what the words "valid standard
conversion" in paragraph 8 mean — do they mean the conversion exists,
or that it would not get an error if it were done? I think the former
was intended — and therefore a static_cast from a private base
to a derived class would be allowed.

Rationale (04/99): A static_cast from a private
base to a derived class is not allowed outside a member from the
derived class, because 4.10 [conv.ptr]
paragraph 3 implies that the conversion is not valid. (Classic style
casts work.)

Reopened September 2003:

Steve Adamczyk:
It makes some sense to disallow the inverse conversion that is
pointer-to-member of derived to pointer-to-member of private base.
There's less justification for the pointer-to-private-base to
pointer-to-derived case. EDG, g++ 3.2, and MSVC++ 7.1 allow
the pointer case and disallow the pointer-to-member case.
Sun disallows the pointer case as well.

There's a tricky case with old-style casts: because the
static_cast interpretation is tried first, you want a case
like the above to be considered a static_cast, but then issue
an error, not be rejected as not a static cast; if you did the
latter, you would then try the cast as a reinterpret_cast.

Ambiguity and casting to a virtual base should likewise be
errors after the static_cast interpretation is selected.

Notes from the October 2003 meeting:

There was lots of sentiment for making things symmetrical:
the pointer case should be the same as the pointer-to-member case.
g++ 3.3 now issues errors on both cases.

We decided an error should be issued on both cases.
The access part of the check should be done later; by some
definition of the word the static_cast is valid, and then
later an access error is issued.
This is similar to the way standard conversions work.

Proposed Resolution (October 2003):

Replace paragraph 5.2.9 [expr.static.cast]/6:

The inverse of any standard conversion sequence (clause
4 [conv]), other than the
lvalue-to-rvalue (4.1 [conv.lval]),
array-to-pointer (4.2 [conv.array]),
function-to-pointer (4.3 [conv.func]), and
boolean (4.12 [conv.bool]) conversions, can be performed
explicitly using static_cast.
The lvalue-to-rvalue (4.1 [conv.lval]),
array-to-pointer (4.2 [conv.array]), and
function-to-pointer (4.3 [conv.func])
conversions are applied to the operand.
Such a
static_cast
is subject to the restriction that the explicit conversion does not
cast away constness (5.2.11 [expr.const.cast]), and the following
additional rules for specific cases:

with two paragraphs:

The inverse of any standard conversion sequence (clause
4 [conv]), other than the
lvalue-to-rvalue (4.1 [conv.lval]),
array-to-pointer (4.2 [conv.array]),
function-to-pointer (4.3 [conv.func]), and
boolean (4.12 [conv.bool]) conversions, can be performed
explicitly using static_cast.
A program is ill-formed if it
uses static_cast to perform the inverse of an ill-formed
standard conversion sequence.[Example:

The lvalue-to-rvalue (4.1 [conv.lval]),
array-to-pointer (4.2 [conv.array]), and
function-to-pointer (4.3 [conv.func])
conversions are applied to the operand.
Such a
static_cast
is subject to the restriction that the explicit conversion does not
cast away constness (5.2.11 [expr.const.cast]), and the following
additional rules for specific cases:

In addition, modify the second sentence of
5.4 [expr.cast]/5. The first two
sentences of 5.4 [expr.cast]/5 presently read:

The conversions performed by

a const_cast (5.2.11),

a static_cast (5.2.9),

a static_cast followed by a const_cast,

a reinterpret_cast (5.2.10), or

a reinterpret_cast followed by a const_cast,

can be performed using the cast notation of explicit type conversion.
The same semantic restrictions and behaviors apply.

Change the second sentence to read:

The same semantic restrictions and behaviors apply, with the exception
that in performing a static_cast in the following situations
the conversion is valid even if the base class is inaccessible:

a pointer to an object of derived class type or an lvalue of
derived class type may be explicitly converted to a pointer or
reference to an unambiguous base class type, respectively;

a pointer to member of derived class type may be explicitly
converted to a pointer to member of an unambiguous non-virtual base
class type;

a pointer to an object of an unambiguous non-virtual
base class type, an lvalue of an unambiguous non-virtual base
class type, or a pointer to member of an unambiguous
non-virtual base class type may be explicitly converted to a pointer,
a reference, or a pointer to member of a derived class type,
respectively.

Remove paragraph 5.4 [expr.cast]/7, which presently reads:

In addition to
those conversions,
the following
static_cast
and
reinterpret_cast
operations
(optionally followed by a
const_cast
operation)
may be performed using the cast notation of explicit type conversion,
even if the base class type is not accessible:

a pointer to an object of derived class type or an lvalue of derived class
type may be explicitly converted
to a pointer or reference to an unambiguous base class type, respectively;

a pointer to member of derived class type may be explicitly converted
to a pointer to member of an unambiguous non-virtual base class type;

a pointer to an object of non-virtual base class type, an lvalue
of non-virtual base class type, or a pointer to member of non-virtual
base class type may be explicitly converted to a pointer, a reference,
or a pointer to member of a derived class type, respectively.

The rules for static_cast permit the conversion to
"const D&" in two ways:

D is derived from B, and b is an lvalue, so a cast to D& is OK.

const D& t = b is valid, using the constructor for D. [Ed. note:
actually, this should be parenthesized initialization.]

The first alternative is 5.2.9 [expr.static.cast]/5; the second is
5.2.9 [expr.static.cast]/2.

Presumably the first alternative is better -- it's the "simpler"
conversion. The standard does not seem to make that clear.

Steve Adamczyk:
I take the "Otherwise" at the beginning of
5.2.9 [expr.static.cast]/3 as meaning that
the paragraph 2 interpretation is used if available, which means in
your example above interpretation 2 would be used. However, that's
not what EDG's compiler does, and I agree that it's not the "simpler"
conversion.

Proposed Resolution (October 2003):

Move paragraph 5.2.9/5:

An lvalue of type
``cv1B'',
where
B
is a class type, can be cast to type ``reference to
cv2D'',
where
D
is a class derived (clause
10 [class.derived]) from
B,
if a valid standard conversion from ``pointer to
D''
to ``pointer to
B''
exists (4.10 [conv.ptr]),
cv2
is the same cv-qualification as, or greater cv-qualification than,
cv1,
and
B
is not a virtual base class of
D.
The result is an lvalue of type
``cv2D.''
If the lvalue of type
``cv1B''
is actually a sub-object of an object of type
D,
the lvalue refers to the enclosing object of type
D.
Otherwise, the result of the cast is undefined.
[Example:

Insert Otherwise, before the text of paragraph
5.2.9 [expr.static.cast]/2
(which will become 5.2.9 [expr.static.cast]/3
after the above insertion), so that it
reads:

Otherwise, an expression
e
can be explicitly converted to a type
T
using a
static_cast
of the form
static_cast<T>(e)
if the declaration
"T t(e);"
is well-formed, for some invented temporary variable
t
(8.5 [dcl.init]).
The effect of such an explicit conversion is the same as performing the
declaration and initialization and then using the temporary variable
as the result of the conversion.
The result is an lvalue if
T
is a reference type (8.3.2 [dcl.ref]), and an rvalue otherwise.
The expression
e
is used as an lvalue if and only if the initialization uses it as an lvalue.

439.
Guarantees on casting pointer back to cv-qualified version of original type

there should be no call to "abort". The last sentence of Paragraph
5.2.9 [expr.static.cast] paragraph 10 should be changed to read:

A value of type pointer to object converted to "pointer to
cvvoid" and back to the original pointer type
(or a variant of the original pointer type that differs only in the
cv-qualifiers applied to the object type) will have its
original value.
[Example:

Rationale: The wording "possibly with different
cv-qualification" was chosen over the suggested wording to
allow for changes in cv-qualification at different levels in a
multi-level pointer, rather than only at the object type level.

This is because values of scope enumeration types (intentionally)
cannot be implicitly converted to integral types (4.5 [conv.prom]
and 4.7 [conv.integral]) and 5.2.9 [expr.static.cast] was not
updated to permit #2, although #1 is covered by paragraph 8.

Proposed resolution (June, 2008):

Add the following as a new paragraph following 5.2.9 [expr.static.cast] paragraph 8:

A value of a scoped enumeration type (7.2 [dcl.enum]) can be
explicitly converted to an integral type. The value is unchanged if
the original value can be represented by the specified
type. Otherwise, the resulting value is unspecified.

195.
Converting between function and object pointers

It is currently not permitted to cast directly between a pointer to
function type and a pointer to object type. This conversion is not
listed in 5.2.9 [expr.static.cast]
and
5.2.10 [expr.reinterpret.cast]
and thus
requires a diagnostic to be issued. However, if a sufficiently long
integral type exists (as is the case in many implementations), it is
permitted to cast between pointer to function types and pointer to
object types using that integral type as an intermediary.

In C the cast results in undefined behavior and thus does not
require a diagnostic, and Unix C compilers generally do not issue
one. This fact is used in the definition of the standard Unix
function dlsym, which is declared to return void*
but in fact may return either a pointer to a function or a pointer to
an object. The fact that C++ compilers are required to issue a
diagnostic is viewed as a "competitive disadvantage" for the language.

Suggested resolution: Add wording to
5.2.10 [expr.reinterpret.cast]
allowing
conversions between pointer to function and pointer to object types,
if the implementation has an integral data type that can be used as an
intermediary.

Several points were raised in opposition to this suggestion:

Early C++ supported this conversion and it was deliberately
removed during the standardization process.

The existence of an appropriate integral type is irrelevant to
whether the conversion is "safe." The condition should be on whether
information is lost in the conversion or not.

There are numerous ways to address the problem at an
implementation level rather than changing the language. For example,
the compiler could recognize the specific case of dlsym and
omit the diagnostic, or the C++ binding to dlsym could be
changed (using templates, for instance) to circumvent the violation.

The conversion is, in fact, not supported by C; the dlsym
function is simply relying on non-mandated characteristics of C
implementations, and we would be going beyond the requirements of C
compatibility in requiring (some) implementations to support the
conversion.

This issue is in fact not a defect (omitted or self-contradictory
requirements) in the current Standard; the proposed change would
actually be an extension and should not be considered until the full
review of the IS.

dlsym appears not to be used very widely, and the
declaration in the header file is not problematic, only calls to it.
Since C code generally requires some porting to be valid C++ anyway,
this should be considered one of those items that requires porting.

Martin O'Riordan suggested an alternative approach:

Do not allow the conversions to be performed via old-style casts.

Allow reinterpret_cast to perform the conversions with
the C-style semantics (undefined behavior if not supported).

Allow dynamic_cast to perform the conversions with
well-defined behavior: the result would be a null pointer if the
implementation could not support the requested conversion.

The advantage of this approach is that it would permit writing
portable, well-defined programs involving such conversions. However,
it breaks the current degree of compatibility between old and new
casts, and it adds functionality to dynamic_cast which is not
obviously related to its current meaning.

Notes from 04/00 meeting:

Andrew Koenig suggested yet another approach: specify that "no
diagnostic is required" if the implementation supports the conversion.

Later note:

It was observed that conversion between function and data pointers
is listed as a "common extension" in C99.

Notes on the 10/01 meeting:

It was decided that we want the conversion defined in such a way that
it always exists but is always undefined (as opposed to existing only
when the size relationship is appropriate, and being implementation-defined
in that case). This would allow an implementation to issue an error
at compile time if the conversion does not make sense.

Bill Gibbons notes that the definitions of the other similar casts are
inconsistent in this regard. Perhaps they should be updated as well.

Proposed resolution (April 2003):

After 5.2.10 [expr.reinterpret.cast]
paragraph 6, insert:

A pointer to a
function can be explicitly converted to a pointer to a function of a different
type. The effect of calling a function through a pointer to a function
type (8.3.5 [dcl.fct])
that is not the same as the type used in the definition of the function is
undefined. Except that converting an rvalue of type ``pointer to T1''
to the type ``pointer to T2'' (where T1 and T2 are
function types) and back to its original type yields the original pointer
value, the result of such a pointer conversion is unspecified. [Note: see
also 4.10 [conv.ptr] for more details of pointer conversions. ]
It is implementation defined whether a conversion from pointer to object to
pointer to function and/or a conversion from pointer to function to pointer to
object exist.

and in paragraph 10:

An lvalue expression of type T1 can be cast to the type
``reference to T2''
if T1 and T2 are object types and an expression of
type ``pointer to T1'' can be explicitly converted to the type
``pointer to T2'' using a reinterpret_cast. That is, a reference
cast reinterpret_cast< T& >(x) has the same effect
as the conversion *reinterpret_cast< T* >(&x) with
the built-in & and * operators.
The result is an lvalue that refers to the same object as the source lvalue,
but with a different type. No temporary is created, no copy is made, and
constructors (12.1 [class.ctor]) or conversion functions
(12.3 [class.conv]) are not called.

Drafting Note:

If either conversion exists, the implementation already has to define the
behavior (paragraph 3).

Notes from April 2003 meeting:

The new consensus is that if the implementation allows
this cast, pointer-to-function converted to pointer-to-object converted
back to the original pointer-to-function should work; anything else
is undefined behavior. If the implementation does not allow the cast,
it should be ill-formed.

Tom Plum is investigating a new concept, that of a
"conditionally-defined" feature, which may be applicable here.

Proposed Resolution (October, 2004):

(See paper J16/04-0067 = WG21 N1627 for background material and
rationale for this resolution. The resolution proposed here differs
only editorially from the one in the paper.)

Insert the following into 1.3 [intro.defs] and renumber
all following definitions accordingly:

1.3.2 conditionally-supported behavior

behavior evoked by a program construct that is not a mandatory
requirement of this International Standard. If a given implementation
supports the construct, the behavior shall be as described herein;
otherwise, the implementation shall document that the construct is not
supported and shall treat a program containing an occurrence of the
construct as ill-formed (1.3 [intro.defs]).

If a program contains a violation of any diagnosable
rule, or an occurrence of a construct described herein as
“conditionally-supported” or as resulting in
“conditionally-supported behavior” when the implementation
does not in fact support that construct, a conforming
implementation shall issue at least one diagnostic message, except
that

Insert the following as a new paragraph following 5.2.10 [expr.reinterpret.cast] paragraph 7:

Converting a pointer to a function to a pointer to an object type or
vice versa evokes conditionally-supported behavior. In any such
conversion supported by an implementation, converting from an rvalue
of one type to the other and back (possibly with different
cv-qualification) shall yield the original pointer value; mappings
between pointers to functions and pointers to objects are otherwise
implementation-defined.

Change 7.4 [dcl.asm] paragraph 1 as indicated:

The meaning of anAnasm declaration evokes
conditionally-supported behavior. If supported, its meaning is
implementation-defined.

Change 7.5 [dcl.link] paragraph 2 as indicated:

The string-literal indicates the required language linkage. The meaning of the
string-literal is implementation-defined. A linkage-specification with a string that
is unknown to the implementation is ill-formed.This International Standard
specifies the semantics of C and C++ language linkage. Other values of the
string-literal evoke conditionally-supported behavior, with
implementation-defined semantics. [Note: Therefore, a
linkage-specification with a string-literal that is
unknown to the implementation requires a diagnostic.When the
string-literal in a linkage-specification names a programming
language, the spelling of the programming language's name is
implementation-defined. [Note:It is recommended that the
spelling be taken from the document defining that language, for
example Ada (not ADA) and Fortran or
FORTRAN (depending on the vintage). The semantics of a
language linkage other than C++ or C are implementation-defined. ]

Change 14 [temp] paragraph 4 as indicated:

A template, a template explicit specialization (14.7.3 [temp.expl.spec]), or a class template partial specialization shall
not have C linkage. If the linkage of one of these is something other
than C or C++, the behavior is implementation-definedresult
is conditionally-supported behavior, with implementation-defined
semantics.

463.
reinterpret_cast<T*>(0)

Is reinterpret_cast<T*>(null_pointer_constant)
guaranteed to yield the
null pointer value of type T*?

I think a committee clarification is needed. Here's why:
5.2.10 [expr.reinterpret.cast]
par. 8 talks of "null pointer value", not
"null pointer constant", so it would seem that

reinterpret_cast<T*>(0)

is a normal int->T* conversion, with an implementation-defined result.

However a little note to
5.2.10 [expr.reinterpret.cast] par. 5 says:

Converting an integral constant expression (5.19) with value zero
always yields a null pointer (4.10), but converting other
expressions that happen to have value zero need not yield a null
pointer.

Where is this supported in normative text? It seems that either the
footnote or paragraph 8 doesn't reflect the intent.

SUGGESTED RESOLUTION: I think it would be better to drop the footnote
#64 (and thus the special case for ICEs), for two reasons:

a) it's not normative anyway; so I doubt anyone is relying on the
guarantee it hints at, unless that guarantee is given elsewhere in a
normative part

b) users expect reinterpret_casts to be almost always implementation
dependent, so this special case is a surprise. After all, if one wants
a null pointer there's static_cast. And if one wants reinterpret_cast
semantics the special case requires doing some explicit cheat, such as
using a non-const variable as intermediary:

It seems that not only that's providing a duplicate functionality, but
also at the cost to hide what seems the more natural one.

Notes from October 2004 meeting:

This footnote was added in 1996, after the invention of
reinterpret_cast, so the presumption must be that it was
intentional. At this time, however, the CWG feels that there is
no reason to require that reinterpret_cast<T*>(0)
produce a null pointer value as its result.

Converting an integral constant expression
(5.19 [expr.const]) with value zero always yields a null
pointer (4.10 [conv.ptr]), but converting other expressions
that happen to have value zero need not yield a null pointer.

Add the indicated note to 5.2.10 [expr.reinterpret.cast] paragraph
8:

The null pointer value (4.10 [conv.ptr]) is converted to
the null pointer value of the destination type. [Note:
A null pointer constant, which has integral type, is not necessarily
converted to a null pointer value. —end note]

If the second and third operands are lvalues and have
the same type, the result is of that type and is an lvalue
and it is a bit-field if the second or the third
operand is a bit-field, or if both are bit-fields.

In 5.17 [expr.ass] paragraph 1 (assignment operators)
add the indicated text (the original text is
as updated by issue 221, which is DR but not in TC1):

The assignment operator (=) and the compound assignment
operators all group right-to-left. All require a modifiable lvalue as
their left operand and return an lvalue with the type and value of
the left operand after the assignment has taken place. The result
in all cases is a bit-field if the left operand is a bit-field.

Note that issue 222 adds (non-conflicting) text at the end of
this same paragraph (5.17 [expr.ass] paragraph 1).

In 5.18 [expr.comma] paragraph 1 (comma operator), change:

The type and value of the result are the type and value of the right
operand; the result is an lvalue if its right operand is.

to

The type and value of the result are the type and value of the right
operand; the result is an lvalue if the right operand is an lvalue,
and is a bit-field if the right operand is an lvalue and a bit-field.

The size requested by an array allocation is computed by multiplying
the number of elements requested by the size of each element and adding
an implementation-specific amount for overhead. It is possible for this
calculation to overflow. Is an implementation required to detect this
situation and, for instance, throw std::bad_alloc?

On one hand, the maximum allocation size is one of the implementation
limits specifically mentioned in Annex B [implimits], and,
according to 1.4 [intro.compliance] paragraph 2, an implementation
is only required to "accept and correctly execute" programs that do
not violate its resource limits.

On the other hand, it is difficult or impossible for user code
to detect such overflows in a portable fashion, especially given that
the array allocation overhead is not fixed, and it would be a
service to the user to handle this situation gracefully.

Rationale (04/01):

Each implementation is required to document the maximum size
of an object (Annex B [implimits]). It is not
difficult for a program to check array allocations to ensure
that they are smaller than this quantity. Implementations
can provide a mechanism in which users concerned with this
problem can request extra checking before array allocations,
just as some implementations provide checking for array index
and pointer validity. However, it would not be appropriate to
require this overhead for every array allocation in every
program.

299.
Conversion on array bound expression in new

In 5.3.4 [expr.new], the standard says that the
expression in an array-new has to
have integral type. There's already a DR (issue 74)
that says it should also be allowed to have enumeration type. But, it should
probably also say that it can have a class type with a single
conversion to integral type; in other words the same thing as in
6.4.2 [stmt.switch] paragraph 2.

Suggested resolution:

In 5.3.4 [expr.new] paragraph 6, replace
"integral or enumeration type (3.9.1 [basic.fundamental])" with
"integral or enumeration type (3.9.1 [basic.fundamental]), or a class
type for which a single conversion function to
integral or enumeration type exists".

Proposed resolution (October, 2004):

Change 5.3.4 [expr.new] paragraph 6 as
follows:

Every constant-expression in a
direct-new-declarator shall be an integral constant
expression (5.19 [expr.const]) and evaluate to a
strictly positive value. The expression in a
direct-new-declarator shall havebe of
integral type, or enumeration type (3.9.1), or a
class type for which a single conversion function to integral or
enumeration type exists (12.3 [class.conv]). If the
expression is of class type, the expression is converted by
calling the conversion function, and the result of the conversion
is used in place of the original expression. The value of the
expression shall bewith a non-negative
value. [Example: ...

Proposed resolution (April, 2005):

Change 5.3.4 [expr.new] paragraph 6 as
follows:

Every constant-expression in a
direct-new-declarator shall be an integral constant
expression (5.19 [expr.const]) and evaluate to a
strictly positive value. The expression in a
direct-new-declarator shall have integral or enumeration
type (3.9.1 [basic.fundamental]) with a non-negative
valuebe of integral type, enumeration type, or a class type for
which a single conversion function to integral or enumeration type
exists (12.3 [class.conv]). If the expression is of class
type, the expression is converted by calling that conversion function,
and the result of the conversion is used in place of the original
expression. If the value of the expression is negative, the behavior
is undefined. [Example: ...

429.
Matching deallocation function chosen based on syntax or signature?

The fundamental issue here is whether the deletion-on-throw
is driven by the syntax of the new (placement or non-placement)
or by signature matching. If the former, the operator delete
would be called with the second argument equal to the size of
the class. If the latter, it would be called with the second
argument 0.

Core issue 127 (in TC1) dealt with
this topic. It removed some wording
in 15.2 [except.ctor] paragraph 2 that implied a
syntax-based interpretation, leaving wording
in 5.3.4 [expr.new] paragraph 19 that is
signature-based. But there is no accompanying
rationale to confirm an explicit choice of the signature-based
approach.

EDG and g++ get 0 for the second argument, matching the presumed
core issue 127 resolution. But maybe this should be revisited.

Notes from October 2003 meeting:

There was widespread agreement that the compiler shouldn't
just silently call the delete with either of the possible values.
In the end, we decided it's smarter to issue an error on this
case and force the programmer to say what he means.

Mike Miller's analysis of the status quo:
3.7.4.2 [basic.stc.dynamic.deallocation] paragraph 2
says that "operator delete(void*, std::size_t)" is a
"usual (non-placement) deallocation function" if the class does
not declare "operator delete(void*)."
3.7.4.1 [basic.stc.dynamic.allocation] does not use the
same terminology for allocation functions, but the most
reasonable way to understand the uses of the term "placement
allocation function" in the Standard is as an allocation function
that has more than one parameter and thus can (but need not) be
called using the "new-placement" syntax described in
5.3.4 [expr.new]. (In
considering issue 127,
the core group discussed and endorsed the
position that, "If a placement allocation function has default
arguments for all its parameters except the first, it can be
called using non-placement syntax.")

5.3.4 [expr.new] paragraph 19
says that any non-placement deallocation function
matches a non-placement allocation function, and that a placement
deallocation function matches a placement allocation function
with the same parameter types after the first -- i.e., a
non-placement deallocation function cannot match a placement
allocation function. This makes sense, because non-placement
("usual") deallocation functions expect to free memory obtained
from the system heap, which might not be the case for storage
resulting from calling a placement allocation function.

According to this analysis, the example shows a placement
allocation function and a non-placement deallocation function, so
the deallocation function should not be invoked at all, and the
memory will just leak.

Proposed Resolution (October 2003):

Add the following text at the end of 5.3.4 [expr.new]
paragraph 19:

If the lookup finds the two-parameter form of a usual deallocation function
(3.7.4.2 [basic.stc.dynamic.deallocation]), and that function, considered as
a placement deallocation function, would have been selected as a match
for the allocation function, the program is ill-formed.
[Example:

624.
Overflow in calculating size of allocation

[Voted into the WP at the September, 2008 meeting (resolution
in paper N2757).]

Issue 256 was closed without action,
principally on the the grounds that an implementation could provide a
means (command-line option, #pragma, etc.) for requesting
that the allocation size be checked for validity, but that “it
would not be appropriate to require this overhead for every array
allocation in every program.”

This rationale may be giving too much weight to the overhead such a
check would add, especially when compared to the likely cost of
actually doing the storage allocation. In particular, the test
essentially amounts to something like

(noting that max_allocation_size/sizeof(T) is a
compile-time constant). It might make more sense to turn the
rationale around and require the check, assuming that implementations
could provide a mechanism for suppressing it if needed.

Suggested resolution:

In 5.3.4 [expr.new] paragraph 7, add the following
words before the example:

If the value of the expression is such that the size of the allocated
object would exceed the implementation-defined limit, an exception of
type std::bad_alloc is thrown and no storage is obtained.

Note (March, 2008):

The Evolution Working Group has accepted the intent of
issue 256 and referred it to CWG for
action for C++0x (see paper J16/07-0033 = WG21 N2173).

Proposed resolution (March, 2008):

As suggested.

Notes from the June, 2008 meeting:

The CWG felt that this situation should not be treated like an
out-of-memory situation and thus an exception of type
std::bad_alloc (or, alternatively, returning a null pointer
for a throw() allocator) would not be appropriate.

Proposed resolution (June, 2008):

Change 5.3.4 [expr.new] paragraph 8 as follows:

If the value of the expression in a
direct-new-declarator is such that the size of the
allocated object would exceed the implementation-defined limit, no
storage is obtained and the new-expression terminates by
throwing an exception of a type that would match a handler
(15.3 [except.handle]) of type std::length_error
(19.2.4 [length.error]). Otherwise, ifWhen the value of thethatexpressionin a
direct-new-declarator is zero, the allocation function is
called to allocate an array with no elements.

[Drafting note: std::length_error is thrown by
std::string and std::vector and thus appears to
be the right choice for the exception to be thrown here.]

288.
Misuse of "static type" in describing pointers

The operand shall have a pointer type, or a class type having
a single conversion function to a pointer type.

However,
paragraph 3 of that same section says:

if the static type of the
operand is different from its dynamic type, the static type shall be a
base class of the operand's dynamic type and the static type shall
have a virtual destructor or the behavior is undefined.

Since the operand must be of pointer type, its static type is
necessarily the same as its dynamic type. That clause is clearly
referring to the object being pointed at, and not to the pointer operand
itself.

Correcting the wording gets a little complicated, because dynamic
and static types are attributes of expressions, not objects, and
there's no sub-expression of a delete-expression which has the
relevant types.

Suggested resolution:

then there is a static type and a dynamic type that the hypothetical
expression (*const-expression) would
have. If that static type is different from that dynamic type, then
that static type shall be a base class of that dynamic type, and that
static type shall have a virtual destructor, or the behavior is
undefined.

There's precedent for such use of hypothetical constructs: see
5.10 [expr.eq] paragraph 2, and 8.1 [dcl.name]
paragraph 1.

10.3 [class.virtual] paragraph 3 has a similar problem. It
refers to

the type of the pointer or reference denoting the object
(the static type).

The type of the pointer is different from the type of the
reference, both of which are different from the static type of
'*pointer', which is what I think was actually intended. Paragraph 6
contains the exact same wording, in need of the same correction. In
this case, perhaps replacing "pointer or reference" with "expression"
would be the best fix. In order for this fix to be sufficient,
pointer->member must be considered equivalent to
(*pointer).member, in which case the "expression" referred to
would be (*pointer).

12.5 [class.free] paragraph 4 says that

if a delete-expression is used to deallocate a class object
whose static type has...

This should be changed to

if a delete-expression is used to deallocate a class object
through a pointer expression whose dereferenced static type would
have...

The same problem occurs later,
when it says that the

static and dynamic types of the object shall be
identical

In this case you could replace "object" with "dereferenced
pointer expression".

Footnote 104 says that

5.3.5 [expr.delete] requires that ... the static type of the
delete-expression's operand be the same as its dynamic type.

This
would need to be changed to

the delete-expression's dereferenced
operand

Proposed resolution (December, 2006):

Change 5.3.5 [expr.delete] paragraph 3 as follows:

In the first alternative (delete object), if the static type of
the operandobject to be deleted is different from its
dynamic type, the static type shall be a base class of
the operand’s dynamic type of the object to be deleted
and the static type shall have a virtual destructor or the behavior is
undefined. In the second alternative (delete array) if the
dynamic type of the object to be deleted differs from its static type,
the behavior is undefined.

Change the footnote in 12.5 [class.free] paragraph 4 as
follows:

A similar provision is not needed for the array version
of operator delete because 5.3.5 [expr.delete]
requires that in this situation, the static type of the
delete-expression’s operandobject to be deleted
be the same as its dynamic type.

Change the footnote in 12.5 [class.free] paragraph 5 as
follows:

If the static type in the delete-expressionof the
object to be deleted is different from the dynamic type and the
destructor is not virtual the size might be incorrect, but that case
is already undefined; see 5.3.5 [expr.delete].

[Drafting notes: No change is required for
10.3 [class.virtual] paragraph 7 because “the type of
the pointer” includes the pointed-to type. No change is
required for 12.5 [class.free] paragraph 4 because
“...used to deallocate a class object whose static
type...” already refers to the object (and not the
operand expression).]

353.
Is deallocation routine called if destructor throws exception in delete?

In a couple of comp.std.c++ threads, people have asked
whether the Standard guarantees that the deallocation function
will be called in a delete-expression if the destructor throws
an exception. Most/all people have expressed the opinion that
the deallocation function must be called in this case, although
no one has been able to cite wording in the Standard supporting
that view.

The delete-expression will call a deallocation function
(3.7.4.2 [basic.stc.dynamic.deallocation])
[Note: The deallocation function is called regardless of
whether the destructor for the object or some element of the array
throws an exception. ]

442.
Incorrect use of null pointer constant in description of delete operator

After some discussion in comp.lang.c++.moderated we came to the conclusion
that there seems to be a defect in
5.3.5 [expr.delete]/4, which says:

The cast-expression in a delete-expression shall be evaluated exactly once.
If the delete-expression calls the implementation deallocation function
(3.7.3.2), and if the operand of the delete expression is not the null
pointer constant, the deallocation function will deallocate the storage
referenced by the pointer thus rendering the pointer invalid. [Note: the
value of a pointer that refers to deallocated storage is indeterminate. ]

In the second sentence, the term "null pointer constant" should be changed
to "null pointer". In its present form, the passage claims that the
deallocation function will deallocate the storage refered to by a null
pointer that did not come from a null pointer constant in the delete
expression. Besides, how can the null pointer constant be the operand of a
delete expression, as "delete 0" is an error because delete requires a
pointer type or a class type having a single conversion function to a
pointer type?

If the delete-expression calls the implementation deallocation
function (3.7.4.2 [basic.stc.dynamic.deallocation]), and if
the value of the operand of
the delete expression is not thea null
pointer constant, the deallocation function will deallocate the
storage referenced by the pointer thus rendering the pointer invalid.

Notes from October 2004 meeting:

This wording is superseded by, and this issue will be resolved
by, the resolution of issue 348.

659.
Alignment of function types

The specification for the alignof operator (5.3.6 [expr.alignof]) does not forbid function types as operands, although it
probably should.

Proposed resolution (March, 2008):

The issue, as described, is incorrect. The requirement in
5.3.6 [expr.alignof] is for “a complete object type,”
so a function type is already forbidden. However, the existing text
does have a problem in this requirement in that it does not allow a
reference type, as anticipated by paragraph 3. Consequently, the
proposal is to change 5.3.6 [expr.alignof] paragraph 1 as
indicated:

An alignof expression yields the alignment requirement of its operand
type. The operand shall be a type-id representing a complete object
type or a reference to a complete object type.

520.
Old-style casts between incomplete class types

The operand of a cast using the cast notation can be an rvalue of type
“pointer to incomplete class type”. The destination type
of a cast using the cast notation can be “pointer to incomplete
class type”. In such cases, even if there is a inheritance
relationship between the source and destination classes, whether the
static_cast or reinterpret_cast interpretation is
used is unspecified.

It's not entirely clear how a compiler can
choose static_cast as 5.4 [expr.cast] paragraph 6
seems to allow. I believe the intent of 5.4 [expr.cast]
paragraph 6 is to force the use of reinterpret_cast when
either are incomplete class types and static_cast iff the
compiler knows both types and there is a non-ambiguous
hierarchy-traversal between that cast (or maybe not, core issue 242 talks about this). I cannot see any
other interpretation because it isn't intuitive, every compiler I've
tried agrees with me, and neither standard pointer conversions
(4.10 [conv.ptr] paragraph 3) nor static_cast
(5.2.9 [expr.static.cast] paragraph 5) talk about incomplete
class types. If the committee agrees with me, I would like to see
4.10 [conv.ptr] paragraph 3 and 5.2.9 [expr.static.cast] paragraph 5 explicitly disallow incomplete class
types and the wording of 5.4 [expr.cast] paragraph 6
changed to not allow any other interpretation.

Proposed resolution (April, 2006):

Change 5.4 [expr.cast] paragraph 6 as indicated:

The operand of a cast using the cast notation can be an rvalue of type
“pointer to incomplete class type.” The destination type
of a cast using the cast notation can be “pointer to incomplete
class type.” In such cases, even if there is a inheritance
relationship between the source and destination classes, whether
the static_cast or reinterpret_cast interpretation
is used is unspecified.If both the operand and destination types
are class types and one or both are incomplete, it is unspecified
whether the static_cast or the reinterpret_cast
interpretation is used, even if there is an inheritance relationship
between the two classes. [Note: For example, if the classes
were defined later in the translation unit, a multi-pass compiler
would be permitted to interpret a cast between pointers to the classes
as if the class types were complete at that point. —end
note]

614.
Results of integer / and %

[Voted into the WP at the September, 2008 meeting as part of
paper N2757.]

The current Standard leaves it implementation-defined whether
integer division rounds the result toward 0 or toward negative
infinity and thus whether the result of % may be negative.
C99, apparently reflecting (nearly?) unanimous hardware practice, has
adopted the rule that integer division rounds toward 0, thus requiring
that the result of -1 % 5 be -1. Should the C++
Standard follow suit?

On a related note, does INT_MIN % -1 invoke undefined
behavior? The % operator is defined in terms of the
/ operator, and INT_MIN / -1 overflows, which by
5 [expr] paragraph 5 causes undefined behavior;
however, that is not the “result” of the %
operation, so it's not clear. The wording of 5.6 [expr.mul]
paragraph 4 appears to allow % to cause undefined behavior
only when the second operand is 0.

Proposed resolution (August, 2008):

Change 5.6 [expr.mul] paragraph 4 as follows:

The binary / operator yields the quotient, and the
binary % operator yields the remainder from the division
of the first expression by the second. If the second operand of
/ or % is zero the behavior is undefined;
otherwise (a/b)*b + a%b is equal to a. If both
operands are nonnegative then the remainder is nonnegative; if
not, the sign of the remainder is
implementation-defined. [Footnote: According to work
underway toward the revision of ISO C, the preferred algorithm
for integer division follows the rules defined in the ISO Fortran
standard, ISO/IEC 1539:1991, in which the quotient is always
rounded toward zero. —end footnote]. For
integral operands, the / operator yields the
algebraic quotient with any fractional part discarded;
[Footnote: This is often called “truncation towards
zero.” —end footnote] if the quotient
a/b is representable in the type of the result,
(a/b)*b + a%b is equal to a.

446.
Does an lvalue-to-rvalue conversion on the "?" operator produce a temporary?

The problem occurs when the value of the operator is determined to
be an rvalue, the selected argument is an lvalue, the type is a class
type and a non-const member is invoked on the modifiable rvalue result.

The types of the second and third operands are the same and
one is an rvalue. Nothing changes until p6 where an lvalue to
rvalue conversion is performed on the third operand.
12.2 [class.temporary] states that an lvalue to rvalue
conversion produces a temporary and there is nothing to remove
it. It seems clear that the assertion must pass, yet most
implementations fail.

There seems to be a defect in p3 b2 b1. First, the conditions to get
here and pass the test.

If E1 and E2 have class type, and the underlying class types are the
same or one is a base class of the other: E1 can be converted to
match E2 if the class of T2 is the same type as, or a base class of,
the class of T1, and the cv-qualification of T2 is the same
cv-qualification as, or a greater cv-qualification than, the
cv-qualification of T1.

If both E1 and E2 are lvalues, passing the conditions here also passes
the conditions for p3 b1. Thus, at least one is an rvalue. The case of
two rvalues is not interesting and the action is covered by the case
when E1 is an rvalue.

(0 ? D(13) : b1).inc();
assert(b1.v == 42);

E1 is changed to an rvalue of type T2 that still refers to the
original source class object (or the appropriate subobject thereof).
[Note: that is, no copy is made. ]

Having changed the rvalue to base type, we are back to the above case
where an lvalue to rvalue conversion is required on the third operand
at p6. Again, most implementations fail.

The remaining case, E1 an lvalue and E2 an rvalue, is the defect.

D d1(42);
(0 ? B(13) : d1).inc();
assert(d1.v == 42);

The above quote states that an lvalue of type T1 is changed to an rvalue
of type T2 without creating a temporary. This is in contradiction to
everything else in the standard about lvalue to rvalue conversions.
Most implementations pass in spite of the defect.

The usual accessible and unambiguous is missing from the base class.

There seems to be two possible solutions. Following other temporary
creations would produce a temporary rvalue of type T1 and change it
to an rvalue of type T2. Keeping the no copy aspect of this bullet
intact would change the lvalue of type T1 to an lvalue of type T2.
In this case the lvalue to rvalue conversion would happen in p6 as
usual.

Suggested wording for p3 b2 b1

The base part:

If E1 and E2 have class type, and the underlying class types are the
same or one is a base class of the other: E1 can be converted to match
E2 if the class of T2 is the same type as, or an accessible and
unambiguous base class of, the class of T1, and the cv-qualification
of T2 is the same cv-qualification as, or a greater cv-qualification
than, the cv-qualification of T1. If the conversion is applied:

The same type temporary version:

If E1 is an lvalue, an lvalue to rvalue conversion is applied. The
resulting or original rvalue is changed to an rvalue of type T2 that
refers to the same class object (or the appropriate subobject
thereof). [Note: that is, no copy is made in changing the type of
the rvalue. ]

The never copy version:

The lvalue(rvalue) E1 is changed to an lvalue(rvalue) of type T2
that refers to the original class object (or the appropriate
subobject thereof). [Note: that is, no copy is made. ]

The test case was posted to clc++m and results for implementations
were reported.

I see no defect with regards to lvalue to rvalue conversions; however,
there seems to be disagreement about what it means by implementers.
It may not be surprising because 5.16 and passing a POD struct to an
ellipsis are the only places where an lvalue to rvalue conversion
applies to a class type. Most lvalue to rvalue conversions are on
basic types as operands of builtin operators.

Notes from the March 2004 meeting:

We decided all "?" operators that return a class rvalue should
copy the second or third operand to a temporary. See
issue 86.

Proposed resolution (October 2004):

Change 5.16 [expr.cond] paragraph 3 bullet 2
sub-bullet 1 as follows:

if E1 and E2 have class type, and the
underlying class types are the same or one is a base class of the
other: E1 can be converted to match E2 if the
class of T2 is the same type as, or a base class of, the
class of T1, and the cv-qualification of T2 is
the same cv-qualification as, or a greater cv-qualification than,
the cv-qualification of T1. If the conversion is
applied, E1 is changed to an rvalue of type T2that still refers to the original source class object (or the
appropriate subobject thereof). [Note: that is, no copy is
made. —end note]by copy-initializing a
temporary of type T2 from E1 and using that
temporary as the converted operand.

Change 5.16 [expr.cond] paragraph 6 bullet 1 as
follows:

The second and third operands have the same type; the result is
of that type. If the operands have class type, the result is an
rvalue temporary of the result type, which is copy-initialized
from either the second operand or the third operand depending on
the value of the first operand.

Change 4.1 [conv.lval] paragraph 2 as follows:

The value contained in the object indicated by the lvalue is
the rvalue result. When an lvalue-to-rvalue conversion occurs
within the operand of sizeof (5.3.3 [expr.sizeof]) the value contained in the referenced object is
not accessed, since that operator does not evaluate its operand.
Otherwise, if the lvalue has a class type, the conversion
copy-initializes a temporary of type T from the lvalue
and the result of the conversion is an rvalue for the temporary.
Otherwise, the value contained in the object indicated by the
lvalue is the rvalue result.

5.19 [expr.const] paragraph 1 implies that some kinds of
nonconstant expressions are allowed inside a sizeof in
a constant expression, but it's not clear that this was intended
to extend all the way to things like overload resolution.
Allowing such things has some hidden
costs. For example, name mangling has to be able to represent all
operators, including calls, and not just the operators that can appear
in constant expressions.

If complex expressions are
indeed allowed, it should be because of an explicit
committee decision rather than because of some looseness in this
section of the standard.

Notes from the 4/02 meeting:

Any argument for restricting such expressions must involve a
cost/benefit ratio: a restriction would be palatable only if it
causes minimum hardship for users and allows a substantial
reduction in implementation cost. If we propose a restriction,
it must be one that library writers can live with.

Lots of these cases fail with current compilers, so there can't
be a lot of existing code using them. We plan to find out what
cases there are in libraries like Loki and Boost.

We noted that in many cases one can move the code into a class
to get the same result. The implementation problem comes up
when the expression-in-sizeof is in a template deduction
context or part of a template signature. The problem cases
are ones where an error causes deduction to fail, as opposed
to contexts where an error causes a diagnostic. The latter
contexts are easier to handle; however, there are situations
where "fail deduction" may be the desired behavior.

The core working group liked the idea of a restriction that
says that expressions inside sizeof in template signature contexts
must be otherwise valid as nontype template argument expressions
(i.e., integer operations only, limited casts). This of
course is subject to whether users can live with that restriction.
This topic was brought up in full committee, but there was
limited feedback from other groups.

It was also noted that if typeof (whatever it is called)
is added, there may be a similar issue there.

as a valid declaration (if the proposal is accepted). If [the
restrictions in the April, 2003 note] really applied to decltype, the
declaration above would be invalid. AFAICT every non-trivial use of
decltype in a template function declaration would be invalid. And for
me this would render my favorite proposal useless.

Jaakko Jarvi: Just reinforcing that this is important and
hope for insights. The topic is discussed a bit on page 10 of the
latest revision of the proposal (N1705). Here's a quote from the
proposal:

However, it is crucial that no restrictions are placed on what kinds
of expressions are allowed inside decltype, and
therefore also inside sizeof. We suggest that issue 339
is resolved to require the compiler to fail deduction (apply the
SFINAE principle), and not produce an error, for as large set of
invalid expressions in operands of sizeof or
decltype as is possible to comfortably implement. We wish
that implementors aid in classifying the kinds of expressions that
should produce errors, and the kinds that should lead to failure of
deduction.

Notes from the April, 2007 meeting:

The CWG is pursuing a compromise proposal, to which the EWG has
tentatively agreed, which would allow arbitrary expressions in the
return types of function templates but which would restrict the
expressions that participate in the function signature (and thus in
overload resolution) to those that can be used as non-type
template arguments. During deduction and overload resolution,
these complex return types would be ignored; that is, there would
be no substitution of the deduced template arguments into the return
type at this point. If such a function were selected by overload
resolution, however, a substitution failure in the return type would
produce a diagnostic rather than a deduction failure.

This approach works when doing overload resolution in the context
of a function call, but additional tricks (still being defined) are
needed in other contexts such as friend function declaration matching
and taking the address of a function, in which the return type does
play a part.

Notes from the July, 2007 meeting:

The problem is whether arbitrary expressions (for example,
ones that include overload resolution) are allowed in template
deduction contexts, and, if so, which expression errors are
SFINAE failures and which are hard errors.

This issue deals with arbitrary expressions inside sizeof in
deduction contexts. That's a fringe case right now (most
compilers don't accept them). decltype makes the problem worse,
because the standard use case is one that involves overload
resolution. Generalized constant expressions make it worse yet,
because they allow overload resolution and class types to show up
in any constant expression in a deduction context.

Why is this an issue? Why don't we just say everything is
allowed and be done with it?

Because it's hard to implement the general case. Template
deduction/substitution has historically used a simplified model
of semantic checking, i.e., the SFINAE rules (which are mostly
about types), instead of full semantic checking. This limited
semantic checking is typically done by completely separate code
from the code for “normal” expression checking, and
it's not easy to extend it to the general
case. “Speculative compilation” sounds like an easy
way out, but in practice compilers can't do that.

Because it affects name mangling and therefore the ABI.

Because we need to figure out what to say and how to say it
in the Standard.

At the April, 2007 meeting, we were headed toward a solution
that imposed a restriction on expressions in deduction contexts,
but such a restriction seems to really hamper uses of constexpr
functions. So we're now proposing that fully general expressions
be allowed, and that most errors in such expressions be treated
as SFINAE failures rather than errors.

One issue with writing Standard wording for that is how to
define “most.” There's a continuum of errors, some
errors being clearly SFINAE failures, and some clearly
“real” errors, with lots of unclear cases in
between. We decided it's easier to write the definition by
listing the errors that are not treated as SFINAE failures, and
the list we came up with is as follows:

errors that occur while processing some entity external to
the expression, e.g., an instantiation of a template or the
generation of the definition of an implicitly-declared copy
constructor

errors due to implementation limits

errors due to access violations (this is a judgment call,
but the philosophy of access has always been that it doesn't
affect visibility)

Everything else produces a SFINAE failure rather than a hard
error.

There was broad consensus that this felt like a good solution,
but that feeling was mixed with trepidation on several
fronts:

The implementation cost is quite significant, at least for
EDG and Microsoft (under GCC, it may be easier). It involves
moving around a large amount of code. This may delay
implementation and introduce bugs in compilers.

While it seems upward compatible with C++03, it's possible it
will break existing code. Any big change in template processing
has a pretty good chance of breaking something.

Since there is no implementation, we don't really know how it
will work in the real world.

We will be producing wording for the Working Draft for the
October, 2007 meeting.

366.
String literal allowed in integral constant expression?

is well-formed, since it is an integral constant expression.
Since that may not be obvious, here is why:

5.19 [expr.const] paragraph 1 says that an integral constant
expression may involve literals (2.14 [lex.literal]);
"Hello, world" is a literal. It restricts
operators to not use certain type conversions; this expression does
not use type conversions. It further disallows functions, class
objects, pointers, ... - this expression is none of those, since it
is an array.

However, 16.1 [cpp.cond] paragraph 6 does not explain what
to do with this if-group, since
the expression evaluates neither to false(zero) nor true(non-zero).

Proposed resolution (October 2002):

Change the beginning of the second sentence of
5.19 [expr.const] paragraph 1 which currently reads

An integral constant-expression can involve only literals
(2.14 [lex.literal]), ...

According to 5.19 [expr.const], this appears to be an
integral constant expression:
it is a conditional expression, involves only literals, and no
assignment, increment, decrement, function-call, or comma operators.
However, if this is well-formed, the standard gives no meaning to
this declaration, since the array bound (8.3.4 [dcl.array]
paragraph 1) cannot be computed.

I believe the defect is that throw expressions should also be banned
from constant expressions.

Notes from October 2002 meeting:

We should also check on new and delete.

Notes from the April, 2005 meeting:

Although it could be argued that all three of these operators
potentially involve function calls — throw
to std::terminate, new and delete to the
corresponding allocation and deallocation functions — and thus
would already be excluded from constant expressions, this reasoning
was considered to be too subtle to allow closing the issue with no
change. A modification that explicitly clarifies the status of these
operators will be drafted.

Proposed resolution (October, 2005):

Change the last sentence of 5.19 [expr.const] as indicated:

In particular, except in sizeof expressions, functions, class
objects, pointers, or references shall not be used, and assignment,
increment, decrement, function-callfunction call (including
new-expressions and delete-expressions), or comma
operators, or throw-expressions shall not be used.

The proposed resolution could potentially be read as saying that
the prohibited operations and operators would be permitted in integral
constant expressions that are non-type template-arguments. John
Spicer is investigating an alternate approach, to say that expressions
in non-type template arguments are not part of the expression in which
the template-id appears (in contrast to the operand of
sizeof, which is part of the containing expression).

Additional note (May, 2008):

This issue is resolved by the rewrite of 5.19 [expr.const]
that was done in conjunction with the constexpr proposal, paper
N2235.

684.
Constant expressions involving the address of an automatic variable

Add the following bullet to the list in 5.19 [expr.const]
paragraph 2:

an id-expression that refers to a variable with
automatic storage duration unless a permitted lvalue-to-rvalue
conversion is applied (see above)

Proposed resolution (June, 2008):

Change 3.6.2 [basic.start.init] paragraph 1 as
follows:

Objects with static storage duration (3.7.1 [basic.stc.static]) or
thread storage duration (3.7.2) shall be zero-initialized
(8.5 [dcl.init]) before any other initialization takes
place. A reference with static or thread storage duration and an
object of trivial or literal type with static or thread storage
duration can be initialized with a constant expression (5.19 [expr.const]); this is called constant initialization.Constant initialization is performed:

if an object of trivial or literal type with static or
thread storage duration is initialized with a constant expression
(5.19 [expr.const]), or

if a reference with static or thread storage duration is
initialized with a constant expression that is not an lvalue
designating an object with thread or automatic storage
duration.

Together, zero-initialization and constant
initialization...

Add the following in 5.19 [expr.const] paragraph
2:

an lvalue-to-rvalue conversion (4.1) unless it is applied
to...

an array-to-pointer conversion (4.2 [conv.array]) that
is applied to an lvalue that designates an object with thread or
automatic storage duration

a unary operator & (5.3.1 [expr.unary.op])
that is applied to an lvalue that designates an object with thread or
automatic storage duration

an id-expression that refers to a variable or data
member of reference type;

...

(Note: the change to 3.6.2 [basic.start.init] paragraph 1
needs to be reconciled with the conflicting change in
issue 688.)

276.
Order of destruction of parameters and temporaries

On exit from a scope (however accomplished), destructors (12.4 [class.dtor]) are called for all constructed objects with automatic
storage duration (3.7.3 [basic.stc.auto]) (named objects or
temporaries) that are declared in that scope, in the reverse order of
their declaration.

This wording is problematic for temporaries and for parameters.
First, temporaries are not "declared," so this requirement does not
apply to them, in spite of the assertion in the quoted text that it
does.

Second, although the parameters of a function are declared
in the called function, they are constructed and destroyed in the
calling context, and the order of evaluation of the arguments is
unspecified (cf 5.2.2 [expr.call] paragraphs 4 and 8).
The order of destruction of the parameters might, therefore, be
different from the reverse order of their declaration.

Notes from 04/01 meeting:

Any resolution of this issue should be careful not to introduce
requirements that are redundant or in conflict with those of other
parts of the IS. This is especially true in light of the pending
issues with respect to the destruction of temporaries (see issues
86, 124,
199, and 201).
If possible, the wording of a resolution should simply reference
the relevant sections.

It was also noted that the temporary for a return value is
also destroyed "out of order."

Note that issue 378 picks a nit
with the wording of this same paragraph.

Proposed Resolution (November, 2006):

Change 6.6 [stmt.jump] paragraph 2 as follows:

On exit from a scope (however accomplished), destructors
(12.4 [class.dtor]) are called for all constructed objects
with automatic storage duration (3.7.3 [basic.stc.auto]) (named
objects or temporaries) that are declared in that scope, in the
reverse order of their declaration.variables with automatic
storage duration (3.7.3 [basic.stc.auto]) that have been
constructed in that scope are destroyed in the reverse order of their
construction. [Note: For temporaries, see 12.2 [class.temporary].
—end note] Transfer out of a loop...

378.
Wording that says temporaries are declared

On exit from a scope (however accomplished), destructors
(12.4 [class.dtor])
are called for all constructed objects with automatic storage
duration (3.7.3 [basic.stc.auto])
(named objects or temporaries) that are declared
in that scope.

It refers to objects "that are declared" but the text in parenthesis
also mentions temporaries, which cannot be declared. I think that text
should be removed.

Bjarne Stroustrup:
... and [the ARM] disallows declaring a function inline after it
has been called.

This may still be a good resolution.

Steve Clamage:
But the situation in the ARM is the reverse: Declare a function
inline, and define it later (with no intervening call). That's
a long-standing rule in C++, and allows you to write member
function definitions outside the class.

In my example, the compiler could reasonably process the entire
function as out-of-line, and not discover the inline declaration
until it was too late to save the information necessary for inline
generation. The equivalent of another compiler pass would be needed
to handle this situation.

Bjarne Stroustrup:
I see, and I think your argument it conclusive.

Steve Clamage:
I'd like to open a core issue on this point, and I recommend wording
along the lines of: "A function defined without an inline specifier
shall not be followed by a declaration having an inline specifier."

I'd still like to allow the common idiom

class T {
int f();
};
inline int T::f() { ... }

Martin Sebor:
Since the inline keyword is just a hint to the compiler, I don't see
any harm in allowing the construct. Your hypothetical compiler can
simply ignore the inline on the second declaration. On the other hand,
I feel that adding another special rule will unnecessarily complicate
the language.

Steve Clamage:
The inline specifier is more than a hint. You can have multiple
definitions of inline functions, but only one definition of a
function not declared inline. In particular, suppose the above
example were in a header file, and included multiple times in
a program.

Proposed resolution (October, 2004):

Add the indicated words to 7.1.2 [dcl.fct.spec]
paragraph 4:

An inline function shall be defined in every translation unit in
which it is used and shall have exactly the same definition in
every case (3.2 [basic.def.odr]). [Note: a call to
the inline function may be encountered before its definition
appears in the translation unit. —end note] If the
definition of a function appears in a translation unit before its
first declaration as inline, the program is ill-formed. If a
function with external linkage is declared inline in one
translation unit...

396.
Misleading note regarding use of auto for disambiguation

BTW, I noticed that the following note in 7.1.1 [dcl.stc]
paragraph 2 doesn't seem to have
made it onto the issues list or into the TR:

[Note: hence, the auto specifier is almost always redundant and not
often used; one use of auto is to distinguish a declaration-statement
from an expression-statement (stmt.ambig) explicitly. --- end note]

I thought that this was well known to be incorrect, because using auto
does not disambiguate this. Writing:

auto int f();

is still a declaration of a function f, just now with an error since the
function's return type may not use an auto storage class specifier. I
suppose an error is an improvement over a silent ambiguity going the
wrong way, but it's still not a solution for the user who wants to
express the other in a compilable way.

Proposed resolution: Replace that note with the following note:

[Note: hence, the auto specifier is always redundant and not often
used. --- end note]

John Spicer:
I support the proposed change, but I think the disambiguation case is not the
one that you describe. An example of the supposed disambiguation is:

cfront would take "int(i)" as a cast of ::i, so the auto would force what it
would otherwise treat as a statement to be considered a declaration
(cfront 3.0 warned that this would change in the future).

In a conforming compiler the auto is always redundant (as you say) because
anything that could be considered a valid declaration should be treated as
one.

Proposed resolution (April 2003):

Replace 7.1.1 [dcl.stc] paragraph 2

[Note: hence, the auto specifier
is almost always redundant and not often used;
one use of auto is to distinguish
a declaration-statement from
an expression-statement (6.8 [stmt.ambig])
explicitly. --- end note]

with

[Note: hence, the auto specifier
is always redundant and not often used.
One use of auto is to distinguish
a declaration-statement from an expression-statement
explicitly
rather than relying on the disambiguation rules
(6.8 [stmt.ambig]),
which may aid readers.
--- end note]

397.
Same address for string literals from default arguments in inline functions?

Are string literals from default arguments
used in extern inlines supposed to have the same addresses across
all translation units?

void f(const char* = "s")
inline g() {
f();
}

Must the "s" strings be the same in all copies of the
inline function?

Steve Adamczyk:
The totality of the standard's wisdom on this topic is
(7.1.2 [dcl.fct.spec] paragraph 4):

A string literal in an extern inline function is the same object
in different translation units.

I'd hazard a guess that a literal in a default argument expression
is not "in" the extern inline function (it doesn't appear in the
tokens of the function), and therefore it need not be
the same in different translation units.

I don't know that users would expect such strings to have
the same address, and an equally valid (and incompatible) expectation
would be that the same string literal would be used for every expansion of
a given default argument in a single translation unit.

Notes from April 2003 meeting:

The core working group feels that the address of a string literal
should be guaranteed to be the same only if it actually appears
textually within the body of the inline function. So a string in
a default argument expression
in a block extern declaration inside the body of a function would
be the same in all instances of the function. On the other
hand, a string in a default argument expression in the header of
the function (i.e., outside of the body) would not be the same.

Proposed resolution (April 2003):

Change the last sentence and add the note to the end of
7.1.2 [dcl.fct.spec] paragraph 4:

A string literal in the body of an extern inline
function is the same
object in different translation units.
[Note: A string literal that is encountered only in the context of a
function call (in the default argument expression of the called function),
is not “in” the extern inline function.]

Notes from October 2003 meeting:

We discussed ctor-initializer lists and decided that they are
also part of the body. We've asked Clark Nelson to work on
syntax changes to give us a syntax term for the body of a
function so we can refer to it here. See also
issue 452, which could use this term.

(October, 2005: moved to “review” status in concert with
issue 452. With that resolution, the wording
above needs no further changes.)

Proposed resolution (April, 2006):

Change the last sentence and add the note to the end of
7.1.2 [dcl.fct.spec] paragraph 4:

A string literal in the body of an extern inline
function is the same object in different translation units.
[Note: A string literal appearing in a default argument
expression is not considered to be “in the body”
of an inline function merely by virtue of the expression’s use in a
function call from that inline function. —end note]

477.
Can virtual appear in a friend declaration?

I couldn't find wording that makes it invalid to say
friend virtual... The closest seems to be
7.1.2 [dcl.fct.spec] paragraph 5, which says:

The virtual specifier shall only be used in declarations
of nonstatic class member functions that appear within a
member-specification of a class definition; see
10.3 [class.virtual].

I don't think that excludes a friend declaration (which is a
valid member-specification by 9.2 [class.mem]).

John Spicer: I agree that virtual should not be allowed
on friend declarations. I think the wording in 7.1.2 [dcl.fct.spec] is intended to be the declaration of a
function within its class, although I think the wording should be
improved to make it clearer.

Proposed resolution (October, 2005):

Change 7.1.2 [dcl.fct.spec] paragraphs 5-6 as indicated:

The virtual specifier shall only be
used only in declarationsthe initial declaration
of a non-static class member functions that appear within a
member-specification of a class definitionfunction;
see 10.3 [class.virtual].

The explicit specifier shall be used only
in declarationsthe declaration of constructorsa constructor within aits class definition; see
12.3.1 [class.conv.ctor].

647.
Non-constexpr instances of constexpr constructor templates

If the instantiated template specialization of a constexpr function
template would fail to satisfy the requirements for a constexpr
function, the constexpr specifier is ignored and the
specialization is not a constexpr function.

One would expect to see a similar provision for an instantiated
constructor template (because the requirements for a constexpr function
[paragraph 3] are different from the requirements for a constexpr
constructor [paragraph 4]), but there is none; constexpr constructor
templates are not mentioned.

Suggested resolution:

Change the wording of 7.1.5 [dcl.constexpr] paragraph 5 as
indicated:

If the instantiated template specialization of a constexpr function
template would fail to satisfy the requirements for a constexpr
function or constexpr constructor, as appropriate to the function
template, the constexpr specifier is ignored and the
specialization is not a constexpr function or constexpr
constructor.

Proposed resolution (June, 2008):

[Drafting note: This resolution goes beyond the problem
described in the issue discussion, which is one aspect of the general
failure of the existing wording to deal consistently with the
distinctions between constexpr functions and constexpr
constructors. The wording below attempts to rectify that problem
systematically.]

Change 7.1.5 [dcl.constexpr] paragraph 2 as follows:

A constexpr specifier used in a function declarationthe declaration of a function that is not a constructor
declares that function to be a constexpr function. Similarly, a
constexpr specifier used in a constructor declaration
declares that constructor to be a constexpr
constructor. Constexpr functions and constexpr constructors are
implicitly inline (7.1.2 [dcl.fct.spec]). A constexpr
function shall not be virtual (10.3).

Change 7.1.5 [dcl.constexpr] paragraph 3 as follows:

The definition of a constexpr function shall satisfy the following
constraints:

it shall not be virtual (10.3 [class.virtual])

its return type shall be a literal type

each of its parameter types shall be a literal type

its function-body shall be a compound-statement of the form

{ returnexpression; }

where expression is a potential constant expression
(5.19 [expr.const])

every implicit conversion used in converting expression
to the function return type (8.5 [dcl.init]) shall be one of
those allowed in a constant expression (5.19 [expr.const]).

[Example:...

Change 7.1.5 [dcl.constexpr] paragraph 4 as follows:

The definition of a constexpr constructor shall satisfy the
following constraints:

each of its parameter types shall be a literal
type

its function-body shall not be a
function-try-block

the compound-statement of its function-body shall
be empty

every non-static data member and base class sub-object shall be
initialized (12.6.2 [class.base.init])

every constructor involved in initializing non-static data
members and base class sub-objects invoked by a
mem-initializer shall be a constexpr constructor invoked
with potential constant expression arguments, if any.

every constructor argument and full-expression in a
mem-initializer shall be a potential constant
expression

every implicit conversion used in converting a constructor
argument to the corresponding parameter type and converting a
full-expression to the corresponding member type shall be one of those
allowed in a constant expression.

A trivial copy constructor is also a constexpr
constructor. [Example: ...

Change 7.1.5 [dcl.constexpr] paragraph 5 as follows:

If the instantiated template specialization of a constexpr function
template would fail to satisfy the requirements for a constexpr
function or constexpr constructor, the constexpr
specifier is ignored and the specialization is not a constexpr
function.

Change 7.1.5 [dcl.constexpr] paragraph 6 as follows:

A constexpr specifier used infor a non-static
member function definitionthat is not a constructor
declares that member function to be const (9.3.1 [class.mfct.non-static]). [Note: ...

648.
Constant expressions in constexpr initializers

The current wording of 7.1.5 [dcl.constexpr] paragraph 7
seems not quite correct. It reads,

A constexpr specifier used in an object declaration declares
the object as const. Such an object shall be initialized, and
every expression that appears in its initializer (8.5 [dcl.init]) shall be a constant expression.

The phrase “every expression” is intended to cover
multiple arguments to a constexpr constructor and multiple expressions
in an aggregate initializer. However, it could be read (incorrectly)
as saying that non-constant expressions cannot appear as subexpressions
in such initializers, even in places where they do not render the
full-expression non-constant (i.e., as unevaluated operands and in the
unselected branches of &&, ||, and
?:). Perhaps this problem could be remedied by replacing
“every expression” with “every
full-expression?”

Proposed resolution (June, 2008):

Change 7.1.5 [dcl.constexpr] paragraph 7 as follows:

A constexpr specifier used in an object declaration declares
the object as const. Such an object shall be initialized,
and every expression that appears in its initializer (8.5)initialized. If it is initialized by a constructor call, the
constructor shall be a constexpr constructor and every argument to the
constructor shall be a constant expression. Otherwise, every
full-expression that appears in its initializer shall be a
constant expression. Every implicit conversion used...

283.
Template type-parameters are not syntactically type-names

A type-parameter defines its identifier to be a
type-name (if declared with class or
typename)

the grammar in 7.1.6.2 [dcl.type.simple] paragraph 1
says that a type-name is either a class-name, an
enum-name, or a typedef-name. The identifier
in a template type-parameter is none of those. One
possibility might be to equate the identifier with a
typedef-name instead of directly with a type-name,
which would have the advantage of not requiring parallel treatment
of the two in situations where they are treated the same (e.g.,
in elaborated-type-specifiers, see
issue 245). See also
issue 215.

Proposed resolution (Clark Nelson, March 2002):

In 14.1 [temp.param] paragraph 3,
change "A type-parameter defines its identifier to be a
type-name"
to "A type-parameter defines its identifier
to be a typedef-name"

In 7.1.6.3 [dcl.type.elab] paragraph 2,
change "If the identifier resolves to a typedef-name or a template
type-parameter"
to "If the identifier resolves to a typedef-name".

This has been consolidated with the edits for some other
issues. See N1376=02-0034.

516.
Use of signed in bit-field declarations

It is implementation-defined whether bit-fields and objects
of char type are represented as signed or unsigned
quantities. The signed specifier forces char
objects and bit-fields to be signed; it is redundant with other
integral types.

The last sentence in that quote is misleading w.r.t. bit-fields. The
first sentence in that quote is correct but incomplete.

Proposed fix: change the two sentences to read:

It is implementation-defined whether objects of char type are
represented as signed or unsigned quantities. The signed
specifier forces char objects signed; it is redundant with
other integral types except when declaring bit-fields (9.6 [class.bit]).

Proposed resolution (October, 2005):

Change 7.1.6.2 [dcl.type.simple] paragraph 3 as indicated:

When multiple simple-type-specifiers are allowed, they can be
freely intermixed with other decl-specifiers in any
order. [Note: It is implementation-defined whether
bit-fields and objects of char type and certain
bit-fields (9.6 [class.bit]) are represented as signed
or unsigned quantities. The signed specifier
forces bit-fields andchar objects and
bit-fields to be signed; it is redundant with other integral
typesin other contexts. —end note]

otherwise, if e is a function call (5.2.2 [expr.call]) or an invocation of an overloaded operator
(parentheses around e are ignored), decltype(e) is
the return type of that function;

The reference to “that function” is imprecise; it is
not the actual function called at runtime but the statically chosen
function (ignoring covariant return types in virtual functions).

Also, the examples in this paragraph have errors:

The declaration of struct A should end with a
semicolon.

The lines of the form decltype(...); are ill-formed;
they need a declarator.

Proposed Resolution (October, 2007):

Change 7.1.6.2 [dcl.type.simple] paragraph 4 as follows:

The type denoted by decltype(e) is defined as follows:

if e is an id-expression or a class member
access (5.2.5 [expr.ref]), decltype(e) is the type
of the entity named by e. If there is no such entity, or
if e names a set of overloaded functions, the program is
ill-formed;

otherwise, if e is a function call (5.2.2 [expr.call]) or an invocation of an overloaded operator (parentheses
around e are ignored), decltype(e) is the return
type of thatthe statically chosen function;

otherwise, if e is an lvalue, decltype(e)
is T&, where T is the type of e;

otherwise, decltype(e) is the type
of e.

The operand of the decltype specifier is an unevaluated
operand (clause 5 [expr]).

629.
auto parsing ambiguity

[Voted into the WP at the February, 2008 meeting as paper
J16/08-0056 = WG21 N2546.]

We've found an interesting parsing ambiguity with the new meaning of
auto. Consider:

typedef int T;
void f() {
auto T = 42; // Valid or not?
}

The question here is whether T should be a type specifier or a
storage class? 7.1.6.4 [dcl.spec.auto] paragraph 1 says,

The autotype-specifier has two meanings depending on
the context of its use. In a decl-specifier-seq that contains
at least one type-specifier (in addition to auto) that
is not a cv-qualifier, the autotype-specifier
specifies that the object named in the declaration has automatic
storage duration.

In this case, T is a type-specifier, so the
declaration is ill-formed: there is no declarator-id. Many,
however, would like to see auto work “just like
int,” i.e., forcing T to be redeclared in
the inner scope. Concerns cited included hijacking of the name in
templates and inline function bodies over the course of time if a
program revision introduces a type with that name in the surrounding
context. Although it was pointed out that enclosing the name in
parentheses in the inner declaration would prevent any such
problems, this was viewed as unacceptably ugly.

Notes from the April, 2007 meeting:

The CWG wanted to avoid a rule like, “if auto can
be a type-specifier, it is” (similar to the existing
“if it can be a declaration, it is” rule) because of the
lookahead and backtracking difficulties such an approach would pose
for certain kinds of parsing techniques. It was noted that the
difficult lookahead cases all involve parentheses, which would not
be a problem if only the “=” form of initializer were
permitted in auto declarations; only very limited lookahead
is required in that case. It was also pointed out that the “if
it can be a type-specifier, it is” approach results in a
quiet change of meaning for cases like

typedef int T;
int n = 3;
void f() {
auto T(n);
}

This currently declares n to be an int variable
in the inner scope but would, under the full lookahead approach,
declare T to be a variable, quitely changing uses
of n inside f() to refer to the outer variable.

The consensus of the CWG was to pursue the change to require the
“=” form of initializer for auto.

Notes from the July, 2007 meeting:

See paper J16/07-0197 = WG21 N2337. There was no consensus
among the CWG for either of the approaches recommended in the
paper; additional input and direction is required.

172.
Unsigned int as underlying type of enum

According to 7.2 [dcl.enum]
paragraph 5,
the underlying type of an enum is an unspecified integral type,
which could potentially be unsigned int. The promotion
rules in 4.5 [conv.prom]
paragraph 2 say
that such an enumeration value used in an expression will be promoted
to unsigned int. This means that a conforming
implementation could give the value false for the
following code:

enum { zero };
-1 < zero; // might be false

This is counterintuitive. Perhaps the description of the underlying
type of an enumeration should say that an unsigned underlying type
can be used only if the values of the enumerators cannot be
represented in the corresponding signed type. This approach would
be consistent with the treatment of integral promotion of
bitfields (4.5 [conv.prom]
paragraph 3).

On a related note,
7.2 [dcl.enum]
paragraph 5 says,

the underlying type shall not be larger than int unless
the value of an enumerator cannot fit in an int or
unsigned int.

This specification does not allow for an enumeration like

enum { a = -1, b = UINT_MAX };

Since each enumerator can fit in an int
or unsigned int, the underlying type is required to be
no larger than int, even though there is no such type that
can represent all the enumerators.

Proposed resolution (04/01; obsolete, see below):

Change 7.2 [dcl.enum] paragraph 5 as follows:

It is implementation-defined which integral type is used as
the underlying type for an enumeration except that the
underlying type shall not be larger than int unless
the value of an enumerator cannot fit in an int
or unsigned intneither int nor
unsigned int can represent all the enumerator values.
Furthermore, the underlying type shall not be an unsigned
type if the corresponding signed type can represent all the
enumerator values.

It was noted that 4.5 [conv.prom] promotes unsigned
types smaller than int to (signed) int. The
signedness chosen by an implementation for small underlying types
is therefore unobservable, so the last sentence of the proposed
resolution above should apply only to int and larger
types. This observation also prompted discussion of an
alternative approach to resolving the issue, in which the
bmin and bmax of the enumeration
would determine the promoted type rather than the underlying type.

Proposed resolution (10/01):

Change 4.5 [conv.prom] paragraph 2 from

An rvalue of type wchar_t (3.9.1 [basic.fundamental])
or an enumeration type
(7.2 [dcl.enum]) can be converted to an rvalue of
the first of the following
types that can represent all the values of its underlying type:
int, unsigned int, long, or unsigned long.

to

An rvalue of type wchar_t (3.9.1 [basic.fundamental])
can be converted to an rvalue of the first of the following
types that can represent all the values of its underlying type:
int, unsigned int, long, or unsigned long.
An rvalue of an enumeration type (7.2 [dcl.enum])
can be converted to an rvalue of the first of the following
types that can represent all the values of the enumeration (i.e., the
values in the range bmin to bmax as
described in 7.2 [dcl.enum]):
int, unsigned int, long, or unsigned long.

660.
Unnamed scoped enumerations

The current specification of scoped enumerations does not appear
to forbid an example like the following, even though the enumerator
e cannot be used:

enum class { e };

This might be covered by 7 [dcl.dcl] paragraph 3,

In a simple-declaration, the
optional init-declarator-list can be omitted only when
declaring a class (clause 9 [class]) or enumeration
(7.2 [dcl.enum]), that is, when
the decl-specifier-seq contains either
a class-specifier, an elaborated-type-specifier with a
class-key (9.1 [class.name]), or
an enum-specifier. In these cases and whenever a
class-specifier or enum-specifier is present in the
decl-specifier-seq, the identifiers in these specifiers are
among the names being declared by the declaration
(as class-names, enum-names, or enumerators,
depending on the syntax). In such cases, and except for the
declaration of an unnamed bit-field (9.6 [class.bit]), the
decl-specifier-seq shall introduce one or more names into the
program, or shall redeclare a name introduced by a previous
declaration.

which, when combined with paragraph 2,

A declaration occurs in a scope (3.3 [basic.scope]); the scope
rules are summarized in 3.4 [basic.lookup]. A declaration that
declares a function or defines a class, namespace, template, or
function also has one or more scopes nested within it. These nested
scopes, in turn, can have declarations nested within them. Unless
otherwise stated, utterances in clause 7 [dcl.dcl] about
components in, of, or contained by a declaration or subcomponent
thereof refer only to those components of the declaration that
are not nested within scopes nested within the declaration.

appears to rule out the similar class definition,

struct { int m; };

However, a scoped enumeration is not listed in paragraph 2 among the
constructs containing a nested scope (although 3.3.8 [basic.scope.enum]
does describe “enumeration scope”); furthermore, an
enumerator-definition is not formally a “nested
declaration.” If unusable scoped enumeration definitions are to
be banned, these shortcomings in 7 [dcl.dcl] paragraph 2
must be addressed. (A note in 7.2 [dcl.enum] mentioning that
unnamed scoped enumerations are not allowed would also be helpful.)

Notes from the February, 2008 meeting:

The consensus was to require that the identifier be
present in an enum-specifier unless the enum-key is
enum.

Proposed resolution (June, 2008):

Change 7.2 [dcl.enum] paragraph 2 as follows:

...The enum-keys enum class and enum struct
are semantically equivalent; an enumeration type declared with one of
these is a scoped enumeration, and its enumerators are
scoped enumerators. The optional identifier shall not be
omitted in the declaration of a scoped enumeration. The
type-specifier-seq of an enum-base...

540.
Propagation of cv-qualifiers in reference-to-reference collapse

[Voted into the WP at the October, 2006 meeting as part of
paper J16/06-0188 = WG21 N2118.]

The resolution of issue 106 specifies
that an attempt to create a type “reference to cv1T,” where T is a typedef or template parameter
of the type “reference to cv2S,” actually
creates the type “reference to cv12S,”
where cv12 is the union of the two sets of cv-qualifiers.

One objection that has been raised to this resolution is that it
is inconsistent with the treatment of cv-qualification and references
specified in 8.3.2 [dcl.ref] paragraph 1, which says
that cv-qualifiers applied to a typedef or template argument that is
a reference type are ignored. For example:

In fact, however, these two declarations are quite different. In the
declaration of r1, const applies to a
“top-level” reference, while in the declaration of t2,
it occurs under a reference. In general, cv-qualifiers that appear under
a reference are preserved, even if the type appears in a context in which
top-level cv-qualification is removed, for example, in determining the
type of a function from parameter types (8.3.5 [dcl.fct]
paragraph 3) and in template argument deduction
(14.8.2.1 [temp.deduct.call] paragraph 2).

Another objection to the resolution is that type composition gives
different results in a single declaration than it does when separated
into two declarations. For example:

The initial motivation for the propagation of cv-qualification
during reference-to-reference collapse was to prevent inadvertent
loss of cv-qualifiers in contexts in which it could make a
difference. For example, if the resolution were changed to discard,
rather than propagate, embedded cv-qualification, overload
resolution could surprisingly select a non-const version of a member
function:

On the other hand, those who would like to see the resolution
changed to discard embedded cv-qualifiers observe that these examples
are too simple to be representative of real-world code. In general,
it is unrealistic to expect that a template written with non-reference
type parameters in mind will automatically work correctly with
reference type parameters as a result of applying the issue 106
resolution. Instead, template metaprogramming allows the template
author to choose explicitly whether cv-qualifiers are propagated or
dropped, according to the intended use of the template, and it is more
important to respect the reasonable intuition that a declaration
involving a template parameter will not change the type that the
parameter represents.

As a sample of real-world code, tr1::tuple was examined.
In both cases — the current resolution of issue 106 and one in
which embedded cv-qualifiers were dropped — some metaprogramming
was required to implement the intended interface, although the version
reflecting the revised resolution was somewhat simpler.

Notes from the October, 2005 meeting:

The consensus of the CWG was that the resolution of
issue 106 should be revised not to
propagate embedded cv-qualification.

Note (February, 2006):

The wording included in the rvalue-reference paper,
J16/06-0022 = WG21 N1952, incorporates changes intended to implement
the October, 2005 consensus of the CWG.

11.
How do the keywords typename/template interact with using-declarations?

When the rules for typename and the similar use of template
were decided, we chose to require that they be used at every reference.
The way to avoid typename at every use is to declare a typedef;
then the typedef name itself is known to be a type. For using-declarations,
we decided that they do not introduce new declarations but rather are aliases
for existing declarations, like symbolic links. This makes it unclear whether
the declaration "X c;" above should be well-formed, because there
is no new name declared so there is no declaration with a "this is a type"
attribute. (The same problem would occur with the template keyword
when a member template of a dependent class is used). I think these are
the main options:

Continue to allow typename in using-declarations, and template
(for member templates) too. Attach the "is a type" or "is a template"
attribute to the placeholder name which the using-declaration "declares"

Disallow typename and template in using-declarations
(just as class-keys are disallowed now). Allow typename
and template before unqualified names which refer to dependent
qualified names through using-declarations.

Document that this is broken.

Suggested Resolution:

The core WG already resolved this issue according to (1), but the wording
does not seem to have been added to the standard. New wording needs to
be drafted.

Issue 2:

Either way, one more point needs clarification. If the first option
is adopted:

When "g" is instantiated, the two declarations of X are compatible
(7.3.3 [namespace.udecl]
paragraph 10).
But there is no way to know this when the definition of "g" is
compiled. I think this case should be ill-formed under the first option.
(It cannot happen under the second option.) If the second option is adopted:

Again, the instantiation would work but there is no way to know that in
the template definition. I think this case should be ill-formed under the
second option. (It would already be ill-formed under the first option.)

From John Spicer:

The "not a new declaration" decision is more of a guiding principle
than a hard and fast rule. For example, a name introduced in a
using-declaration
can have different access than the original declaration.

Like symbolic links, a using-declaration can be viewed as a declaration
that declares an alias to another name, much like a typedef.

In my opinion, "X c;" is already well-formed. Why would we permit
typename to be used in a using-declaration if not to permit this
precise usage?

In my opinion, all that needs to be done is to clarify that the "typeness"
or "templateness" attribute of the name referenced in the using-declaration
is attached to the alias created by the using-declaration. This is
solution #1.

Tentative Resolution:

The rules for multiple declarations with the same name in the same scope
should treat a using-declaration which names a type as a typedef,
just as a typedef of a class name is treated as a class declaration. This
needs drafting work. Also see Core issue 36.

Rationale (04/99): Any semantics associated with the
typename keyword in using-declarations should be considered an
extension.

Notes from the April 2003 meeting:

This was reopened because we are now considering extensions again.
We agreed that it is desirable for the typename to be "sticky" on
a using-declaration, i.e., references to the name introduced by
the using-declaration are known to be type names without the use
of the typename keyword (which can't be specified on an unqualified
name anyway, as of now). The related issue with the template keyword
already has a separate issue 109.

Issue 2 deals with the "struct hack."
There is an example in 7.3.3 [namespace.udecl] paragraph 10
that shows a use of using-declarations to import two names that
coexist because of the "struct hack." After some deliberation,
we decided that the template-dependent using-declaration case is
different enough that we did not have to support the "struct hack"
in that case.
A name introduced in such a case is like a typedef, and no other
hidden type can be accessed through an elaborated type specifier.

Proposed resolution (April 2003, revised October 2003):

Add a new paragraph to the bottom of 7.3.3 [namespace.udecl]:

If a using-declaration uses
the keyword typename and specifies a dependent name
(14.6.2 [temp.dep]), the
name introduced by the using-declaration is treated as a
typedef-name (7.1.3 [dcl.typedef]).

258.
using-declarations and cv-qualifiers

When a using-declaration brings names from a base class into a
derived class scope, member functions in the derived class override
and/or hide member functions with the same name and parameter types in
a base class (rather than conflicting).

Note that this description says nothing about the cv-qualification
of the hiding and hidden member functions. This means, for instance,
that a non-const member function in the derived class hides a const
member function with the same name and parameter types instead of
overloading it in the derived class scope. For example,

If a virtual member function vf is declared in a class
Base and in a class Derived, derived directly or
indirectly from Base, a member function vf with the
same name and same parameter list as Base::vf is declared,
then Derived::vf is also virtual (whether or not it is so
declared) and it overrides Base::vf.

Notes on the 04/01 meeting:

The hiding and overriding should
be on the basis of the function signature, which includes any
cv-qualification on the function.

Proposed resolution (04/02):

In 7.3.3 [namespace.udecl] paragraph 12 change:

When a using-declaration brings names from a base class into a
derived class scope, member functions in the derived class override and/or
hide member functions with the same name and parameter types in a base
class (rather than conflicting).

to read:

When a using-declaration brings names from a base class into a
derived class scope, member functions and member function templates in
the derived class override and/or hide member functions and member
function templates with the same name, parameter-type-list
(8.3.5 [dcl.fct]),
and cv-qualification in a base class (rather than conflicting).

In 10.3 [class.virtual] paragraph 2 change:

If a virtual member function vf is declared in a class
Base and in a class Derived, derived directly or
indirectly from Base, a member function vf with the
same name and same parameter list as Base::vf is declared,
then Derived::vf is also virtual (whether or not it is so
declared) and it overrides Base::vf.

to read:

If a virtual member function vf is declared in a class
Base and in a class Derived, derived directly or
indirectly from Base, a member function vf with the
same name, parameter-type-list (8.3.5 [dcl.fct]), and
cv-qualification as Base::vf
is declared, then Derived::vf is also virtual (whether or not
it is so declared) and it overrides Base::vf.

Several popular compilers give an error on this, but there
doesn't seem to be anything in 7.3.3 [namespace.udecl] that
prohibits it. It should be noted that the user can get the same
effect by using a namespace alias:

namespace my_namespace2 = ::my_namespace::my_namespace2;

Notes from the March 2004 meeting:

We agree that it should be an error.

Proposed resolution (October, 2004):

Add the following as a new paragraph after 7.3.3 [namespace.udecl] paragraph 5:

A using-declaration shall not name a namespace;

4.
Does extern "C" affect the linkage of function names with internal linkage?

At most one of a set of overloaded functions with a particular name
can have C linkage.

Does this apply to static functions as well? For example, is the following
well-formed?

extern "C" {
static void f(int) {}
static void f(float) {}
};

Can a function with internal linkage "have C linkage" at all (assuming
that phrase means "has extern "C" linkage"), for how can a function be
extern "C" if it's not extern? The function type can have extern
"C" linkage — but I think that's independent of the linkage of the function
name. It should be perfectly reasonable to say, in the example above,
that extern "C" applies only to the types of f(int) and f(float),
not to the function names, and that the rule in 7.5 [dcl.link]
paragraph 6 doesn't apply.

Suggested resolution: The extern "C" linkage specification applies
only to the type of functions with internal linkage, and therefore some
of the rules that have to do with name overloading don't apply.

Proposed Resolution:

The intent is to distingush implicit linkage from explicit linkage
for both name linkage and language (function type) linkage. (It might
be more clear to use the terms name linkage and type linkage
to distinguish these concepts. A function can have a name with one
kind of linkage and a type with a different kind of linkage. The
function itself has no linkage: it has no name, only the declaration has
a name. This becomes more obvious when you consider function pointers.)

The tentatively agreed proposal is to apply implicit linkage to names
declared in brace-enclosed linkage specifications and to non-top-level
names declared in simple linkage specifications; and to apply explicit
linkage to top-level names declared in simple linkage specifications.

The language linkage of any function type formed through a function
declarator is that of the nearest enclosing linkage-specification.
For purposes of determining whether the declaration of a namespace-scope
name matches a previous declaration, the language linkage portion of the
type of a function declaration (that is, the language linkage of the function
itself, not its parameters, return type or exception specification) is
ignored.

For a linkage-specification using braces, i.e.

externstring-literal{declaration-seqopt}

the linkage of any declaration of a namespace-scope name (including local
externs) which is not contained in a nested linkage-specification,
is not declared to have no linkage (static), and does not match a previous
declaration is given the linkage specified in the string-literal.
The language linkage of the type of any function declaration of a namespace-scope
name (including local externs) which is not contained in a nested linkage-specification
and which is declared with function declarator syntax is the same as that
of a matching previous declaration, if any, else is specified by string-literal.

For a linkage-specification without braces, i.e.

externstring-literaldeclaration

the linkage of the names declared in the top-level declarators of declaration
is specified by string-literal; if this conflicts with the linkage
of any matching previous declarations, the program is ill-formed. The language
linkage of the type of any top-level function declarator is specified by
string-literal; if this conflicts with the language linkage of the
type of any matching previous function declarations, the program is ill-formed.
The effect of the linkage-specification on other (non top-level)
names declared in declaration is the same as that of the brace-enclosed
form.

extern "C++" void f(void(*fp)()); // error - linkage of "f" does not
// match previous declaration
// (linkage of function type used in
// parameter is still "C" and is not
// by itself ill-formed)
extern "C" void g(void(*fp)()); // error - linkage of "g" does not
// match previous declaration
// (linkage of function type used in
// parameter is still "C++" and is not
// by itself ill-formed)

That is, non-top-level declarators get their linkage from matching
declarations, if any, else from the nearest enclosing linkage
specification. (As already described, top-level declarators in a
brace-enclosed linkage specification get the linkage from matching
declarations, if any, else from the linkage specifcation; while
top-level declarators in direct linkage specifications get their
linkage from that specification.)

Mike Miller: This is a pretty significant change from the
current specification, which treats the two forms of language linkage
similarly for most purposes. I don't understand why it's desirable to
expand the differences.

It seems very unintuitive to me that you could have a top-level
declaration in an extern "C" block that would not
receive "C" linkage.

In the current standard, the statement in
7.5 [dcl.link] paragraph 4 that

the specified language linkage applies to the function types of all
function declarators, function names, and variable names introduced by
the declaration(s)

both "C++" declarations would be well-formed, declaring an
overloaded version of f that takes a pointer to a "C++"
function as a parameter. I wouldn't expect that either declaration
would be a redeclaration (valid or invalid) of the "C" version of
f.

Bill Gibbons: The potential difficulty is the matching
process and the handling of deliberate overloading based on language
linkage. In the above examples, how are these two declarations
matched:

given that the linkage that is part of fp1 is "C" while the linkage (prior
to the matching process) that is part of fp2 is "C++"?

The proposal is that the linkage which is part of the parameter type is not
determined until after the match is attempted. This almost always correct
because you can't overload "C" and "C++" functions; so if the function names
match, it is likely that the declarations are supposed to be the
same.

Mike Miller: This seems like more trouble than it's worth.
This comparison of function types ignoring linkage specifications is,
as far as I know, not found anywhere in the current standard. Why do
we need to invent it?

Bill Gibbons: It is possible to construct pathological cases where this fails, e.g.

In this case the two function declarations refer to different
functions.

Mike Miller: This seems pretty strange to me. I think it
would be simpler to determine the type of the parameter based on the
containing linkage specification (implicitly "C++") and require a
typedef if the user wants to override the default behavior. For
example:

The following changes were tentatively approved, but because they
do not completely implement the proposal above the issue is being kept
for the moment in "drafting" status.

Notes from 10/00 meeting:

After further discussion, the core language working group
determined that the more extensive proposal described above is
not needed and that the following changes are sufficient.

Proposed resolution (04/01):

Change the first sentence of 7.5 [dcl.link]
paragraph 1 from

All function types, function names, and variable names
have a language linkage.

to

All function types, function names with external
linkage, and variable names with external linkage have
a language linkage.

Change the following sentence of 7.5 [dcl.link]
paragraph 4:

In a linkage-specification, the specified language
linkage applies to the function types of all function
declarators, function names, and variable names
introduced by the declaration(s).

to

In a linkage-specification, the specified language
linkage applies to the function types of all function
declarators, function names with external linkage, and
variable names with external linkage declared within
the linkage-specification.

Except for functions with internal linkage, a function
first declared in a linkage-specification behaves as a
function with external linkage. [Example:

extern "C" double f();
static double f(); // error

is ill-formed (7.1.1 [dcl.stc]). ] The form of
linkage-specification that contains a braced-enclosed
declaration-seq does not affect whether the contained
declarations are definitions or not (3.1 [basic.def]); the
form of linkage-specification directly containing a
single declaration is treated as an extern specifier
(7.1.1 [dcl.stc]) for the purpose of determining whether
the contained declaration is a definition. [Example:

extern "C" int i; // declaration
extern "C" {
int i; // definition
}

—end example] A linkage-specification directly
containing a single declaration shall not specify a
storage class. [Example:

extern "C" static void f(); // error

—end example]

to

A declaration directly contained in a
linkage-specification is treated as if it contains the
extern specifier (7.1.1 [dcl.stc]) for the purpose of
determining the linkage of the declared name and
whether it is a definition. Such a declaration shall
not specify a storage class. [Example:

29.
Linkage of locally declared functions

[Moved to DR at October 2002 meeting. This was incorrectly
marked as having DR status between 4/01 and 4/02. It was overlooked
when issue 4 was moved to DR at the 4/01
meeting; this one should have been moved as well, because it's resolved
by the changes there.]

Consider the following:

extern "C" void foo()
{
extern void bar();
bar();
}

Does "bar()" have "C" language linkage?

The ARM is explicit and says

A linkage-specification for a function also applies to functions
and objects declared within it.

The DIS says

In a linkage-specification, the specified language linkage
applies to the function types of all function declarators, function names,
and variable names introduced by the declaration(s).

Is the body of a function definition part of the declaration?

From Mike Miller:

Yes: from 7 [dcl.dcl]
paragraph 1,

declaration:

function-definition

and 8.4 [dcl.fct.def]
paragraph 1:

function-definition:

decl-specifier-seqopt declarator ctor-initializeropt function-body

At least that's how I'd read it.

From Dag Brück:

Consider the
following where extern "C" has been moved to a separate declaration:

extern "C" void foo();
void foo() { extern void bar(); bar(); }

I think the ARM wording could possibly be interpreted such that bar() has
"C" linkage in my example, but not the DIS wording.

As a side note, I have always wanted to think that placing extern "C"
on a function definition or a separate declaration would produce identical
programs.

The restrictions on declaring and/or defining classes inside
type-specifier-seqs and type-ids are inconsistent
throughout the Standard. This is probably due to the fact that
nearly all of the sections that deal with them attempt to state
the restriction afresh. There are three cases:

5.3.4 [expr.new], 6.4 [stmt.select],
and 12.3.2 [class.conv.fct] prohibit “declarations”
of classes and enumerations. That means that

while (struct C* p = 0) ;

is ill-formed unless a prior declaration of C has been
seen. These appear to be cases that should have been fixed by
issue 379, changing “class
declaration” to “class definition,” but were
overlooked.

All the remaining cases prohibit “type
definitions,” apparently referring to classes and
enumerations.

Suggested resolution:

Add something like, “A class or enumeration shall
not be defined in a type-specifier-seq or in a
type-id,” to a single place in the Standard and
remove all other mentions of that restriction (allowing
declarations via elaborated-type-specifier).

Mike Miller:

An alias-declaration is just a different syntax for
a typedef declaration, which allows definitions of a class in
the type; I would expect the same to be true of an
alias-declaration. I don't have any particularly
strong attachment to allowing a class definition in an
alias-declaration. My only concern is introducing
an irregularity into what are currently exact-match
semantics with typedefs.

There's a parallel restriction in many (but not all?) of
these places on typedef declarations.

Jens Maurer:

Those are redundant, as typedef is not a
type-specifier, and should be removed as well.

The type-specifier-seq shall not contain class declarations, or
enumeration declarations.

Delete paragraph 4 of 5.3.6 [expr.alignof]:

A type shall not be defined in an alignof expression.

Delete paragraph 3 of 5.4 [expr.cast]:

Types shall not be defined in casts.

Delete the indicated words from 6.4 [stmt.select]
paragraph 2:

...The type-specifier-seq shall not contain
typedef and shall not declare a new class or
enumeration....

Add the indicated words to 7.1.6 [dcl.type]
paragraph 3:

At least one type-specifier that is not a
cv-qualifier is required in a declaration unless it
declares a constructor, destructor or conversion function.
[Footnote: ... ] A type-specifier-seq shall not
define a class or enumeration unless it appears in the
type-id of an alias-declaration
(7.1.3 [dcl.typedef]).

Delete the indicated words from 12.3.2 [class.conv.fct]
paragraph 1:

...Classes, enumerations, and typedef-names shall not be
declared in the type-specifier-seq....

In
3.7.4.1 [basic.stc.dynamic.allocation]
paragraph 4, replace "type_info" by
"std::type_info" in the note.

In
3.7.4.2 [basic.stc.dynamic.deallocation]
paragraph 3, replace all four instances of "size_t" by
"std::size_t".

In
3.8 [basic.life]
paragraph 5, replace "malloc" by
"std::malloc" in the example code and insert
"#include <cstdlib>" at the beginning of the example
code.

In
3.9 [basic.types]
paragraph 2, replace "memcpy" by
"std::memcpy" (the only instance in the footnote and both
instances in the example) and replace "memmove" by
"std::memmove" in the footnote (see also
issue 43).

In
3.9 [basic.types]
paragraph 3, replace "memcpy" by
"std::memcpy", once in the normative text and once in the
example (see also issue 43).

In
15.4 [except.spec]
paragraph 9, replace "unexpected" by
"std::unexpected" and "terminate" by
"std::terminate".

In
15.5 [except.special]
paragraph 1, replace "terminate" by
"std::terminate" and "unexpected" by
"std::unexpected".

In the heading of
15.5.1 [except.terminate],
replace "terminate" by "std::terminate".

In
15.5.1 [except.terminate]
paragraph 1, footnote in the first bullet, replace
"terminate" by "std::terminate". In the
same paragraph, fifth bullet, replace "atexit" by
"std::atexit". In the same paragraph, last bullet,
replace "unexpected_handler" by
"std::unexpected_handler".

In
15.5.1 [except.terminate]
paragraph 2, replace

In such cases,

void terminate();

is called...

by

In such cases, std::terminate() is called...

and replace all three instances of "terminate" by
"std::terminate".

In the heading of
15.5.2 [except.unexpected],
replace "unexpected" by "std::unexpected".

In
15.5.2 [except.unexpected]
paragraph 1, replace

...the function

void unexpected();

is called...

by

...the function std::unexpected() is called...

.

In
15.5.2 [except.unexpected]
paragraph 2, replace "unexpected" by
"std::unexpected" and "terminate" by
"std::terminate".

—end example]
[Note: an "array of Ncv-qualifier-seqT"
has cv-qualified type; such
an array has internal linkage unless explicitly declared extern
(7.1.6.1 [dcl.type.cv]
)
and must be initialized as specified in
8.5 [dcl.init]
. ]

The Note appears to contradict the sentence that precedes it.

Mike Miller:
I disagree; all it says is that whether the qualification on
the element type is direct ("const int x[5]") or indirect
("const A CA"), the array itself is qualified in the same way
the elements are.

A compound type (3.9.2 [basic.compound]
)
is not cv-qualified by the cv-qualifiers (if
any) of the types from which it is compounded. Any cv-qualifiers
applied to an array type affect the array element type, not the
array type (8.3.4 [dcl.array]
)."

The Note appears to contradict that section as well.

Mike Miller:
Yes, but consider the last two sentences of
3.9.3 [basic.type.qualifier]
paragraph 5:

Cv-qualifiers applied to an array type attach to the
underlying element type, so the notation "cvT,"
where T is
an array type, refers to an array whose elements are
so-qualified. Such array types can be said to be more (or
less) cv-qualified than other types based on the cv-qualification
of the underlying element types.

I think this says essentially the same thing as
8.3.4 [dcl.array]
paragraph 1 and
its note: the qualification of an array is (bidirectionally)
equivalent to the qualification of its members.

Mike Ball:
I find this a very far reach. The text in
8.3.4 [dcl.array]
is essentially that which
is in the C standard (and is a change from early versions of C++).
I don't see any justification at all for the bidirectional equivalence.
It seems to me that
the note is left over from the earlier version of the language.

Steve Clamage: Finally, the Note seems to say that the declaration

volatile char greet[6] = "Hello";

gives "greet" internal linkage, which makes no sense.

Have I missed something, or should that Note be entirely removed?

Mike Miller:
At least the wording in the note
should be repaired not to indicate that volatile-qualification
gives an array internal linkage. Also, depending on how the
discussion goes, either the wording in
3.9.3 [basic.type.qualifier]
paragraph 2
or in paragraph 5 needs
to be amended to be consistent regarding whether an array type
is considered qualified by the qualification of its element
type.

Steve Adamczyk pointed out that
the current state of affairs resulted from the need to handle
reference binding consistently. The wording is intended to define
the question, "Is an array type cv-qualified?" as being equivalent
to the question, "Is the element type of the array cv-qualified?"

Proposed resolution (10/00):

Replace the portion of the note in 8.3.4 [dcl.array]
paragraph 1 reading

such an array has internal linkage unless explicitly declared
extern (7.1.6.1 [dcl.type.cv]) and must be
initialized as specified in 8.5 [dcl.init].

140.
Agreement of parameter declarations

All declarations for a function with a given parameter list shall
agree exactly both in the type of the value returned and in the
number and type of parameters.

It is not clear what this requirement means with respect to a pair
of declarations like the following:

int f(const int);
int f(int x) { ... }

Do they violate this requirement? Is x const in the body of
the function declaration?

Tom Plum:
I think the FDIS quotation means that the pair of decls are valid.
But it doesn't clearly answer whether
x is const inside the function definition.
As to intent, I know the intent was that if the function
definition wants to specify that x is const,
the const must appear specifically in the defining
decl, not just on some decl elsewhere.
But I can't prove that intent from the drafted words.

Mike Miller:
I think the intent was something along the
following lines:

Two function declarations denote the same entity if
the names are the same and the function signatures
are the same. (Two function declarations with C
language linkage denote the same entity if the names
are the same.) All declarations of a given function
shall agree exactly both in the type of the value
returned and in the number and type of parameters;
the presence or absence of the ellipsis is considered
part of the signature.

(See 3.5 [basic.link]
paragraph 9.
That paragraph talks about names in different
scopes and says that function references are the same if the
"types are identical for purposes of overloading," i.e., the
signatures are the same. See also
7.5 [dcl.link]
paragraph 6
regarding C language
linkage, where only the name is required to be the same for
declarations in different namespaces to denote the same
function.)

According to this paragraph, the type of a parameter is
determined by considering its decl-specifier-seq and
declarator
and then applying the array-to-pointer and function-to-pointer
adjustments. The cv-qualifier and storage class adjustments
are performed for the function type but not for the parameter
types.

If my interpretation of the intent of the second sentence of
the paragraph is correct, the two declarations in the example
violate that restriction — the parameter types are not the
same, even though the function types are. Since there's no
dispensation mentioned for "no diagnostic required," an
implementation presumably must issue a diagnostic in this
case. (I think "no diagnostic required" should be stated if
the declarations occur in different translation units —
unless there's a blanket statement to that effect that I have
forgotten?)

(I'd also note in passing that, if my interpretation is
correct,

void f(int);
void f(register int) { }

is also an invalid pair of declarations.)

Proposed resolution (10/00):

In 1.3 [intro.defs] “signature,” change
"the types of its parameters"
to
"its parameter-type-list (8.3.5 [dcl.fct])".

In the third bullet of 3.5 [basic.link] paragraph 9
change
"the function types are identical for the purposes of overloading"
to
"the parameter-type-lists of the functions (8.3.5 [dcl.fct]) are identical."

In the sub-bullets of the third bullet of
5.2.5 [expr.ref] paragraph 4, change all four occurrences
of
"function of (parameter type list)"
to
"function of parameter-type-list."

In 8.3.5 [dcl.fct] paragraph 3, change

All declarations for a function with a given parameter list shall agree
exactly both in the type of the value returned and in the number and
type of parameters; the presence or absence of the ellipsis is
considered part of the function type.

to

All declarations for a function shall
agree exactly in both the return type and the
parameter-type-list.

In 8.3.5 [dcl.fct] paragraph 3, change

The resulting list of transformed parameter types is the function's
parameter type list.

to

The resulting list of transformed parameter types and the presence or
absence of the ellipsis is the function's parameter-type-list.

In 8.3.5 [dcl.fct] paragraph 4, change
"the parameter type list"
to
"the parameter-type-list."

In the second bullet of 13.1 [over.load] paragraph 2,
change all occurrences of "parameter types" to
"parameter-type-list."

In 13.3 [over.match] paragraph 1, change "the types of
the parameters" to "the parameter-type-list."

In the last sub-bullet of the third bullet of
13.3.1.2 [over.match.oper] paragraph 3, change "parameter type
list" to "parameter-type-list."

Note, 7 Sep 2001:

Editorial changes while putting in issue 147
brought up the fact that injected-class-name is not a syntax term and
therefore perhaps shouldn't be written with hyphens. The same can be said of
parameter-type-list.

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.

Suggested resolution:

Replace the quoted sentence from paragraph 4 in
8.3.5 [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.

Proposed resolution (10/01):

In 8.3.5 [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:

typedef void F();
struct S {
const F f; // ill-formed
};

-- end example]

by

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:

Strike the last bulleted item in 14.8.2 [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.

Notes from 4/02 meeting:

Yes, the difference is intentional. There is no way to add cv-qualifiers
other than those cases.

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.

and the type of the contained declarator-id in the
declaration T D1 is
“derived-declarator-type-listT,” T
shall be the single type-specifierauto and the
derived-declarator-type-list shall be empty.

These restrictions were intended to ensure that the return type of
the function is exactly the specified type-id following the
->, not modified by declarator operators and
cv-qualification.

Unfortunately, the requirement for an empty
derived-declarator-type-list does not achieve this goal but
instead forbids declarations like

auto (*fp)() -> int; // pointer to function returning int

while allowing declarations like

auto *f() -> int; // function returning pointer to int

The reason for this is that, according to the grammar in
8 [dcl.decl] paragraph 4, the declarator *f() -> int
is parsed as a ptr-operator applied to the direct-declaratorf() -> int; that is, the declarator D1 seen in
8.3.5 [dcl.fct] is just f, and the
derived-declarator-type-list is thus empty.

By contrast, the declarator (*fp)() -> int is parsed
as the direct-declarator(*fp) followed by the
parameter-declaration-clause, etc. In this case, D1 in
8.3.5 [dcl.fct] is (*fp) and the
derived-declarator-type-list is “pointer to,” i.e.,
not empty.

My personal view is that there is no reason to forbid the
(*fp)() -> int form, and that doing so is problematic.
For example, this restriction would require users desiring the
late-specified return type syntax to write function parameters as
function types and rely on parameter type transformations rather
than writing them as pointer-to-function types, as they will actually
turn out to be:

It may be helpful in deciding whether to allow this form to
consider the example of a function returning a pointer to a function.
With the current restriction, only one of the three plausible forms is
allowed:

... T shall be the single type-specifierautoand the derived-declarator-type-list shall be
empty. Then the type...

Change all occurrences of direct-new-declarator in
5.3.4 [expr.new] to noptr-new-declarator. These
changes appear in the grammar in paragraph 1 and in the text of
paragraphs 6-8, as follows:

...new-declarator:

ptr-operator new-declaratoroptdirect-noptr-new-declarator

direct-noptr-new-declarator:

[expression]direct-noptr-new-declarator[constant-expression]

...

When the allocated object is an array (that is, the
direct-noptr-new-declarator syntax is used or the
new-type-id or type-id denotes an array type), the
new-expression yields a pointer to the initial element (if any)
of the array. [Note: both new int and new
int[10] have type int* and the type of new
int[i][10] is int (*)[10] —end note]

Every constant-expression in a
direct-noptr-new-declarator shall be an integral
constant expression (5.19 [expr.const]) and evaluate to a
strictly positive value. The expression in a
direct-noptr-new-declarator shall be of integral
type, enumeration type, or a class type for which a single
non-explicit conversion function to integral or enumeration type
exists (12.3 [class.conv]). If the expression is of class
type, the expression is converted by calling that conversion function,
and the result of the conversion is used in place of the original
expression. If the value of the expression is negative, the behavior
is undefined. [Example: given the definition int n =
42, new float[n][5] is well-formed (because n
is the expression of a
direct-noptr-new-declarator), but new
float[5][n] is ill-formed (because n is not a constant
expression). If n is negative, the effect of new float[n][5]
is undefined. —end example]

When the value of the expression in a
direct-noptr-new-declarator is zero, the
allocation function is called to allocate an array with no
elements.

136.
Default arguments and friend declarations

For non-template functions, default arguments can be added in later
declarations of a function in the same scope. Declarations in
different scopes have completely distinct sets of default arguments.
That is, declarations in inner scopes do not acquire default arguments
from declarations in outer scopes, and vice versa.

It is unclear how this wording applies to friend function declarations.
For example,

Does the declaration at #2 acquire the default argument from #1, and
does the one at #3 acquire the default arguments from #2?

There are several related questions involved with this issue:

Is the friend
declaration in the scope of class C or in the surrounding namespace
scope?

Mike Miller:
8.3.6 [dcl.fct.default]
paragraph 4
is speaking about the lexical location of the
declaration...
The friend declaration occurs in a different declarative region
from the declaration at #1, so I would read [this paragraph] as saying that it
starts out with a clean slate of default arguments.

Bill Gibbons:
Yes. It occurs in a different region, although it declares a name
in the same region (i.e. a redeclaration). This is the same as with
local externs and is intended to work the same way. We decided that
local extern declarations cannot add (beyond the enclosing block) new
default arguments, and the same should apply to friend declarations.

John Spicer:
The question is whether [this paragraph]
does (or should) mean declarations that appear in the same lexical
scope or declarations that declare names in the same scope. In my opinion,
it really needs to be the latter. It seems somewhat paradoxical to say
that a friend declaration declares a function in namespace scope yet the
declaration in the class still has its own attributes. To make that work
I think you'd have to make friends more like block externs that really do
introduce a name into the scope in which the declaration is contained.

Should default arguments be permitted in friend function
declarations, and what effect should they have?

Bill Gibbons:
In the absence of a declaration visible in class scope to which
they could be attached, default arguments on friend declarations
do not make sense.
[They should be] ill-formed, to prevent surprises.

In other words, a function first declared in a friend declaration must be
permitted to have default arguments and those default arguments must be
usable when the function is found by argument dependent lookup. The reason
that this is important is that it is common practice to define functions
in friend declarations in templates, and that definition is the only place
where the default arguments can be specified.

What restrictions should be placed on default argument usage with
friend declarations?

John Spicer:
We want to avoid instantiation side effects. IMO, the way to do this
would be to prohibit a friend declaration from providing default arguments
if a declaration of that function is already visible.
Once a function has had a default specified in a friend
declaration it should not be possible to add defaults in another declaration
be it a friend or normal declaration.

Mike Miller:
The position that seems most reasonable to me is to
allow default arguments in friend declarations to be used in
Koenig lookup, but to say that they are
completely unrelated to default arguments in declarations in
the surrounding scope; and to forbid use of a default argument
in a call if more than one declaration in the overload set has
such a default, as in the proposed resolution for
issue 1.

5.
CV-qualifiers and type conversions

The description of copy-initialization in 8.5 [dcl.init]
paragraph 14 says:

If the destination type is a (possibly cv-qualified) class type:
...

Otherwise (i.e. for the remaining copy-initialization cases), user-defined
conversion sequences that can convert from the source type to the destination
type or (when a conversion function is used) to a derived class thereof
are enumerated ... if the function is a constructor, the call initializes
a temporary of the destination type. ...

Should "destination type" in this last bullet refer to "cv-unqualified
destination type" to make it clear that the destination type excludes any
cv-qualifiers? This would make it clearer that the following example is
well-formed:

The temporary created with the conversion function is an lvalue of type
B. If the temporary must have the cv-qualifiers of the destination
type (i.e. const) then the copy-constructor for A cannot be called
to create the object of type A from the lvalue of type const
B. If the temporary has the cv-qualifiers of the result type of the
conversion function, then the copy-constructor for A can be called
to create the object of type A from the lvalue of type const
B. This last outcome seems more appropriate.

Steve Adamczyk:

Because of late changes to this area, the
relevant text is now the third sub-bullet of the fourth bullet of
8.5 [dcl.init] paragraph 14:

Otherwise (i.e., for the remaining copy-initialization cases),
user-defined conversion sequences that can convert from the source
type to the destination type or (when a conversion function is used)
to a derived class thereof are enumerated...
The function selected is called with the initializer expression as its
argument; if the function is a constructor, the call initializes a
temporary of the destination type. The result of the call (which is
the temporary for the constructor case) is then used to
direct-initialize, according to the rules above, the object that is
the destination of the copy-initialization.

The issue still remains whether the wording should refer to "the
cv-unqualified version of the destination type." I think it
should.

Notes from 10/00 meeting:

The original example does not illustrate the remaining
problem. The following example does:

78.
Section 8.5 paragraph 9 should state it only applies to non-static objects

If no initializer is specified for an object, and the object
is of (possibly cv-qualified) non-POD class type (or array thereof), the
object shall be default-initialized; if the object is of const-qualified
type, the underlying class type shall have a user-declared default constructor.
Otherwise, if no initializer is specified for an object, the object and
its subobjects, if any, have an indeterminate initial value; if the object
or any of its subobjects are of const-qualified type, the program is ill-formed.

It should be made clear that this paragraph does not apply to static objects.

According to 8.5 [dcl.init]
paragraph
14, the initialization of a is performed in two steps.
First, a temporary of type A is created using A::A(const
B&). Second, the resulting temporary is used to
direct-initialize a using A::A(A&).

The second step requires binding a reference to non-const to the
temporary resulting from the first step. However,
8.5.3 [dcl.init.ref]
paragraph 5 requires
that such a reference be bound only to lvalues.

It is not clear from 3.10 [basic.lval]
whether the temporary created in the process of copy-initialization
should be treated as an lvalue or an rvalue. If it is an lvalue, the
example is well-formed, otherwise it is ill-formed.

Proposed resolution (04/01):

In 8.5 [dcl.init] paragraph 14, insert
the following after "the call initializes a temporary of
the destination type":

277.
Zero-initialization of pointers

The intent of 8.5 [dcl.init] paragraph 5 is that
pointers that are zero-initialized will contain a null pointer
value. Unfortunately, the wording used,

...set to the value of 0 (zero) converted to T

does not match the requirements for creating a null pointer
value given in 4.10 [conv.ptr] paragraph 1:

A null pointer constant is an integral constant expression
(5.19 [expr.const]) rvalue of integer type that evaluates to
zero. A null pointer constant can be converted to a pointer type; the
result is the null pointer value of that type...

The problem is that the "value of 0" in the description of
zero-initialization is not specified to be an integral constant
expression. Nonconstant expressions can also have the value 0,
and converting a nonconst 0 to pointer type need not result in
a null pointer value.

Proposed resolution (04/01):

In 8.5 [dcl.init] paragraph 5, change

...set to the value 0 (zero) converted to T;

to

...set to the value 0 (zero), taken as an integral constant
expression, converted to T; [footnote: as
specified in 4.10 [conv.ptr], converting an integral
constant expression whose value is 0 to a pointer type results
in a null pointer value.]

302.
Value-initialization and generation of default constructor

We've been looking at implementing value-initialization. At one point,
some years back, I remember Bjarne saying that something like X() in
an expression should produce an X object with the same value one would
get if one created a static X object, i.e., the uninitialized members
would be zero-initialized because the whole object is initialized
at program startup, before the constructor is called.

The formulation for default-initialization that made it into TC1 (in
8.5 [dcl.init])
is written a little differently (see issue 178),
but I had always
assumed that it would still be a valid implementation to zero the whole
object and then call the default constructor for the troublesome
"non-POD but no user-written constructor" cases.

That almost works correctly, but I found a problem case:

struct A {
A();
~A();
};
struct B {
// B is a non-POD with no user-written constructor.
// It has a nontrivial generated constructor.
const int i;
A a;
};
int main () {
// Value-initializing a "B" doesn't call the default constructor for
// "B"; it value-initializes the members of B. Therefore it shouldn't
// cause an error on generation of the default constructor for the
// following:
new B();
}

If the definition of the B::B() constructor is generated, an error
is issued because the const member "i" is not initialized. But the
definition of value-initialization doesn't require calling the
constructor, and therefore it doesn't require generating it, and
therefore the error shouldn't be detected.

So this is a case where zero-initializing and then calling the constructor
is not equivalent to value-initializing, because one case generates
an error and the other doesn't.

This is sort of unfortunate, because one doesn't want to generate all
the required initializations at the point where the "()"
initialization
occurs. One would like those initializations to be packaged in a
function, and the default constructor is pretty much the function
one wants.

I see several implementation choices:

Zero the object, then call the default generated constructor. This
is not valid unless the standard is changed to say that the default
constructor might be generated for value-initialization cases like the
above (that is, it's implementation-dependent whether the constructor
definition is generated). The zeroing operation can of course be
optimized, if necessary, to hit only the pieces of the object that
would otherwise be left uninitialized. An alternative would be
to require generation of the constructor for value-initialization
cases, even if the implementation technique doesn't call the
constructor at that point. It's pretty likely that the constructor
is going to have to be generated at some point in the program anyway.

Make a new value-initialization "constructor," whose body looks a
lot like the usual generated constructor, but which also zeroes other members.
No errors would be generated while generating this modified constructor,
because it generates code that does full initialization. (Actually,
it wouldn't guarantee initialization of reference members, and that
might be an argument for generating the constructor, in order to get that
error.) This is standard-conforming, but it destroys object-code
compatibility.

Variation on (1): Zero first, and generate the object code for the
default constructor when it's needed for value-initialization cases, but
don't issue any errors at that time. Issue the errors only if it turns
out the constructor is "really" referenced. Aside from the essential
shadiness of this approach, I fear that something in the generation
of the constructor will cause a template instantiation which will be
an abservable side effect.

Personally, I find option 1 the least objectionable.

Proposed resolution (10/01):

Add the indicated wording to the third-to-last sentence of
3.2 [basic.def.odr] pararaph 2:

A default constructor for a class is used by default initialization
or value initialization as specified in 8.5 [dcl.init].

Add a footnote to the indicated bullet in 8.5 [dcl.init]
paragraph 5:

if T is a non-union class type without a user-declared constructor,
then every non-static data member and base-class component of T is
value-initialized.
[Footnote: Value-initialization for such a class object may be
implemented by zero-initializing the object and then calling the default
constructor.]

Add the indicated wording to the first sentence of
12.1 [class.ctor] paragraph 7:

An implicitly-declared default constructor for a class is implicitly
defined when it is used (3.2 [basic.def.odr]) to
create an object of its class type
(1.8 [intro.object]).

if T is a non-POD class type (clause 9 [class]), the default constructor for T is called (and the
initialization is ill-formed if T has no accessible default
constructor);

if T is an array type, each element is
default-initialized;

otherwise, the object is zero-initialized.

However, default initialization is invoked only for non-POD class
types and arrays thereof (5.3.4 [expr.new] paragraph 15
for new-expressions, 8.5 [dcl.init] paragraph 10
for top-level objects, and 12.6.2 [class.base.init] paragraph 4
for member and base class subobjects — but see
issue 510). Consequently, all cases that
invoke default initialization are handled by the first two bullets;
the third bullet can never be reached. Its presence is misleading, so
it should be removed.

Notes from the September, 2008 meeting:

The approach adopted in the resolution in paper N2762 was
different from the suggestion above: it changes the definition of
default initialization to include POD types and changes the third
bullet to specify that “no initialization is
performed.”

543.
Value initialization and default constructors

[Voted into the WP at the September, 2008 meeting (resolution
in paper N2762).]

The wording resulting from the resolution of
issue 302 does not quite implement the intent
of the issue. The revised wording of 3.2 [basic.def.odr]
paragraph 2 is:

A default constructor for a class is used by default initialization or
value initialization as specified in 8.5 [dcl.init].

This sounds as if 8.5 [dcl.init] specifies how and
under what circumstances value initialization uses a default
constructor (which was, in fact, the case for default initialization
in the original wording). However, the normative text there makes it
plain that value initialization does not call the default
constructor (the permission granted to implementations to call the
default constructor for value initialization is in a non-normative
footnote).

The example that occasioned this observation raises an
additional question. Consider:

struct POD {
const int x;
};
POD data = POD();

According to the (revised) resolution of issue 302, this code is
ill-formed because the implicitly-declared default constructor will
be implicitly defined as a result of being used by value initialization
(12.1 [class.ctor] paragraph 7), and the implicitly-defined
constructor fails to initialize a const-qualified member
(12.6.2 [class.base.init] paragraph 4). This seems unfortunate,
because the (trivial) default constructor of a POD class is otherwise
not used — default initialization applies only to non-PODs
— and it is not actually needed in value initialization.
Perhaps value initialization should be defined to “use”
the default constructor only for non-POD classes? If so, both of
these problems would be resolved by rewording the above-referenced
sentence of 3.2 [basic.def.odr] paragraph 2 as:

A default constructor for a non-POD class is used by
default initialization or value initialization as specified in(8.5 [dcl.init]).

Notes from the April, 2006 meeting:

The approach favored by the CWG was to leave 3.2 [basic.def.odr]
unchanged and to add normative wording to 8.5 [dcl.init]
indicating that it is unspecified whether the default constructor is
called.

Notes from the October, 2006 meeting:

The CWG now prefers that it should not be left unspecified whether
programs of this sort are well- or ill-formed; instead, the Standard
should require that the default constructor be defined in such cases.
Three possibilities of implementing this decision were discussed:

Change 3.2 [basic.def.odr] to state flatly that the
default constructor is used by value initialization (removing the
implication that 8.5 [dcl.init] determines the conditions
under which it is used).

Change 8.5 [dcl.init] to specify that non-union
class objects with no user-declared constructor are value-initialized
by first zero-initializing the object and then calling the
(implicitly-defined) default constructor, replacing the current
specification of value-initializing each of its sub-objects.

Add a normative statement to 8.5 [dcl.init] that
value-initialization causes the implicitly-declared default constructor
to be implicitly defined, even if it is not called.

Proposed resolution (June, 2008):

Change the second bullet of the value-initialization definition
in 8.5 [dcl.init] paragraph 5 as follows:

if T is a non-union class type without a
user-provided constructor, then every non-static data member and
base-class component of T is value-initialized;
[Footnote: Value-initialization for such a class object may be
implemented by zero-initializing the object and then calling the
default constructor. —end footnote]the object is
zero-initialized and the implicitly-defined default constructor is
called;

Notes from the September, 2008 meeting:

The resolution supplied in paper N2762 differs from the June,
2008 proposed resolution in that the implicitly-declared default
constructor is only called (and thus defined) if it is
non-trivial, making the struct POD example above
well-formed.

is this undefined or unspecified or something else? I can find nothing in
8.5.1 [dcl.init.aggr] that indicates whether the components of
an initializer-list are evaluated in order or not, or whether they
have sequence points between them.

6.7.8/23 of the C99 std has this to say

The order in which any side effects occur among the initialization list
expressions is unspecified.

I think similar wording is needed in 8.5.1 [dcl.init.aggr]

Steve Adamczyk:
I believe the standard is clear that each initializer
expression in the above is a full-expression
(1.9 [intro.execution]/12-13; see also
issue 392) and therefore there is a sequence point
after each expression (1.9 [intro.execution]/16). I agree that the
standard does not seem to dictate the order in which the expressions
are evaluated, and perhaps it should. Does anyone know of a compiler
that would not evaluate the expressions left to right?

Mike Simons: Actually there is one, that does not do
left to right: gcc/C++. None of the post increment operations
take effect until after the statement finishes. So in the sample
code gcc stores 23 into all positions in the array. The
commercial vendor C++ compilers for AIX, Solaris, Tru64, HPUX
(parisc and ia64), and Windows, all do sequence points at each
',' in the initializer list.

491.
Initializers for empty-class aggregrate members

The current wording of 8.5.1 [dcl.init.aggr] paragraph
8 requires that

An initializer for an aggregate member that is an empty class
shall have the form of an empty initializer-list {}.

This is overly constraining. There is no reason that the
following should be ill-formed:

struct S { };
S s;
S arr[1] = { s };

Mike Miller: The wording of 8.5.1 [dcl.init.aggr] paragraph 8 is unclear. “An aggregate
member” would most naturally mean “a member of an
aggregate.” In context, however, I think it must mean
“a member [of an aggregate] that is an aggregate”,
that is, a subaggregate. Members of aggregates need not
themselves be aggregates (cf paragraph 13 and 12.6.1 [class.expl.init]); it cannot be the case that an object of an
empty class with a user-declared constructor must be initialized
with {} when it is a member of an aggregate. This
wording should be clarified, regardless of the decision on
Nathan's point.

in which the initializer of a scalar member of an aggregate can
itself be brace-enclosed. The relevant wording from the C99
Standard is found in 6.7.8 paragraph 11:

The initializer for a scalar shall be a single expression,
optionally enclosed in braces.

and paragraph 16:

Otherwise, the initializer for an object that has aggregate or
union type shall be a brace-enclosed list of initializers for the
elements or named members.

The “list of initializers” in paragraph 16 must be
a recursive reference to paragraph 11 (that's the only place that
describes how an initialized item gets its value from the
initializer expression), which would thus make the
“brace-enclosed” part of paragraph 11 apply to each of
the initializers in the list in paragraph 16 as well.

This appears to be an incompatibility between C and C++:
8.5.1 [dcl.init.aggr] paragraph 11 says,

If the initializer-list begins with a left brace, then the
succeeding comma-separated list of initializer-clauses
initializes the members of a subaggregate....

which clearly leaves the impression that only a subaggregate
may be initialized by a brace-enclosed initializer-clause.

Either the specification in 8.5.1 [dcl.init.aggr]
should be changed to allow a brace-enclosed initializer of a
scalar member of an aggregate, as in C, or this incompatibility
should be listed in Appendix C [diff].

Notes from the July, 2007 meeting:

It was noted that implementations differ in their handling of this
construct; however, the issue is long-standing and fairly obscure.

Notes from the October, 2007 meeting:

The initializer-list proposal will resolve this issue when it is
adopted.

There is a place in the Standard where overload resolution is implied
but the way that a set of candidate functions is to be formed is
omitted. See below.

According to the Standard, when initializing a reference to a
non-volatile const class type (cv1T1) with an rvalue
expression (cv2T2) where cv1T1 is
reference compatible with cv2T2, the implementation
shall proceed in one of the following
ways (except when initializing the implicit object parameter of a
copy constructor) 8.5.3 [dcl.init.ref] paragraph 5 bullet 2
sub-bullet 1:

The reference is bound to the object represented by the rvalue (see
3.10 [basic.lval]) or to a sub-object within that object.

A temporary of type "cv1T2" [sic] is created, and a
constructor is called to copy the entire rvalue object into the temporary...

While the first case is quite obvious, the second one is a bit unclear
as it says "a constructor is called to copy the entire rvalue object
into the temporary" without specifying how the temporary is created --
by direct-initialization or by copy-initialization? As stated in DR
152, this can make a difference when the copy constructor is declared
as explicit. How should the set of candidate functions be formed? The
most appropriate guess is that it shall proceed as per
13.3.1.3 [over.match.ctor].

Another detail worth of note is that in the draft version of the
Standard as of 2 December 1996 the second bullet read:

A temporary of type "cv1T2" [sic] is created, and a copy
constructor is called to copy the entire rvalue object into the
temporary...

J. Stephen Adamczyk replied that the reason for changing "a copy
constructor" to "a constructor" was to allow for member template
converting constructors.

However, the new wording is somewhat in conflict with the footnote #93
that says that when initializing the implicit object parameter of a
copy constructor an implementation must eventually choose the first
alternative (binding without copying) to avoid infinite recursion.
This seems to suggest that a copy constructor is always used for
initializing the temporary of type "cv1T2".

Furthermore, now that the set of candidate functions is not limited to
only the copy constructors of T2, there might be some unpleasant
consequences.
Consider a rather contrived sample below:

In this example the initialization of the temporary of type
'<TT>const std::auto_ptr<int>'
(to which 'ri' is meant to be subsequently bound)
doesn't fail, as it would had the approach with copy constructors been
retained, instead, a yet another temporary gets created as the
well-known sequence:

is called (assuming, of course, that the set of candidate functions is
formed as per 13.3.1.3 [over.match.ctor]). The second temporary
is transient and gets
destroyed at the end of the initialization. I doubt that this is the
way that the committee wanted this kind of reference binding to go.

Besides, even if the approach restricting the set of candidates to copy
constructors is restored, it is still not clear how the initialization
of the temporary (to which the reference is intended to be bound) is
to be performed -- using direct-initialization or copy-initialization.

Another place in the Standard that would benefit from a similar
clarification is the creation of an exception object, which is
delineated in 15.1 [except.throw].

David Abrahams (February 2004):
It appears, looking at core 291, that there may be a need to tighten
up 8.5.3 [dcl.init.ref]/5.

Please see the attached example file, which demonstrates "move
semantics" in C++98. Many compilers fail to compile test 10 because
of the way 8.5.3/5 is interpreted. My problem with that
interpretation is that test 20:

typedef X const XC;
sink2(XC(X()));

does compile. In other words, it *is* possible to construct the const
temporary from the rvalue. IMO, that is the proper test.

8.5.3/5 doesn't demand that a "copy constructor" is used to copy the
temporary, only that a constructor is used "to copy the temporary".
I hope that when the language is tightened up to specify direct (or
copy initialization), that it also unambiguously allows the enclosed
test to compile. Not only is it, I believe, within the scope of
reasonable interpretation of the current standard, but it's an
incredibly important piece of functionality for library writers and
users alike.

Change paragraph 5, second bullet,
first sub-bullet, second sub-sub-bullet as follows:

A temporary of type "cv1T2" [sic] is created, and a
constructor is called to copy the entire rvalue object into the temporaryvia copy-initialization from the entire rvalue object.
The reference is bound to the temporary or to a sub-object
within the temporary.

The text immediately following that is changed as follows:

The constructor that would be used to make the copy shall be
callable whether or not the copy is actually done.The constructor and any conversion function that would be used in the
initialization shall be callable whether or not the temporary is
actually created.

Note, however, that the way the core working group is leaning
on issue 391 (i.e., requiring direct
binding) would make this change unnecessary.

391.
Require direct binding of short-lived references to rvalues

After some email exchanges with Rani Sharoni, I've come up
with the following proposal to allow reference binding to
non-copyable rvalues in some cases. Rationale and some
background appear afterwards.

---- proposal ----

Replace the section of 8.5.3 [dcl.init.ref] paragraph 5
that begins "If the initializer expression is an rvalue" with the
following:

If the initializer expression is an rvalue, with T2 a
class type, and ``cv1 T1'' is reference-compatible with
``cv2 T2,'' the reference is bound as follows:

If the lifetime of the reference does not extend
beyond the end of the full expression containing the
initializer expression, the reference is bound to
the object represented by the rvalue (see 3.10 [basic.lval]) or
to a sub-object within that object.

otherwise, the reference is bound in one of the
following ways (the choice is implementation-defined):

[... continues as before - the original wording applies
unchanged to longer-lived references]

---- rationale ----

The intention of the current wording is to provide the
implementation freedom to construct an rvalue of class
type at an arbitrary location and copy it zero or more
times before binding any reference to it.

The standard allows code to call a member function on an
rvalue of class type (in 5.2.5 [expr.ref], I guess).
This means that
the implementation can be forced to bind the reference
directly, with no freedom to create any temporary
copies. e.g.

Forcing a direct binding in this way is possible wherever
the lifetime of the reference does not extend beyond the
containing full expression, since the reference returned
by the member function remains valid for this long.

As demonstrated above, existing implementations must
already be capable of constructing an rvalue of class
type in the "right" place the first time. Some compilers
already silently allow the direct binding of references
to non-copyable rvalues.

The change will not break any portable user code. It
would break any platform-specific user code that relies
on copies being performed by the particular
implementation.

---- background ----

The proposal is based on a recent discussion in this
group. I originally wanted to leave the implementation free
to copy the rvalue if there was a callable copy constructor,
and only have to bind directly if none was callable.
Unfortunately, a traditional compiler can't always tell
whether a function is callable or not, e.g. if the copy
constructor is declared but not defined. Rani pointed this
out in an example, and suggested that maybe trivial copy
constructors should still be allowed (by extension, maybe
wherever the compiler can determine callability). I've gone
with this version because it's simpler, and I also figure
the "as if" rule gives the compiler some freedom with POD
types anyway.

Notes from April 2003 meeting:

We agreed generally with the proposal. We were unsure about the
need for the restriction regarding long-lived references.
We will check with the proposer about that.

Jason Merrill points out that the test case in
issue 86 may be a case where we
do not want to require direct binding.

Further information from Rani Sharoni (April 2003):

I wasn't aware about the latest suggestion of Raoul as it appears in
core issue 391. In our discussions we tried to formulate a different
proposal.

The rational, as we understood, behind the implementation freedom to
make an extra copying (8.5.3/5/2/12) of the rvalue is to allow return
values in registers which on some architectures are not addressable.
The example that Raoul and I presented shows that this implementation
freedom is not always possible since we can "force" the rvalue to be
addressable using additional member function (by_ref). The example
only works for short lived rvalues and this is probably why Raoul
narrow the suggestion.

I had different rational which was related to the implementation of
conditional operator in VC. It seems that when conditional operator is
involved VC does use an extra copying when the lifetime of the
temporary is extended:

I don't know what the consideration behind the VC implementation was
(I saw open bug on this issue) but it convinced me to narrow the
suggestion.

IMHO such limitation seems to be too strict because it might limit the
optimizer since returning class rvalues in registers might be useful
(although I'm not aware about any implementation that actually does
it). My suggestion was to forbid the extra copying if the ctor is not
viable (e.g. A::A(A&) ). In this case the implementation "freedom"
doesn't exist (since the code might not compile) and only limits the
programmer freedom (e.g. Move Constructors -
http://www.cuj.com/experts/2102/alexandr.htm).

Core issue 291 is strongly related to
the above issue and I personally
prefer to see it resolved first. It seems that VC already supports the
resolution I prefer.

Notes from October 2003 meeting:

We ended up feeling that this is just one of a number of cases
of optimizations that are widely done by compilers
and allowed but not required by the standard. We don't see any
strong reason to require compilers to do this particular
optimization.

Notes from the March 2004 meeting:

After discussing issue 450, we
found ourselves reconsidering this, and we are now inclined to
make a change to require the direct binding in all cases,
with no restriction on long-lived references. Note that such
a change would eliminate the need for a change for
issue 291.

If the initializer expression is an rvalue, with T2 a class type,
and "cv1T1" is reference-compatible with
"cv2T2", the reference is bound to the
object represented by the rvalue (see 3.10 [basic.lval]) or to a sub-object within that object.in one of the following ways (the choice is
implementation-defined):

The reference is bound to the object represented by the
rvalue (see 3.10 [basic.lval]) or to a sub-object
within that object.

A temporary of type "cv1T2" [sic] is created, and a
constructor is called to copy the entire rvalue object into the
temporary. The reference is bound to the temporary or to a
sub-object within the temporary.

The constructor that would be used to make the copy shall be
callable whether or not the copy is actually done.
[Example:

struct A { };
struct B : public A { } b;
extern B f();
const A& rca = f (); // BoundEither bound to the A sub-object of the B rvalue,
// or the entire B object is copied and the reference
// is bound to the A sub-object of the copy

When you run this through 8.5.3 [dcl.init.ref], you sort of end up
falling off the end of the standard's description of reference
binding. The standard says in the final bullet of paragraph 5
that an array temporary should be created and copy-initialized
from the rvalue array, which seems implausible.

I'm not sure what the right answer is. I think I'd be happy with
allowing the binding in this case. We would have to introduce
a special case like the one for class rvalues.

Notes from the March 2004 meeting:

g++ and EDG give an error. Microsoft (8.0 beta) and Sun accept
the example. Our preference is to allow the direct binding (no copy).
See the similar issue with class rvalues in
issue 391.

If the initializer expression is an rvalue, with T2 an
array type, and “cv1T1” is
reference-compatible with “cv2T2”,
the reference is bound to the object represented by the rvalue
(see 3.10 [basic.lval]).

Change 3.10 [basic.lval] paragraph 2 as
follows:

An lvalue refers to an object or function. Some rvalue
expressions — those of (possibly cv-qualified) class
or array typeor cv-qualified class type —
also refer to objects.

175.
Class name injection and base name access

With class name injection, when a base class name is used in a derived
class, the name found is the injected name in the base class, not the
name of the class in the scope containing the base class.
Consequently, if the base class name is not accessible (e.g., because
is is in a private base class), the base class name cannot be used
unless a qualified name is used to name the class in the class or
namespace of which it is a member.

Without class name injection the following example is valid. With
class name injection, A is inaccessible in class C.

At the least, the standard should be more explicit that this is, in
fact, ill-formed.

(See paper J16/99-0010 = WG21 N1187.)

Proposed resolution (04/01):

Add to the end of 11.1 [class.access.spec] paragraph 3:

[Note: In a derived class, the lookup of a base class name
will find the injected-class-name instead of the name of the base
class in the scope in which it was declared. The
injected-class-name might be less accessible than the name of the
base class in the scope in which it was declared.] [Example:

273.
POD classes and operator&()

I think that the definition of a POD class in the current version
of the Standard is overly permissive in that it allows for POD classes
for which a user-defined operator function operator& may
be defined. Given that the idea behind POD classes was to achieve
compatibility with C structs and unions, this makes 'Plain old'
structs and unions behave not quite as one would expect them to.

In the C language, if x and y are variables of
struct or union type S that has a member m, the
following expression are allowed: &x, x.m, x
= y. While the C++ standard guarantees that if x and
y are objects of a POD class type S, the expressions
x.m, x = y will have the same effect as they would
in C, it is still possible for the expression &x to be
interpreted differently, subject to the programmer supplying an
appropriate version of a user-defined operator function
operator& either as a member function or as a non-member
function.

For any complete POD object type T, whether or not the object
holds a valid value of type T, the underlying bytes
(1.7 [intro.memory]) making up the object can be copied into
an array of char or unsigned char [footnote:
By using, for example, the library functions (17.6.1.2 [headers]) memcpy or memmove]. If the
content of the array of char or unsigned char is
copied back into the object, the object shall subsequently hold its
original value. [Example:

#define N sizeof(T)
char buf[N];
T obj; // obj initialized to its original value
memcpy(buf, &obj, N);
// between these two calls to memcpy,
// obj might be modified
memcpy(&obj, buf, N);
// at this point, each subobject of obj of scalar type
// holds its original value

—end example]

Now, supposing that the complete POD object type T in the
example above is POD_bomb, and we cannot any more count on
the assertions made in the comments to the example. Given a standard
conforming implementation, the code will not even compile. And I see
no legal way of copying the contents of an object of a complete object
type POD_bomb into an array of char or unsigned
char with memcpy or memmove without making use
of the unary & operator. Except, of course, by means of
an ugly construct like:

The fact that the definition of a POD class allows for POD classes
for which a user-defined operator& is defined, may also
present major obstacles to implementers of the offsetof macro from
<cstddef>

18.2 [support.types] paragraph 5 says:

The macro offsetof accepts a restricted set of type arguments
in this International Standard. type shall be a POD structure
or a POD union (clause 9 [class]). The result of
applying the offsetof macro to a field that is a static data
member or a function is undefined."

A consensus was forming around the idea of disallowing
operator& in POD classes when it was noticed that it is
permitted to declare global-scope operator& functions,
which cause the same problems. After more discussion, it was
decided that such functions should not be prohibited in POD classes,
and implementors should simply be required to "get the right answer"
in constructs such as offsetof and va_start that
are conventionally implemented using macros that use the "&"
operator. It was noted that one can cast the original operand to
char & to de-type it, after which one can use the
built-in "&" safely.

Proposed resolution:

Add a footnote in 18.2 [support.types] paragraph 5:

[Footnote: Note that offsetof is required to
work as specified even if unary operator& is
overloaded for any of the types involved.]

Add a footnote in 18.10 [support.runtime] paragraph 3:

[Footnote: Note that va_start is required to
work as specified even if unary operator& is
overloaded for the type of parmN.]

284.
qualified-ids in class declarations

Although 8.3 [dcl.meaning] requires that a declaration of
a qualified-id refer to a member of the specified namespace or
class and that the member not have been introduced by a
using-declaration, it applies only to names declared in a
declarator. It is not clear whether there is existing wording
enforcing the same restriction for qualified-ids in
class-specifiers and elaborated-type-specifiers or
whether additional wording is required. Once such wording is
found/created, the proposed resolution of
issue 275 must be modified accordingly.

Notes from 10/01 meeting:

The sentiment was that this should be required on class definitions, but
not on elaborated type specifiers in general (which are references, not
declarations). We should also make sure we consider explicit instantiations,
explicit specializations, and friend declarations.

Proposed resolution (10/01):

Add after the end of 9.1 [class.name] paragraph 3:

When a nested-name-specifier is specified in a
class-head or in an
elaborated-type-specifier, the resulting qualified name
shall refer to a previously declared member of the class or namespace to
which the nested-name-specifier refers, and
the member shall not have been introduced by a
using-declaration in the scope of the class or namespace
nominated by the nested-name-specifier.

327.
Use of "structure" without definition

In 9 [class] paragraph 4, the first sentence says
"A structure is a class
definition defined with the class-keystruct".
As far as I know,
there is no such thing as a structure in C++; it certainly isn't
listed as one of the possible compound types in 3.9.2 [basic.compound].
And defining structures opens the question of whether a forward
declaration is a structure or not. The parallel here with union
(which follows immediately) suggests that structures and classes are
really different things, since the same wording is used, and classes
and unions do have some real differences, which manifest themselves
outside of the definition. It also suggests that since one can't
forward declare union with class and vice versa, the same should
hold for struct and class -- I believe that the intent was that one
could use struct and class interchangeably in forward declaration.

Suggested resolution:

I suggest something like the following:

If a class is defined with the class-keyclass, its members and
base classes are private by default. If a class is defined with
the class-keystruct,
its members and base classes are public by
default. If a class is defined with the class-keyunion, its
members are public by default, and it holds only one data member
at a time. Such classes are called unions, and obey a number of
additional restrictions, see 9.5 [class.union].

379.
Change "class declaration" to "class definition"

The ARM used the term "class declaration" to refer to what
would usually be termed the definition of the class. The standard
now often uses "class definition", but there are some surviving uses
of "class declaration" with the old meaning. They should be found
and changed.

Proposed resolution (April 2003):

Replace in 3.1 [basic.def] paragraph 2

A declaration is a definition unless it declares a function
without specifying the function's body
(8.4 [dcl.fct.def]), it contains the
extern specifier (7.1.1 [dcl.stc]) or
a linkage-specification
[Footnote: Appearing inside the braced-enclosed
declaration-seq in a linkage-specification does not
affect whether a declaration is a definition. --- end
footnote]
(7.5 [dcl.link]) and neither an
initializer nor a function-body, it declares a static
data member in a class declarationdefinition
(9.4 [class.static]), it is a class name
declaration (9.1 [class.name]), or it is
a typedef declaration
(7.1.3 [dcl.typedef]), a
using-declaration
(7.3.3 [namespace.udecl]), or a
using-directive
(7.3.4 [namespace.udir]).

Replace in 7.1.2 [dcl.fct.spec] paragraphs 5 and 6

The virtual specifier shall only be used in declarations of
nonstatic class member functions that appear within a
member-specification of a class declarationdefinition; see
10.3 [class.virtual].

The explicit specifier shall be used only in declarations of
constructors within a class declarationdefinition; see
12.3.1 [class.conv.ctor].

Replace in 7.1.3 [dcl.typedef] paragraph 4

A
typedef-name
that names a class is a
class-name
(9.1 [class.name]).
If a typedef-name is used following the class-key
in an elaborated-type-specifier
(7.1.6.3 [dcl.type.elab]) or in the
class-head
of a class declarationdefinition
(9 [class]),
or is used as the identifier in the declarator for a
constructor or destructor declaration
(12.1 [class.ctor],
12.4 [class.dtor]), the program is ill-formed.

Replace in 7.3.1.2 [namespace.memdef] paragraph 3

The name of the friend is not found by simple name lookup until a
matching declaration is provided in that namespace scope (either
before or after the class declarationdefinition granting friendship).

Replace in 8.3.2 [dcl.ref] paragraph 4

There shall be no references to references, no arrays of references,
and no pointers to references. The declaration of a reference shall
contain an initializer
(8.5.3 [dcl.init.ref]) except when
the declaration contains an explicit extern specifier
(7.1.1 [dcl.stc]), is a class member
(9.2 [class.mem]) declaration within a
class declarationdefinition, or is the
declaration of a parameter or a return type
(8.3.5 [dcl.fct]); see
3.1 [basic.def].

Replace in 8.5.3 [dcl.init.ref] paragraph 3

The initializer can be omitted for a reference only in a parameter
declaration (8.3.5 [dcl.fct]), in the
declaration of a function return type, in the declaration of a class
member within its class declarationdefinition
(9.2 [class.mem]), and where the
extern specifier is explicitly used.

Replace in 9.1 [class.name] paragraph 2

A class definitiondeclaration introduces the
class name into the scope where it is defineddeclared and hides any class, object, function, or other
declaration of that name in an enclosing scope
(3.3 [basic.scope]). If a class name
is declared in a scope where an object, function, or enumerator of the
same name is also declared, then when both declarations are in scope,
the class can be referred to only using an
elaborated-type-specifier
(3.4.4 [basic.lookup.elab]).

Replace in 9.4 [class.static] paragraph 4

Static members obey the usual class member access rules (clause
11 [class.access]). When used
in the declaration of a class member, the static specifier
shall only be used in the member declarations that appear within the
member-specification of the class declarationdefinition.

Replace in 9.7 [class.nest] paragraph 1

A class can be defineddeclared within another
class. A class defineddeclared within
another is called a nested class. The name of a nested class
is local to its enclosing class. The nested class is in the scope of
its enclosing class. Except by using explicit pointers, references,
and object names, declarations in a nested class can use only type
names, static members, and enumerators from the enclosing class.

Replace in 9.8 [class.local] paragraph 1

A class can be defineddeclared within a
function definition; such a class is called a local class. The
name of a local class is local to its enclosing scope. The local
class is in the scope of the enclosing scope, and has the same access
to names outside the function as does the enclosing function.
Declarations in a local class can use only type names, static
variables, extern variables and functions, and enumerators
from the enclosing scope.

Replace in 10 [class.derived] paragraph 1

... The class-name in a base-specifier shall not be an
incompletely defined class (clause 9 [class]);
this class is called a
directbaseclass for the class being
declareddefined. During the lookup for a
base class name, non-type names are ignored
(3.3.10 [basic.scope.hiding]).
If the name found is not a class-name, the program is ill-formed.
A class B is a base class of a class D if it is a
direct base class of D or a direct base class of one of
D's base classes. A class is an indirect base class
of another if it is a base class but not a direct base class. A class
is said to be (directly or indirectly) derived from its (direct
or indirect) base classes. [Note: See clause
11 [class.access]
for the meaning of access-specifier.] Unless
redefinedredeclared in the
derived class, members of a base class are also considered to be
members of the derived class. The base class members are said to be
inherited by the derived class. Inherited members can be
referred to in expressions in the same manner as other members of the
derived class, unless their names are hidden or ambiguous
(10.2 [class.member.lookup]).
[Note: the scope resolution operator ::
(5.1.1 [expr.prim.general])
can be used to refer to a direct or indirect base member explicitly.
This allows access to a name that has been redefinedredeclared in the derived class. A derived class can itself
serve as a base class subject to access control; see
11.2 [class.access.base].
A pointer to a derived class can be implicitly converted to a pointer
to an accessible unambiguous base class
(4.10 [conv.ptr]).
An lvalue of a derived class type can be bound to a reference to an
accessible unambiguous base class
(8.5.3 [dcl.init.ref]).]

for an object c of class type C, a single subobject
of type V is shared by every base subobject of c
that is declared to havehas a
virtual base class of type V.

Replace in the example in 10.2 [class.member.lookup]
paragraph 6 (the whole paragraph was turned into a note by the
resolution of core issue 39)

The names defineddeclared in V and
the left hand instance of W are hidden by those in
B, but the names defineddeclared in
the right hand instance of W are not hidden at all.

Replace in 10.4 [class.abstract] paragraph 2

... A virtual function is specified pure by using a
pure-specifier (9.2 [class.mem])
in the function declaration in the class declarationdefinition. ...

Replace in the footnote at the end of 11.2 [class.access.base]
paragraph 1

[Footnote: As specified previously in clause
11 [class.access], private members of
a base class remain inaccessible even to derived classes unless
friend declarations within the base class
declarationdefinition are used to grant access
explicitly.]

Replace in 11.3 [class.access.dcl] paragraph 1

The access of a member of a base class can be changed in the derived
class by mentioning its qualified-id in the derived class
declarationdefinition. Such mention is
called an accessdeclaration. ...

Replace in the example in 13.4 [over.over] paragraph 5

The initialization of pfe is ill-formed because no
f() with type int(...) has been
defineddeclared, and not because of any
ambiguity.

Replace in C.1.5 [diff.dcl] paragraph 1

Rationale: Storage class specifiers don't have any meaning when
associated with a type. In C++, class members can be
defineddeclared with the static
storage class specifier. Allowing storage class specifiers on type
declarations could render the code confusing for users.

Replace in C.1.7 [diff.class] paragraph 3

In C++, a typedef name may not be redefinedredeclared in a class
declarationdefinition after being used in the
declarationthat definition

383.
Is a class with a declared but not defined destructor a POD?

The standard (9 [class] par. 4) says that
"A POD-struct is an aggregate class
that has no non-static data members of type non-POD-struct,
non-POD-union (or array of such types) or reference, and has no
user-defined copy assignment operator and no user-defined destructor."

Note that it says 'user-defined', not 'user-declared'. Is it the
intent that if e.g. a copy assignment operator is declared but not
defined, this does not (per se) prevent the class to be a POD-struct?

Proposed resolution (April 2003):

Replace in 9 [class] paragraph 4

A POD-struct is an aggregate class that has no non-static data
members of type non-POD-struct, non-POD-union (or array of such types)
or reference, and has no user-defineddeclared
copy assignment operator and no user-defineddeclared destructor. Similarly, a POD-union is an
aggregate union that has no non-static data members of type
non-POD-struct, non-POD-union (or array of such types) or reference,
and has no user-defineddeclared copy
assignment operator and no user-defineddeclared destructor.

Drafting note: The changes are shown relative to TC1, incorporating
the changes from the resolution of
core issue 148.

413.
Definition of "empty class"

The proposal says that value is true if "T is an empty class (10)".
Clause 10 doesn't define an empty class, although it has a note that
says a base class may "be of zero size (clause 9)" 9/3 says "Complete
objects and member subobjects of class type shall have nonzero size."
This has a footnote, which says "Base class subobjects are not so
constrained."

The standard uses the term "empty class" in two places
(8.5.1 [dcl.init.aggr]), but neither of
those places defines it. It's also listed in the index, which refers to
the page that opens clause 9, i.e. the nonzero size stuff cited above.

So, what's the definition of "empty class" that determines whether the
predicate is_empty is true?

The one place where it's used is
8.5.1 [dcl.init.aggr] paragraph 8, which says (roughly paraphrased)
that an aggregate initializer for an empty class must be "{}", and when
such an initializer is used for an aggregate that is not an empty class the
members are default-initialized. In this context it's pretty clear what's
meant. In the type traits proposal it's not as clear, and it was probably
intended to have a different meaning. The boost implementation, after it
eliminates non-class types, determines whether the trait is true by
comparing the size of a class derived from T to the size of an
otherwise-identical class that is not derived from T.

Howard Hinnant:is_empty was created to find out whether a type could be derived from
and have the empty base class optimization successfully applied. It
was created in part to support compressed_pair which attempts to
optimize away the space for one of its members in an attempt to reduce
spatial overhead. An example use is:

Here the compare function is optimized away via the empty base
optimization if Compare turns out to be an "empty" class. If Compare
turns out to be a non-empty class, or a function pointer, the space is
not optimized away. is_empty is key to making this work.

Clark Nelson:
I've been looking at issue 413, and I've reached the conclusion that
there are two different kinds of empty class. A class containing only
one or more anonymous bit-field members is empty for purposes of
aggregate initialization, but not (necessarily) empty for purposes of
empty base-class optimization.

Of course we need to add a definition of emptiness for purposes of
aggregate initialization. Beyond that, there are a couple of questions:

Should the definition of emptiness used by the is_empty predicate be
defined in a language clause or a library clause?

Do we need to open a new core issue pointing out the fact that the
section on aggregate initialization does not currently say that unnamed
bit-fields are skipped?

Notes from the October, 2005 meeting:

There are only two places in the Standard where the phrase
“empty class” appears, both in 8.5.1 [dcl.init.aggr] paragraph 8. Because it is not clear whether the
definition of “empty for initialization purposes” is
suitable for use in defining the is_empty predicate, it would
be better just to avoid using the phrase in the language clauses. The
requirements of 8.5.1 [dcl.init.aggr] paragraph 8 appear to be
redundant; paragraph 6 says that an initializer-list must have
no more initializers than the number of elements to initialize, so an
empty class already requires an empty initializer-list, and
using an empty initializer-list with a non-empty class is
covered adequately by paragraph 7's description of the handling of an
initializer-list with fewer initializers than the
number of members to initialize.

Here, the second initializer 2 initializes a.j and not the
static data member A::s, and the third initializer 3
initializes a.k and not the padding before it.
—end example]

Delete 8.5.1 [dcl.init.aggr] paragraph 8:

An initializer for an aggregate member that is an empty
class shall have the form of an empty initializer-list{}. [Example:

struct S { };
struct A {
S s;
int i;
} a = { { } , 3 };

—end example] An empty initializer-list can be used to
initialize any aggregate. If the aggregate is not an empty class, then
each member of the aggregate shall be initialized with a value of the
form T() (5.2.3 [expr.type.conv]), where T
represents the type of the uninitialized member.

Deleting 8.5.1 [dcl.init.aggr] paragraph 8 altogether may
not be a good idea. It would appear that, in its absence, the
initializer elision rules of paragraph 11 would allow the initializer
for a in the preceding example to be written { 3 }
(because the empty-class member s would consume no
initializers from the list).

Proposed resolution (October, 2006):

(Drafting note: this resolution also cleans up incorrect
references to syntactic non-terminals in the nearby paragraphs.)

Change 8.5.1 [dcl.init.aggr] paragraph 4 as indicated:

An array of unknown size initialized with a brace-enclosed
initializer-list containing ninitializersinitializer-clauses, where n shall be greater
than zero... An empty initializer list {} shall not be used as the
initializerinitializer-clause for an array of
unknown bound.

Here, the second initializer 2 initializes a.j
and not the static data member A::s, and the third
initializer 3 initializes a.k and not the anonymous
bit field before it. —end example]

Change 8.5.1 [dcl.init.aggr] paragraph 6 as indicated:

An initializer-list is ill-formed if the number of
initializersinitializer-clauses
exceeds the number of members...

Change 8.5.1 [dcl.init.aggr] paragraph 7 as indicated:

If there are fewer initializersinitializer-clauses in the list than there are members...

Replace 8.5.1 [dcl.init.aggr] paragraph 8:

An initializer for an aggregate member that is an empty
class shall have the form of an empty initializer-list{}. [Example:

struct S { };
struct A {
S s;
int i;
} a = { { } , 3 };

—end example] An empty initializer-list can be used to
initialize any aggregate. If the aggregate is not an empty class, then
each member of the aggregate shall be initialized with a value of the
form T() (5.2.3 [expr.type.conv]), where T
represents the type of the uninitialized member.

with:

If an aggregate class C contains a subaggregate
member m that has no members for purposes of aggregate
initialization, the initializer-clause for m shall not
be omitted from an initializer-list for an object of type
C unless the initializer-clauses for all members
of C following m are also omitted. [Example:

When initializing a multi-dimensional array, the initializersinitializer-clauses initialize the elements...

Change 8.5.1 [dcl.init.aggr] paragraph 11 as indicated:

Braces can be elided in an initializer-list as follows. If the
initializer-list begins with a left brace, then the succeeding
comma-separated list of initializersinitializer-clauses initializes the members of a
subaggregate; it is erroneous for there to be more initializersinitializer-clauses than members. If, however,
the initializer-list for a subaggregate does not begin with a
left brace, then only enough initializersinitializer-clauses from the list are taken to
initialize the members of the subaggregate; any
remaining initializersinitializer-clauses
are left to initialize the next member of the aggregate of which the
current subaggregate is a member. [Example:...

Change 8.5.1 [dcl.init.aggr] paragraph 12 as indicated:

All implicit type conversions (clause 4 [conv]) are
considered when initializing the aggregate member with an initializer
from an initializer-listassignment-expression. If
the initializerassignment-expression can
initialize a member, the member is initialized. Otherwise, if the
member is itself a non-empty subaggregate, brace elision is
assumed and the initializerassignment-expression is considered for the
initialization of the first member of the
subaggregate. [Note: As specified above, brace elision
cannot apply to subaggregates with no members for purposes of
aggregate initialization; an initializer-clause for the entire
subobject is required. —end note]
[Example:... Braces are elided around
the initializerinitializer-clause for
b.a1.i...

Change 8.5.1 [dcl.init.aggr] paragraph 15 as indicated:

When a union is initialized with a brace-enclosed initializer, the
braces shall only contain an initializerinitializer-clause for the first member of the
union...

Change 8.5.1 [dcl.init.aggr] paragraph 16 as indicated:

[Note:asAs described above, the braces around
the initializerinitializer-clause for a union
member can be omitted if the union is a member of another
aggregate. —end note]

There are several problems with the terms defined in
9 [class] paragraph 4:

A structure is a class defined with
the class-keystruct; its members and base classes
(clause 10 [class.derived]) are public by default (clause
11 [class.access]). A union is a class defined with the
class-keyunion; its members are public by default and
it holds only one data member at a time (9.5 [class.union]). [Note: aggregates of class type are described
in 8.5.1 [dcl.init.aggr]. —end note]
A POD-struct is an aggregate class that has no non-static data
members of type non-POD-struct, non-POD-union (or array of such types)
or reference, and has no user-declared copy assignment operator and no
user-declared destructor. Similarly, a POD-union is an
aggregate union that has no non-static data members of type
non-POD-struct, non-POD-union (or array of such types) or reference,
and has no user-declared copy assignment operator and no user-declared
destructor. A POD class is a class that is either a POD-struct
or a POD-union.

Although the term structure is defined here, it is
used only infrequently throughout the Standard, often apparently
inadvertently and consequently incorrectly:

5.2.5 [expr.ref] paragraph 4: the use is in a
note and is arguably correct and helpful.

9.2 [class.mem] paragraph 11: the term is used
(three times) in an example. There appears to be no reason to use
it instead of “class,” but its use is not
problematic.

17.3 [definitions] “iostream class templates:”
the traits argument
to the iostream class templates is (presumably unintentionally)
constrained to be a structure, i.e., to use the struct
keyword and not the class keyword in its definition.

B [implimits] paragraph 2: the minimum number of
declarator operators is given for structures and unions but not
for classes defined using the class keyword.

B [implimits] paragraph 2: class, structure,
and union are used as disjoint terms in describing nesting
levels. (The nonexistent nonterminal struct-declaration-list
is used, as well.)

There does not appear to be a reason for defining the term
structure. The one reference where it is arguably useful,
in the note in 5.2.5 [expr.ref], could be rewritten
as something like, “'class objects' may be defined using the
class, struct, or unionclass-keys; see clause 9 [class].”

Based on its usage later in the paragraph and elsewhere,
“POD-struct” appears to be intended to exclude unions.
However, the definition of “aggregate class” in
8.5.1 [dcl.init.aggr] paragraph 1 includes unions.
Furthermore, the name itself is confusing, leading to the question of
whether it was intended that only classes defined
using struct could be POD-structs or
if class-classes are included. The definition should
probably be rewritten as, “A POD-struct is an aggregate
class defined with the class-keystruct or
the class-keyclass that has no...

In most references outside clause 9 [class],
POD-struct and POD-union are mentioned together and treated
identically. These references should be changed to refer to the
unified term, “POD class.”

Noted in passing: 18.2 [support.types] paragraph 4
refers to the undefined terms “POD structure” and
(unhyphenated) “POD union;” the pair should be replaced
by a single reference to “POD class.”

Proposed resolution (April, 2006):

Change 9 [class] paragraph 4 as indicated:

A structure is a class defined with
the class-keystruct; its members and base classes
(clause 10 [class.derived]) are public by default (clause
11 [class.access]). A union is a class defined with the
class-keyunion; its members are public by default
and it holds only one data member at a time (9.5 [class.union]). [Note: aggregates of class type are described
in 8.5.1 [dcl.init.aggr]. —end note]
A POD-struct is an aggregate class that has no non-static
data members of type non-POD-struct, non-POD-union (or array of such
types) or reference, and has no user-declared copy assignment operator
and no user-declared destructor. Similarly, a POD-union is an
aggregate union that has no non-static data members of type
non-POD-struct, non-POD-union (or array of such types) or reference,
and has no user-declared copy assignment operator and no user-declared
destructor. A POD class is a class that is either a POD-struct
or a POD-union.A POD class is an aggregate class that
has no non-static data members of non-POD type (or array of such a
type) or reference, and has no user-declared copy assignment operator
and no user-declared destructor. A POD-struct is a POD class
defined with the class-keystruct or
the class-keyclass. A POD-union is a POD class
defined with the class-keyunion.

Change 11.2 [class.access.base] paragraph 2 as indicated:

In the absence of an access-specifier for a base
class, public is assumed when the derived class is
declareddefined with
the class-keystruct and private is
assumed when the class is declareddefined with the
class-keyclass. [Example:...

568.
Definition of POD is too strict

[Voted into the WP at the July, 2007 meeting as part of paper
J16/07-0202 = WG21 N2342.]

A POD struct (9 [class] paragraph 4) is “an
aggregate class that has no non-static data members of type
non-POD-struct, non-POD-union (or array of such types), or reference,
and that has no user-defined copy assignment operator and no
user-defined destructor.” Meanwhile, an aggregate class
(8.5.1 [dcl.init.aggr] paragraph 1) must have “no
user-declared constructors, no private or protecte non-static data
members, no base classes, and no virtual functions.”

This is too strict. The whole reason we define the notion of POD is
for the layout compatibility guarantees in 9.2 [class.mem]
paragraphs 14-17 and the byte-for-byte copying guarantees of
3.9 [basic.types] paragraph 2. None of those guarantees
should be affected by the presence of ordinary constructors, any more
than they're affected by the presence of any other member
function. It’s silly for the standard to make layout and memcpy
guarantees for this class:

struct A {
int n;
};

but not for this one:

struct B {
int n;
B(n_) : n(n_) { }
};

With either A or B, it ought to be possible to
save an array of those objects to disk with a single call to
Unix’s write(2) system call or the equivalent. At present the
standard says that it’s legal for A but not B,
and there isn’t any good reason for that distinction.

Suggested resolution:

The following doesn’t fix all problems (in particular it
still doesn’t let us treat pair<int, int> as a
POD), but at least it goes a long way toward fixing the problem: in
8.5.1 [dcl.init.aggr] paragraph 1, change “no
user-declared constructors” to “no nontrivial default
constructor and no user-declared copy constructor.”

(Yes, I’m aware that this proposed change would also allow
brace initialization for some types that don't currently allow it. I
consider this to be a feature, not a bug.)

Mike Miller: I agree that something needs to be done about
“POD,” but I’m not sure that this is it. My own
take is that “POD” is used for too many different things
— things that are related but not identical — and the
concept should be split. The current definition is useful, as is, for
issues regarding initialization and lifetime. For example, I
wouldn’t want to relax the prohibition of jumping over a
constructor call in 6.7 [stmt.dcl] (which is currently
phrased in terms of POD types). On the other hand, I agree that the
presence of a user-declared constructor says nothing about layout and
bitwise copying. This needs (IMHO) a non-trivial amount of further
study to determine how many categories we need (instead of just POD
versus non-POD), which guarantees and prohibitions go with which
category, the interaction of “memcpy initialization” (for
want of a better term) with object lifetime, etc.

417.
Using derived-class qualified name in out-of-class nested class definition

We had a user complain that our compiler was allowing the
following code:

struct B {
struct S;
};
struct D : B { };
struct D::S {
};

We took one look at the code and made the reasonable (I would claim)
assumption that this was
indeed a bug in our compiler. Especially as we had just fixed a very
similar issue with the
definition of static data members.

Imagine our surprise when code like this showed up in Boost and that
every other compiler we tested accepts this code. So is this
indeed legal (it seems like
it must be) and if so is there any justification for this beyond
3.4.3.1 [class.qual]?

John Spicer:
The equivalent case for a member function is covered by the declarator
rules in 8.3 [dcl.meaning] paragraph 1. The committee has
previously run into cases where a restriction should apply to both
classes and non-classes, but fails to do so because there is no
equivalent of 8.3 [dcl.meaning] paragraph 1 for classes.

Given that, by the letter of the standard, I would say that this
case is allowed.

Add the following as a new paragraph immediately following
3.3.2 [basic.scope.pdecl] paragraph 2:

The point of declaration for a class first declared by a
class-specifier is
immediately after the identifier
or template-id (if any) in its class-head
(Clause 9 [class]).
The point of declaration for an enumeration is immediately after
the identifier (if any) in its enum-specifier
(7.2 [dcl.enum]).

Change point 1 of 3.3.7 [basic.scope.class] paragraph 1 to read:

The potential scope of a name declared in a class consists not only of the
declarative region following the name's
declaratorpoint of declaration, but also
of all function bodies, default arguments, and constructor
ctor-initializers in that
class (including such things in nested classes).

[Note that the preceding change duplicates one of the changes
in the proposed resolution of issue 432.]

Change 14.7.2 [temp.explicit] paragraph 2 to read:

If the explicit instantiation is for a member function, a member
class or a static
data member of a class template specialization, the name of
the class template
specialization in the qualified-id for the member declaratorname shall be a template-id.

Add the following as paragraph 5 of Clause 9 [class]:

If a class-head contains a nested-name-specifier,
the class-specifier shall refer to a
class that was previously declared directly in the class or namespace
to which the nested-name-specifier refers (i.e., neither
inherited nor introduced by a using-declaration),
and the class-specifier shall appear in a namespace enclosing the
previous declaration.

When a nested-name-specifier is specified in a
class-head or in an
elaborated-type-specifier, the resulting qualified name
shall refer to a previously declared member of the class or namespace to
which the nested-name-specifier refers, and
the member shall not have been introduced by a
using-declaration in the scope of the class or namespace
nominated by the nested-name-specifier.

328.
Missing requirement that class member types be complete

Is it legal to use an incomplete type (3.9 [basic.types]
paragraph 6) as a
class member, if no object of such class is ever created ?

And as a class template member, even if the template is instantiated,
but no object of the instantiated class is created?

The consensus seems to be NO, but no wording was found in the standard
which explicitly disallows it.

The problem seems to be that most of the restrictions on incomplete types
are on their use in objects, but class members are not objects.

A possible resolution, if this is considered a defect, is to add to
3.2 [basic.def.odr] paragraph 4, (situations when T must be complete),
the use of T as a member of a class or instantiated class template.

The thread on comp.std.c++ which brought up the issue was
"Compiler differences: which is correct?", started 2001 11 30.
<3c07c8fb$0$8507$ed9e5944@reading.news.pipex.net>

Proposed Resolution (April 2002, revised April 2003):

Change the first bullet of the note in 3.2 [basic.def.odr]
paragraph 4 and add two new bullets following it, as follows:

an object of type T is defined
(3.1 [basic.def], 5.3.4 [expr.new]), or

a non-static class data member of type T is declared
(9.2 [class.mem]), or

T is used as the object type or array element type
in a new-expression (5.3.4 [expr.new]), or

Replace 9.2 [class.mem] paragraph 8 by:

Non-static (9.4 [class.static]) data members shall
not have incomplete types.
In particular, a class C shall not contain a non-static
member of class C, but it can contain a pointer or reference to
an object of class C.

See also 3.9 [basic.types] paragraph 6, which is relevant
but not changed by the Proposed Resolution.

437.
Is type of class allowed in member function exception specification?

The compiler is complaining that Foo is an incomplete type, and can't be
used in the exception specification.

My reading of the standard [basic.types] is inconclusive. Although it
does state that the class declaration is considered complete when the
closing brace is read, I believe it also intends that the member
function declarations should not be semantically validated until the
class has been completely declared.

If this isn't allowed, I don't know how else a member function could be
declared to throw an object of its own class.

John Spicer:
The type is considered complete within function bodies, but not in their
declaration (see 9.2 [class.mem] paragraph 2).

Proposed Resolution:

Change 9.2 [class.mem] paragraph 2 as follows:

Within the class member-specification, the class is regarded
as complete within function bodies, default arguments,
exception-specifications, and constructor
ctor-initializers (including such things in nested classes).

Rationale: Taken with 8.3.5 [dcl.fct] paragraph 6, the
exception-specification is the only part of a function
declaration/definition in which the class name cannot be used because
of its putative incompleteness. There is no justification for
singling out exception specifications this way; both in the function
body and in a catch clause, the class type will be complete,
so there is no harm in allowing the class name to be used in the
exception-specification.

613.
Unevaluated uses of non-static class members

According to 9.2 [class.mem] paragraph 9, the name of a
non-static data member can only be used with an object reference
(explicit or implied by the this pointer of a non-static
member function) or to form a pointer to member. This restriction
applies even in the operand of sizeof, although the
operand is not evaluated and thus no object is needed to perform the
operation. Consequently, determining the size of a non-static class
member often requires a circumlocution like

sizeof((C*) 0)->m

instead of the simpler and more obvious (but incorrect)

sizeof(C::m)

The CWG considered this question as part of
issue 198 and decided at that time to
retain the restriction on consistency grounds: the rule was
viewed as applying uniformly to expressions, and making an
exception for sizeof would require introducing a
special-purpose “wart.”

The issue has recently resurfaced, in part due to the fact that
the restriction would also apply to the decltype operator.
Like the unary & operator to form a pointer to member,
sizeof and decltype need neither an lvalue nor
an rvalue, requiring solely the declarative information of the
named operand. One possible approach would be to define the concept
of “unevaluated operand” or the like, exempt unevaluated
operands from the requirement for an object reference in
9.2 [class.mem] paragraph 9, and then define the operands
of these operators as “unevaluated.”

620.
Declaration order in layout-compatible POD structs

[Voted into the WP at the July, 2007 meeting as part of paper
J16/07-0202 = WG21 N2342.]

It should be made clear in 9.2 [class.mem] paragraph 15,

Two POD-struct (clause 9 [class]) types are
layout-compatible if they have the same number of non-static data
members, and corresponding non-static data members (in order) have
layout-compatible types (3.9 [basic.types]).

that “corresponding... (in order)” refers to declaration
order and not the order in which the members are laid out in memory.

However, this raises the point that, in cases where an
access-specifier is involved, the declaration and layout
order can be different (see paragraph 12). Thus, for two POD-struct
classes A and B,

struct A {
char c;
int i;
}
struct B {
char c;
public:
int i;
};

a compiler could move B::i before B::c, but
A::c must precede A::i. It does not seem
reasonable that these two POD-structs would be considered
layout-compatible, even though they satisfy the requirement that
corresponding members in declaration order are layout-compatible.

One possibility would be to require that neither POD-struct have
an access-specifier in order to be considered
layout-compatible. (It's not sufficient to require that they have
the same access-specifiers, because the compiler is not
required to lay out the storage the same way for different classes.)

8.5.1 [dcl.init.aggr] paragraph 2 should also be clarified
to make explicit that “increasing... member order” refers
to declaration order.

Proposed resolution (April, 2007):

This issue will be resolved by the adoption of the POD proposal
(currently J16/07-0090 = WG21 N2230). That paper does not propose
a change to the wording of 8.5.1 [dcl.init.aggr] paragraph 2,
but the CWG feels that the intent of that paragraph (that the
initializers are used in declaration order) is clear enough not to
require revision.

452.
Wording nit on description of this

9.3.2 [class.this] paragraph 1, which specifies the
meaning of the
keyword 'this', seems to limit its usage to the *body* of non-static
member functions. However 'this' is also usable in ctor-initializers
which, according to the grammar in
8.4 [dcl.fct.def] par. 1, are not
part of the body.

Proposed resolution: Changing the first part of
9.3.2 [class.this] par. 1 to:

In the body of a nonstatic (9.3) member function or in a
ctor-initializer (12.6.2), the keyword this is a non-lvalue
expression whose value is the address of the object for which
the function is called.

NOTE: I'm talking of constructors as functions that are "called";
there have been discussions on c.l.c++.m as to whether constructors
are "functions" and to whether this terminology is correct or not; I
think it is both intuitive and in agreement with the standard wording.

Steve Adamczyk: See also issue 397,
which is defining a new syntax term for the body of a function
including the ctor-initializers.

An informal reference to the body of a function should be
interpreted as a reference to the nonterminal function-body.

Change the definition of function-try-block in
15 [except] paragraph 1:

function-try-block:

try ctor-initializeroptfunction-bodycompound-statement handler-seq

Change 3.3.7 [basic.scope.class] paragraph 1, point 1, as
indicated:

The potential scope of a name declared in a class consists not only of
the declarative region following the name's point of declaration, but
also of all function bodies,bodies and default
arguments, and constructor ctor-initializers in that
class (including such things in nested classes).

Change 3.3.7 [basic.scope.class] paragraph 1, point 5, as
indicated:

The potential scope of a declaration that extends to or past the end
of a class definition also extends to the regions defined by its
member definitions, even if the members are defined lexically outside
the class (this includes static data member definitions, nested class
definitions, member function definitions (including the member
function body and, for constructor functions (12.1 [class.ctor]), the ctor-initializer (12.6.2 [class.base.init]))
and any portion of the declarator part of such definitions which
follows the identifier, including a parameter-declaration-clause
and any default arguments (8.3.6 [dcl.fct.default]).
[Example:...

That is, an unqualified name that occurs, for instance, in a type or
default argument expression in the parameter-declaration-clause,parameter-declaration-clause or in the function body,
or in an expression of a mem-initializer in a constructor
definition.

Change 5.1.1 [expr.prim.general] paragraph 3 as indicated:

...The keyword this shall be used only inside a non-static
class member function body (9.3 [class.mfct]) or in a
constructor mem-initializer (12.6.2 [class.base.init])...

Change 9.2 [class.mem] paragraph 2 as indicated:

...Within the class member-specification, the class is regarded as
complete within function bodies, default arguments, andexception-specifications, and constructor
ctor-initializers (including such things in nested classes)...

Change 9.2 [class.mem] paragraph 9 as indicated:

Each occurrence in an expression of the name of a non-static data
member or non-static member function of a class shall be expressed as
a class member access (5.2.5 [expr.ref]), except when it
appears in the formation of a pointer to member (5.3.1 [expr.unary.op]), oror when it appears in the body of
a non-static member function of its class or of a class derived from
its class (9.3.1 [class.mfct.non-static]), or when it appears in
a mem-initializer for a constructor for its class or for a
class derived from its class (12.6.2 [class.base.init]).

Change the note in 9.3 [class.mfct] paragraph 5 as
indicated:

[Note: a name used in a member function definition (that is, in the
parameter-declaration-clause including the default arguments
(8.3.6 [dcl.fct.default]), oror in the member
function body, or, for a constructor function (12.1 [class.ctor]), in a mem-initializer expression (12.6.2 [class.base.init])) is looked up as described in 3.4 [basic.lookup]. —end note]

Change 9.3.1 [class.mfct.non-static] paragraph 1 as indicated:

...A non-static member function may also be called directly using
the function call syntax (5.2.2 [expr.call], 13.3.1.1 [over.match.call]) from within the body of a member function of its class or of a class derived from its class.

from within the body of a member function of its class or of a
class derived from its class, or

from a mem-initializer (12.6.2 [class.base.init]) for
a constructor for its class or for a class derived from its class.

Change 9.3.1 [class.mfct.non-static] paragraph 3 as indicated:

When an id-expression (5.1.1 [expr.prim.general]) that is not
part of a class member access syntax (5.2.5 [expr.ref])
and not used to form a pointer to member (5.3.1 [expr.unary.op]) is used in the body of a non-static member function
of class Xor used in the mem-initializer for a
constructor of class X, if name lookup (3.4.1 [basic.lookup.unqual]) resolves the name in the id-expression to a
non-static non-type member of class X or of a base class
of X, the id-expression is transformed into a class
member access expression (5.2.5 [expr.ref])
using (*this) (9.3.2 [class.this]) as the
postfix-expression to the left of the . operator...

Change 12.1 [class.ctor] paragraph 7 as indicated:

...The implicitly-defined default constructor performs the set of
initializations of the class that would be performed by a user-written
default constructor for that class with an
empty mem-initializer-listno ctor-initializer (12.6.2 [class.base.init])
and an empty function bodycompound-statement...

Change 12.6.2 [class.base.init] paragraph 4 as indicated:

...After the call to a constructor for class X has completed, if a
member of X is neither specified in the constructor’s
mem-initializers, nor default-initialized, nor
value-initialized, nor given a value during execution
of the compound-statement of the body of the
constructor, the member has indeterminate value.

Change the last bullet of 12.6.2 [class.base.init]
paragraph 5 as indicated:

Finally, the bodycompound-statement of the
constructor body is executed.

Change 15 [except] paragraph 4 as indicated:

A function-try-block associates a handler-seq with the
ctor-initializer, if present, and the function-bodycompound-statement. An exception thrown during the
execution of the initializer expressions in
the ctor-initializer or during the execution of
the function-bodycompound-statement
transfers control to a handler in a
function-try-block in the same way as an exception thrown
during the execution of a try-block transfers control to other
handlers. [Example:

When an exception is thrown, control is transferred to the nearest
handler with a matching type (15.3 [except.handle]);
“nearest” means the handler for which the
compound-statement,compound-statement
orctor-initializer, or function-body following
the try keyword was most recently entered by the thread of
control and not yet exited.

We are not quite sure about what an "unnamed class" is.
There is no exact definition in ISO/IEC 14882; the closest we can come to a
hint is the wording of section 7.1.3 [dcl.typedef]
paragraph 5, where it seems to be understood that a class-specifier with no
identifier between "class" and "{" is unnamed. The identifier provided after
"}" ( "A" in the test case above) is there for "linkage purposes" only.

To us, class B::A in the test program above seems "named"
enough, and there is certainly a mechanism to provide the definition for
B::A::i (in contrast to the note in section 9.4.2 [class.static.data]
paragraph 5).

Our position is therefore that the above test program is
indeed legal C++. Can you confirm or reject this claim?

Herb Sutter replied to the submitter as follows:
Here are my notes based on a grep for
"unnamed class" in the standard:

3.5 [basic.link] paragraph 4, bullet 3, makes a note that
does not directly speak to your question but which draws the same distinction:

a named class (clause class), or an unnamed class defined in a
typedef declaration in which the class has the typedef name for
linkage purposes (7.1.3 [dcl.typedef]);

Likewise in your example, you have an unnamed class defined in a
typedef declaration.

9.4.2 [class.static.data] paragraph 5 does indeed appear to
me to make your example not supported by ISO C++ (although implementations
could allow it as an extension, and many implementation do happen to allow it).

7.1.3 [dcl.typedef] paragraph 5 does indeed likewise confirm
the interpretation you give of an unnamed class.

So yes, an unnamed class is one where there is no identifier (class
name) between the class-key and the {. This is also in harmony with the
production for class-name in 9 [class] paragraph 1:

class-name:

identifiertemplate-id

Notes from the October 2003 meeting:

We agree that the example is not valid; this is an unnamed class.
We will add wording to define an unnamed class. The note in
9.4.2 [class.static.data] paragraph 5 should be corrected
or deleted.

Proposed Resolution (October 2003):

At the end of clause 9 [class],
paragraph 1, add the following:

A class-specifier where the class-head omits
the optional identifier defines an unnamed class.

Delete the following from 9.4.2 [class.static.data] paragraph 5:

[ Note: this is because there is no mechanism to provide the
definitions for such static data members. ]

454.
When is a definition of a static data member required?

As a result of the resolution of core issue 48, the current C++ standard is not in sync with existing
practice and with user expectations as far as definitions of static
data members having const integral or const enumeration type are
concerned. Basically what current implementations do is to require a
definition only if the address of the constant is taken. Example:

To the letter of the standard, though, the above requires a
definition of npos, since the
expression std::string::npos is potentially evaluated. I
think this problem would be easily solved with simple changes to
9.4.2 [class.static.data] paragraph 4, 9.4.2 [class.static.data] paragraph 5 and 3.2 [basic.def.odr] paragraph
3.

Suggested resolution:

Replace 9.4.2 [class.static.data] paragraph 4 with:

If a static data member is of const integral or const enumeration
type, its declaration in the class definition can specify a
constant-initializer which shall be [note1] an integral constant
expression (5.19). In that case, the member can appear in integral
constant expressions. No definition of the member is required, unless
an lvalue expression that designates it is potentially evaluated and
either used as operand to the built-in unary & operator [note 2] or
directly bound to a reference.

If a definition exists, it shall be at namespace scope and shall not
contain an initializer.

In 9.4.2 [class.static.data] paragraph 5 change

There shall be exactly one definition of a static data member that is
used in a program; no diagnostic is required; see 3.2.

to

Except as allowed by 9.4.2 par. 4, there shall be exactly one
definition of a static data member that is potentially evaluated (3.2)
in a program; no diagnostic is required.

In 3.2 [basic.def.odr] paragraph 3 add, at the beginning:

Except for the omission allowed by 9.4.2, par. 4, ...

[note 1] Actually it shall be a "= followed by a constant-expression".
This could probably be an editorial fix, rather than a separate DR.

[note 2] Note that this is the case when reinterpret_cast-ing to a
reference, like in

More information, in response to a question about why
issue 48 does not resolve the problem:

The problem is that the issue was settled in a way that solves much
less than it was supposed to solve; that's why I decided to file, so
to speak, a DR on a DR.

I understand this may seem a little 'audacious' on my part, but please
keep reading. Quoting from the text of DR 48 (emphasis mine):

Originally, all static data members still had to be defined
outside the class whether they were used or not.

But that restriction was supposed to be lifted [...]

In particular, if an integral/enum const static data member is
initialized within the class, and its address is never taken,
we agreed that no namespace-scope definition was required.

The corresponding resolution doesn't reflect this intent, with the
definition being still required in most situations anyway: it's enough
that the constant appears outside a place where constants are
required (ignoring the obvious cases of sizeof and typeid) and you
have to provide a definition. For instance:

whose main goal is to map the same couples (type, value) to the same
storage, also solves the definition problem. In this usage it is an
excellent hack (if your compiler is good enough), but IMHO still a
hack on a language defect.

<end digression>

What I propose is to solve the issue according to the original intent,
which is also what users expect and all compilers that I know of
already do. Or, in practice, we would have a rule that exists only as
words in a standard document.

PS: I've sent a copy of this to Mr. Adamczyk to clarify an important
doubt that occurred to me while writing this reply:

if no definition is provided for an integral static const data member
is that member an object? Paragraph 1.8/1 seems to say no, and in fact
it's difficult to think it is an object without assuming/pretending
that a region of storage exists for it (an object *is* a region of
storage according to the standard).

I would think that when no definition is required we have to assume
that it could be a non-object. In that case there's nothing in 3.2
which says what 'used' means for such an entity and the current
wording would thus be defective. Also, since the name of the member is
an lvalue and 3.10/2 says an lvalue refers to an object we would have
another problem.

OTOH the standard could pretend it is always an object (though the
compiler can optimize it away) and in this case it should probably
make a special case for it in 3.2/2.

Notes from the March 2004 meeting:

We sort of like this proposal, but we don't feel it has very
high priority. We're not going to spend time discussing it, but
if we get drafting for wording we'll review it.

Proposed resolution (October, 2005):

Change the first two sentences of 3.2 [basic.def.odr]
paragraph 2 from:

An expression is potentially evaluated unless it appears where
an integral constant expression is required (see 5.19 [expr.const]), is the operand of the sizeof operator
(5.3.3 [expr.sizeof]), or is the operand of
the typeid operator and the expression does not designate an
lvalue of polymorphic class type (5.2.8 [expr.typeid]). An
object or non-overloaded function is used if its name appears
in a potentially-evaluated expression.

to

An expression that is the operand of the sizeof operator
(5.3.3 [expr.sizeof]) is unevaluated, as is an
expression that is the operand of the typeid operator if it
is not an lvalue of a polymorphic class type (5.2.8 [expr.typeid]); all other expressions are potentially
evaluated. An object or non-overloaded function whose name appears
as a potentially-evaluated expression is used, unless it is an
object that satisfies the requirements for appearing in an integral
constant expression (5.19 [expr.const]) and the lvalue-to-rvalue
conversion (4.1 [conv.lval]) is immediately applied.

Change the first sentence of 9.4.2 [class.static.data]
paragraph 2 as indicated:

If a static data member is of const integral or const enumeration
type, its declaration in the class definition can specify a
constant-initializerwhichwhose constant-expression
shall be an integral constant expression (5.19 [expr.const]).

58.
Signedness of bit fields of enum type

Section 9.6 [class.bit]
paragraph 4 needs to be more specific about the signedness of bit
fields of enum type. How much leeway does an implementation have
in choosing the signedness of a bit field? In particular, does the
phrase "large enough to hold all the values of the enumeration" mean "the
implementation decides on the signedness, and then we see whether all the
values will fit in the bit field", or does it require the implementation
to make the bit field signed or unsigned if that's what it takes to make
it "large enough"?

Note (March, 2005): Clark Nelson observed that there is
variation among implementations on this point.

Notes from April, 2005 meeting:

Although implementations enjoy a great deal of latitude in handling
bit-fields, it was deemed more user-friendly to ensure that the
example in paragraph 4 will work by requiring implementations to use
an unsigned underlying type if the enumeration type has no negative
values. (If the implementation is allowed to choose a signed
representation for such bit-fields, the comparison against
TRUE will be false.)

In addition, it was observed that there is an apparent circularity
between 7.2 [dcl.enum] paragraph 7 and 9.6 [class.bit] paragraph 4 that should be resolved.

For an enumeration where emin is the smallest
enumerator and emax is the largest, the values of
the enumeration are the values in the range bmin to
bmax, defined as follows: Let K be 1 for a
two's complement representation and 0 for a one's complement or
sign-magnitude representation. bmax is the smallest
value greater than or equal to
max(|emin|-K,|emax|) and
equal to 2M-1, where M is a non-negative
integer. bmin is zero if emin is
non-negative and -(bmax+K) otherwise. The
size of the smallest bit-field large enough to hold all the values of
the enumeration type is max(M,1) if bmin is
zero and M+1 otherwise. It is possible to define an
enumeration that has values not defined by any of its enumerators.

Add the indicated text to the second sentence of
9.6 [class.bit] paragraph 4:

If the value of an enumerator is stored into a bit-field of the same
enumeration type and the number of bits in the bit-field is large
enough to hold all the values of that enumeration type
(7.2 [dcl.enum]), the original enumerator value and
the value of the bit-field shall compare equal.

198.
Definition of "use" in local and nested classes

Declarations in a local class can use only type names, static
variables, extern variables and functions, and enumerators
from the enclosing scope.

The definition of when an object or function is "used" is found in
3.2 [basic.def.odr]
paragraph 2 and
essentially says that the operands of sizeof and
non-polymorphic typeid operators are not used. (The
resolution for issue 48 will add
contexts in which integral constant expressions are required to the
list of non-uses.)

This definition of "use" would presumably allow code like

void foo() {
int i;
struct S {
int a[sizeof(i)];
};
};

which is required for C compatibility.

However, the restrictions on nested classes in
9.7 [class.nest]
paragraph 1 are very
similar to those for local classes, and the example there explicitly
states that a reference in a sizeof expression is a forbidden
use (abbreviated for exposition):

[As a personal note, I have seen real-world code that was exactly like
this; it was hard to persuade the author that the required
writearound, sizeof(((enclose*) 0)->x), was an improvement
over sizeof(x). —wmm]

Similarly, 9.2 [class.mem] paragraph 9 would appear to
prohibit examples like the following:

struct B {
char x[10];
};
struct D: B {
char y[sizeof(x)];
};

Suggested resolution: Add cross-references to
3.2 [basic.def.odr]
following the word
"use" in both 9.7 [class.nest]
and
9.8 [class.local]
, and change the example
in 9.7 [class.nest]
to indicate that a
reference in a sizeof expression is permitted. In
9.2 [class.mem] paragraph 9, "referred to" should be
changed to "used" with a cross_reference to
3.2 [basic.def.odr].

Notes from 10/01 meeting:

It was noted that the suggested resolution did not make the
sizeof() example in 9.7 [class.nest] valid.
Although the reference to the argument of sizeof() is not regarded
as a use, the right syntax must be used nonetheless to reference a non-static
member from the enclosing class. The use of the member name by itself is not
valid. The consensus within the core working group was that nothing should be
done about this case. It was later discovered that
9.4 [class.static] paragraph 3 states that

The
definition of a static
member shall not use directly the names of the nonstatic members of its class
or of a base class of its class (including as operands of the sizeof
operator). The definition of a static member may only refer to
these members to
form pointer to members (5.3.1 [expr.unary.op]) or
with the class member access syntax (5.2.5 [expr.ref]).

This seems to
reinforce the decision of the working group.

The use of "use" should still be cross-referenced. The
statements in 9.7 [class.nest] and 9.8 [class.local]
should also be rewritten to state the requirement
positively rather than negatively as the list of "can't"s is already missing
some cases such as template parameters.

Notes from the 4/02 meeting:

We backed away from "use" in the technical sense, because the
requirements on the form of reference are the same whether or not
the reference occurs inside a sizeof.

Proposed Resolution (revised October 2002):

In 9.2 [class.mem] paragraph 9, replace

Except when used to form a pointer to member
(5.3.1 [expr.unary.op]), when used in the body of a
nonstatic member function of
its class or of a class derived from its class
(9.3.1 [class.mfct.non-static]), or when used in
a mem-initializer for a
constructor for its class or for a class derived from its class
(12.6.2 [class.base.init]), a nonstatic data or function member
of a class shall only be referred to with the class member access syntax
(5.2.5 [expr.ref]).

with the following paragraph

Each occurrence in an expression of the name of a nonstatic data
member or nonstatic member function of a class shall be expressed as a class
member access (5.2.5 [expr.ref]), except when it appears
in the formation of a pointer to member
(5.3.1 [expr.unary.op]), when it appears in the body
of a nonstatic member function
of its class or of a class derived from its class
(9.3.1 [class.mfct.non-static]), or when it appears in a
mem-initializer for
a constructor for its class or for a class derived from its class
(12.6.2 [class.base.init]).

In 9.7 [class.nest]
paragraph 1, replace the last sentence,

Except by using explicit pointers, references, and object names,
declarations in a nested class can use only type names, static members, and
enumerators from the enclosing class.

with the following

[Note: In accordance with 9.2 [class.mem],
except by using explicit pointers,
references, and object names, declarations in a nested class shall not use
nonstatic data members or nonstatic member functions from the
enclosing class. This restriction applies in all constructs including the
operands of the sizeof operator.]

In the example following 9.7 [class.nest]
paragraph 1, change the comment on the first statement of
function f to emphasize that sizeof(x) is an error. The
example reads in full:

484.
Can a base-specifier name a cv-qualified class type?

Issue 298, recently approved,
affirms that cv-qualified class types can be used as
nested-name-specifiers. Should the same be true for
base-specifiers?

Rationale (April, 2005):

The resolution of issue 298 added
new text to 9.1 [class.name] paragraph 5 making it
clear that a typedef that names a cv-qualified class type is a
class-name. Because the definition of base-specifier
simply refers to class-name, it is already the case that
cv-qualified class types are permitted as base-specifiers.

Additional notes (June, 2005):

It's not completely clear what it means to have a cv-qualified
type as a base-specifier. The original proposed resolution
for issue 298 said that “the
cv-qualifiers are ignored,” but that wording is not in the
resolution that was ultimately approved.

If the cv-qualifiers are not ignored, does that mean that
the base-class subobject should be treated as always similarly
cv-qualified, regardless of the cv-qualification of the derived-class
lvalue used to access the base-class subobject? For instance:

A typedef-name (7.1.3 [dcl.typedef]) that names a
class type, or a cv-qualified version thereof, is also
a class-name, butclass-name. If
a typedef-name that names a cv-qualified class type is used
where a class-name is required, the cv-qualifiers are ignored.
A typedef-name shall not be used as the identifier
in a
class-head.

Delete 7.1.3 [dcl.typedef] paragraph 8:

[Note: if the typedef-name is used where
a class-name (or enum-name) is required, the program is
ill-formed. For example,

typedef struct {
S(); // error: requires a return type because S is
// an ordinary member function, not a constructor
} S;

This is a name lookup ambiguity because of 10.2 [class.member.lookup]
paragraph 2:

... Each of these declarations that was introduced by a using-declaration
is considered to be from each sub-object of C that is of the type containing
the declaration designated by the using-declaration. If the resulting set
of declarations are not all from sub-objects of the same type, or the set
has a nonstatic member and includes members from distinct sub-objects,
there is an ambiguity and the program is ill-formed.

This contradicts the text and example in paragraph 12 of 7.3.3 [namespace.udecl]
.

Proposed Resolution (10/00):

Replace the two cited sentences from 10.2 [class.member.lookup]
paragraph 2 with the following:

The resulting set of declarations shall all be from sub-objects
of the same type, or there shall be a set of declarations from
sub-objects of a single type that contains using-declarations
for the declarations found in all other sub-object types.
Furthermore, for nonstatic members, the resulting set of
declarations shall all be from a single sub-object, or there shall
be a set of declarations from a single sub-object that contains
using-declarations for the declarations found in all other
sub-objects. Otherwise, there is an ambiguity and the program is
ill-formed.

Replace the examples in 10.2 [class.member.lookup]
paragraph 3 with the following:

... Each of these declarations that was introduced by a using-declaration
is considered to be from each sub-object of C that is of the type containing
the declaration designated by the using-declaration. If the resulting set
of declarations are not all from sub-objects of the same type, or the set
has a nonstatic member and includes members from distinct sub-objects,
there is an ambiguity and the program is ill-formed.

Since the two x's are considered to be "from" different objects, looking up
x produces a set including declarations "from" different objects, and the
program is ill-formed. Clearly this is wrong. The problem with the
existing wording is that it fails to consider lookup context.

The first proposed solution:

The resulting set of declarations shall all be from sub-objects
of the same type, or there shall be a set of declarations from
sub-objects of a single type that contains using-declarations
for the declarations found in all other sub-object types.
Furthermore, for nonstatic members, the resulting set of
declarations shall all be from a single sub-object, or there shall
be a set of declarations from a single sub-object that contains
using-declarations for the declarations found in all other
sub-objects. Otherwise, there is an ambiguity and the program is
ill-formed.

because it considers the lookup context, but not the definition context;
under this definition of "from", the two declarations found are the
using-declarations, which are "from" B1 and B2.

The solution is to separate the notions of lookup and definition context.
I have taken an algorithmic approach to describing the strategy.

Incidentally, the earlier proposal allows one base to have a superset of
the declarations in another base; that was an extension, and my proposal
does not do that. One algorithmic benefit of this limitation is to
simplify the case of a virtual base being hidden along one arm and not
another ("domination"); if we allowed supersets, we would need to remember
which subobjects had which declarations, while under the following
resolution we need only keep two lists, of subobjects and declarations.

Proposed resolution (October 2002):

Replace 10.2 [class.member.lookup] paragraph 2 with:

The following steps define the result of name lookup for a member
name f in a class scope C.

The lookup set for f in C, called S(f,C), consists of two
component sets: the declaration set, a set of members named f; and
the subobject set, a set of subobjects where declarations of these
members (possibly including using-declarations) were found. In the
declaration set, using-declarations are replaced by the members they
designate, and type declarations (including injected-class-names) are
replaced by the types they designate. S(f,C) is calculated as
follows.

If C contains a declaration of the name f, the declaration set contains
every declaration of f in C (excluding bases), the subobject set contains C
itself, and calculation is complete.

Otherwise, S(f,C) is initially empty. If C has base classes, calculate
the lookup set for f in each direct base class subjobject Bi,
and merge each such lookup set S(f,Bi) in turn into S(f,C).

The following steps define the result of merging lookup set
S(f,Bi) into the intermediate S(f,C):

If each of the subobject members of S(f,Bi) is a base
class subobject of at least one of the subobject members of S(f,C), S(f,C)
is unchanged and the merge is complete. Conversely, if each of the
subobject members of S(f,C) is a base class subobject of at least one of
the subobject members of S(f,Bi), the new S(f,C) is a copy of
S(f,Bi).

Otherwise, if the declaration sets of S(f,Bi) and S(f,C)
differ, the merge is ambiguous: the new S(f,C) is a lookup set with an
invalid declaration set and the union of the subobject sets. In subsequent
merges, an invalid declaration set is considered different from any
other.

Otherwise, consider each declaration d in the set, where d is a
member of class A. If d is a nonstatic member, compare the A base class
subobjects of the subobject members of S(f,Bi) and
S(f,C). If they do not match, the merge is ambiguous, as in the
previous step. [Note: It is not necessary to remember which A subobject
each member comes from, since using-declarations don't disambiguate. ]

Otherwise, the new S(f,C) is a lookup set with the shared
set of declarations and the union of the subobject sets.

The result of name lookup for f in C is the declaration set of
S(f,C). If it is an invalid set, the program is ill-formed.

S(x,F) is unambiguous because the A and B base subobjects of D are also
base subobjects of E, so S(x,D) is discarded in the first merge step. --end
example]

Turn 10.2 [class.member.lookup] paragraphs 5 and 6 into notes.

Notes from October 2003 meeting:

Mike Miller raised some new issues in N1543, and we adjusted the
proposed resolution as indicated in that paper.

Further information from Mike Miller (January 2004):

Unfortunately, I've become aware of a minor glitch in
the proposed resolution for issue 39 in N1543, so I'd like to
suggest a change that we can discuss in Sydney.

A brief review and background of the problem: the major change we
agreed on in Kona was to remove detection of multiple-subobject
ambiguity from class lookup (10.2 [class.member.lookup]) and instead
handle it as part
of the class member access expression. It was pointed out in
Kona that 11.2 [class.access.base]/5 has this effect:

If a class member access operator, including an implicit
"this->," is used to access a nonstatic data member or
nonstatic member function, the reference is ill-formed if the
left operand (considered as a pointer in the "." operator
case) cannot be implicitly converted to a pointer to the
naming class of the right operand.

After the meeting, however, I realized that this requirement is
not sufficient to handle all the cases. Consider, for instance,

Here, both the object expression ("this") and the naming class
are "D", so the reference to "i" satisfies the requirement in
11.2 [class.access.base]/5, even though it involves a
multiple-subobject ambiguity.

In order to address this problem, I proposed in N1543 to add a
paragraph following 5.2.5 [expr.ref]/4:

If E2 is a non-static data member or a non-static member
function, the program is ill-formed if the class of E1 cannot
be unambiguously converted (10.2) to the class of which E2 is
directly a member.

That's not quite right. It does diagnose the case above as
written; however, it breaks the case where qualification is used
to circumvent the ambiguity:

In my proposed wording, the class of "this" can't be converted to
"B" (the qualifier is ignored), so the access is ill-formed.
Oops.

I think the following is a correct formulation, so the proposed
resolution we discuss in Sydney should contain the following
paragraph instead of the one in N1543:

If E2 is a nonstatic data member or a non-static member
function, the program is ill-formed if the naming class
(11.2) of E2 cannot be unambiguously converted (10.2) to
the class of which E2 is directly a member.

This reformulation also has the advantage of pointing readers to
11.2 [class.access.base], where the the convertibility requirement
from the class of
E1 to the naming class is located and which might otherwise be
overlooked.

Notes from the March 2004 meeting:

We discussed this further and agreed with these latest
recommendations. Mike Miller has produced a paper N1626 that gives
just the final collected set of changes.

390.
Pure virtual must be defined when implicitly called

A pure virtual function need be defined only if explicitly called with
the qualified-id syntax (5.1.1 [expr.prim.general]).

This is IMHO incomplete. A dtor is a function (well, a "special member
function", but this also makes it a function, right?) but it is called
implicitly and thus without a qualified-id syntax. Another alternative
is that the pure virtual function is called directly or indirectly from
the ctor. Thus the above sentence which specifies when a pure virtual
function need be defined ("...only if...") needs to be extended:

A pure virtual function need be defined only if explicitly called with
the qualified-id syntax (5.1.1 [expr.prim.general]) or if implicitly
called (12.4 [class.dtor] or 12.7 [class.cdtor]).

Proposed resolution:

Change 10.4 [class.abstract] paragraph 2 from

A pure virtual function need be defined only if explicitly called
with the qualified-id syntax (5.1.1 [expr.prim.general]).

to

A pure virtual function need be defined only if
explicitly called with, or as if with
(12.4 [class.dtor]),
the qualified-id syntax (5.1.1 [expr.prim.general]).

Note: 12.4 [class.dtor] paragraph 6 defines the "as if"
cited.

8.
Access to template arguments used in a function return type and in the nested name specifier

All access controls in clause 11 affect the ability to access a class
member name from a particular scope... In particular, access controls
apply as usual to member names accessed as part of a function return type,
even though it is not possible to determine the access privileges of that
use without first parsing the rest of the function declarator.

This means, if we take the loosest possible definition of "access from
a particular scope", that we have to save and check later the following
names

I suspect that member templates were not really considered when this was
written, and that it might have been written rather differently if they
had been. Note that access to the template arguments is only legal because
the class has been declared a friend, which is probably not what most programmers
would expect.

Rationale:

Not a defect. This behavior is as intended.

ISSUE 2:

Now consider void A::int_temp<A::A1, A::garbconst + 2, &A::func>::func1()
{...} By my reading of 11.8 [class.access.nest]
, the references to
A::A1, A::garbconst and A::func are now illegal,
and there is no way to define this function outside of the class. Is there
any need to do anything about either of these Issues?

Proposed resolution (04/01):

The resolution for this issue is contained in the resolution
for issue 45.

494.
Problems with the resolution of issue 45

The proposed resolution for issue 45 inserts the following sentence after 11 [class.access] paragraph 1:

A member of a class can also access all names as the class of
which it is a member.

I don't think that this is correctly constructed English. I see two
possibilities:

This is a typo, and the correct change is:

A member of a class can also access all names of the class of which
it is a member.

The intent is something more like:

A member of a nested class can also access all names accessible by
any other member of the class of which it is a member.

[Note: this was editorially corrected at the time defect
resolutions were being incorporated into the Working Paper to
read, “...can also access all the names declared in the
class of which it is a member,” which is essentially the
same as the preceding option 1.]

I would prefer to use the language proposed for 11.8 [class.access.nest]:

A nested class is a member and as such has the same access rights
as any other member.

A second problem is with the text in 11.4 [class.friend] paragraph 2:

[Note: this means that access to private and protected
names is also granted to member functions of the friend class (as
if the functions were each friends) and to the static data member
definitions of the friend class. This also means that private and
protected type names from the class granting friendship can be
used in the base-clause of a nested class of the friend
class. However, the declarations of members of classes nested
within the friend class cannot access the names of private and
protected members from the class granting friendship. Also,
because the base-clause of the friend class is not part of
its member declarations, the base-clause of the friend
class cannot access the names of the private and protected
members from the class granting friendship. For example,

This seems to be an oversight. The proposed change to
11.8 [class.access.nest] paragraph 1 would appear to have
eliminated the restrictions on nested class access. However, at
least one compiler (gcc 3.4.3) doesn't appear to take my view,
and continues with the restrictions on access by classes within a
friend class, while implementing the rest of the resolution of
issue 45.

Like a member function, a friend function (11.4 [class.friend])
defined within a nested class is in the lexical scope of that class;
it obeys the same rules for name binding as a static member function
of that class (9.4 [class.static]) and has no special access
rights to members of an enclosing class.

9.
Clarification of access to base class members

A base class is said to be accessible if an invented public
member of the base class is accessible. If a base class is accessible,
one can implicitly convert a pointer to a derived class to a pointer to
that base class.

Can you access the protected member b1 of B in foo?
Can you convert a D* to a B* in foo?

1st interpretation:

A public member of B is accessible within foo (since
foo is a friend), therefore foo can refer to b1 and convert
a D* to a B*.

2nd interpretation:

B is a protected base class of D, and a public member of B
is a protected member of D and can only be accessed within members
of D and friends of D. Therefore foo cannot refer to
b1 and cannot convert a D* to a B*.

(See J16/99-0042 = WG21 N1218.)

Proposed Resolution (04/01):

Add preceding 11.2 [class.access.base]
paragraph 4:

A base class B of N is accessible at R,
if

an invented public member of B would be a public member
of N, or

R occurs in a member or friend of class N, and an
invented public member of B would be a private or protected
member of N, or

R occurs in a member or friend of a class P derived
from N, and an invented public member of B would be
a private or protected member of P, or

there exists a class S such that B is a base class
of S accessible at R and S is a base class
of N accessible at R. [Example:

77.
The definition of friend does not allow nested classes to be friends

A friend of a class is a function or class that is not a member
of the class but is permitted to use the private and protected member names
from the class. ...

A nested class, i.e. INNER in the example below, is a member of class OUTER.
The sentence above states that it cannot be a friend. I think this is a
mistake.

class OUTER {
class INNER;
friend class INNER;
class INNER {};
};

Proposed resolution (04/01):

Change the first sentence of 11.4 [class.friend]
as follows:

A friend of a class is a function or class that is not a
member of the class but is allowedgiven permission
to use the private and protected member names from the class.
The name of a friend is not in the scope of the class, and
the friend is not called with the member access operators
(5.2.5 [expr.ref]) unless it is a member of
another class.A class specifies its friends, if any,
by way of friend declarations. Such declarations give special
access rights to the friends, but they do not make the nominated
friends members of the befriending class.

#410-D: protected function "A::g" is not accessible through a "B" pointer or object
b.g();
^

Steve Adamczyk:
The error in this case is due to
11.5 [class.protected] of the standard, which is an additional
check on top of the other access checking. When that section says
"a protected nonstatic member function ... of a base class" it doesn't
indicate whether the fact that there is a using-declaration is relevant.
I'd say the current wording taken at face value would suggest that
the error is correct -- the function is protected, even if the
using-declaration for it makes it accessible as a public function.
But I'm quite sure the wording in
11.5 [class.protected] was written before using-declarations
were invented and has not been reviewed since for consistency with
that addition.

Notes from April 2003 meeting:

We agreed that the example should be allowed.

Proposed resolution (April 2003, revised October 2003):

Change 11.5 [class.protected] paragraph 1 from

When a friend or a member function of a derived class references a
protected nonstatic member function or protected nonstatic data member
of a base class, an access check applies in addition to those
described earlier in clause 11 [class.access].
[Footnote: This
additional check does not apply to other members, e.g. static
data members or enumerator member constants.] Except
when forming a pointer to member (5.3.1 [expr.unary.op]),
the access must be through a
pointer to, reference to, or object of the derived class itself (or
any class derived from that class (5.2.5 [expr.ref]).
If the access is to form a
pointer to member, the nested-name-specifier shall name the
derived class (or any class derived from that class).

to

An additional access check beyond those described earlier in
clause 11 [class.access]
is applied when a nonstatic data member or nonstatic member
function is a protected member of its naming class
(11.2 [class.access.base]).
[Footnote: This additional check does not apply
to other members, e.g., static data members or enumerator member
constants.] As described
earlier, access to a protected member is granted because the
reference occurs in a friend or member of some
class C. If the access is to form a pointer to member
(5.3.1 [expr.unary.op]), the
nested-name-specifier shall name C or a
class derived from C. All other accesses involve a
(possibly implicit) object expression (5.2.5 [expr.ref]).
In this case, the
class of the object expression shall be C or a class derived
from C.

I think the formulation that the member is a protected member
of its naming class is not what we want. I think we intended
that the member is protected in the declaration that is found,
where the declaration found might be a using-declaration.

Mike Miller: I think the proposed wording makes the
access pb->p ill-formed, and I think that's the right
thing to do.

First, protected inheritance of A by B means
that B intends the public and protected members of
A to be part of B's implementation, available
to B's descendants only. (That's why there's a
restriction on converting from B* to A*, to
enforce B's intention on the use of members of
A.) Consequently, I see no difference in access policy
between your example and

class B {
protected:
int p;
};

Second, the reason we have this rule is that C's use
of inherited protected members might be different from their use
in a sibling class, say D. Thus members and friends of
C can only use B::p in a manner consistent with
C's usage, i.e., in C or
derived-from-C objects. If we rewrote your example
slightly,

This is because the nested class does not have access to the member E
in D. 11 [class.access]
paragraph 5 says that access to D::E is checked with
member access to class E, but unfortunately that doesn't give
access to D::E. 11 [class.access]
paragraph 6 covers the access for D::E::m,
but it doesn't affect the D::E access. Are there any implementations
that are standard compliant that support this?

Here is another example:

class C {
class B
{
C::B *t; //2 error, C::B is inaccessible
};
};

This causes trouble for member functions declared outside of the class
member list. For example:

If the return type (i.e. C::B) is access checked in the scope
of class B (as implied by
11 [class.access]
paragraph 5)
as a qualified name, then
the return type is an error just like referring to C::B in the
member list of class B above (i.e. //2) is ill-formed.

Proposed resolution (04/01):

The resolution for this issue is incorporated into the
resolution for issue 45.

private; that is, its name can be used only by members and
friends of the class in which it is declared. [...]

and
11.8 [class.access.nest]
paragraph 1:

The members of a nested class
have no special access to members of an enclosing class, nor to classes
or functions that have granted friendship to an enclosing class; the usual
access rules (clause 11 [class.access]
)
shall be obeyed. [...]

This makes me think that the ': Parent' part is OK by itself,
but that the implicit call of 'Parent::Parent()' by 'Derived::Derived()'
is not.

From Mike Miller:

I think it is completely legal, by the reasoning given in the (non-normative)
11.8 [class.access.nest]
paragraph 2. The use of a private nested class as a base of another nested class
is explicitly declared to be acceptable there. I think the rationale in
the comments in the example ("// OK because of injection of name A in A")
presupposes that public members of the base class will be public members
in a (publicly-derived) derived class, regardless of the access of the
base class, so the constructor invocation should be okay as well.

Insert the following as a new paragraph following
11 [class.access] paragraph 1:

A member of a class can also access all names as the class of which
it is a member. A local class of a member function may access the
same names that the member function itself may access. [Footnote:
Access permissions are thus transitive and cumulative to nested and
local classes.]

Delete 11 [class.access] paragraph 6.

In 11.8 [class.access.nest] paragraph 1, change

The members of a nested class have no special access to members of an
enclosing class, nor to classes or functions that have granted
friendship to an enclosing class; the usual access rules
(clause 11 [class.access]) shall be obeyed.

to

A nested class is a member and as such has the same access rights
as any other member.

263.
Can a constructor be declared a friend?

According to 12.1 [class.ctor] paragraph 1, a
declaration of a constructor has a special limited syntax, in
which only function-specifiers are allowed. A friend
specifier is not a function-specifier, so one interpretation
is that a constructor cannot be declared in a friend
declaration.

(It should also be noted, however, that neither friend
nor function-specifier is part of the declarator
syntax, so it's not clear that anything conclusive can be derived
from the wording of 12.1 [class.ctor].)

Notes from 04/01 meeting:

The consensus of the core language working group was that it
should be permitted to declare constructors as friends.

Proposed Resolution (revised October 2002):

Change paragraph 1a in 3.4.3.1 [class.qual] (added by
the resolution of issue 147) as follows:

If the nested-name-specifier nominates a class C, and the
name specified after the nested-name-specifier, when looked up in
C, is the injected-class-name of C (clause
9 [class]), the name is instead considered to name the
constructor of class C. Such a constructor name shall be used
only in the declarator-id of a constructor definitiondeclaration that appears outside of the class definitionnames a constructor....

Note: the above does not allow qualified names to be used for
in-class declarations; see 8.3 [dcl.meaning] paragraph 1.
Also note that issue 318 updates the
same paragraph.

326.
Wording for definition of trivial constructor

In 12.1 [class.ctor] paragraph 5, the standard says
"A constructor is trivial if [...]", and goes on to define a trivial
default constructor. Taken literally, this would mean that a copy
constructor can't be trivial (contrary to 12.8 [class.copy] paragraph 6). I suggest changing this to "A default
constructor is trivial if [...]". (I think the change is purely
editorial.)

Proposed Resolution (revised October 2002):

Change 12.1 [class.ctor] paragraph 5-6 as follows:

A default constructor for a class X
is a constructor of class X
that can be called without an argument.
If there is no
user-declareduser-declared
constructor for class X,
a default constructor is implicitly declared.
An
implicitly-declaredimplicitly-declared
default constructor
is an inline public member of its class.
A
default
constructor is trivial
if it is an implicitly-declared default constructor
and if:

its class has no virtual functions (10.3 [class.virtual])
and no virtual base classes (10.1 [class.mi]), and

all the direct base classes of its class
have trivial
default
constructors, and

for all the nonstatic data members of its class
that are of class type (or array thereof),
each such class has a trivial
default
constructor.

Otherwise, the
default
constructor is non-trivial.

Change 12.4 [class.dtor] paragraphs 3-4 as follows (the main
changes are removing italics):

If a class has no
user-declareduser-declared
destructor, a destructor is declared
implicitly. An
implicitly-declaredimplicitly-declared
destructor is an inline public
member of its class. A destructor is trivial if it is an
implicitly-declared destructor and if:

all of the direct base classes of its class have trivial destructors and

for all of the non-static data members of its class that are of
class type (or array thereof), each such class has a trivial
destructor.

331.
Allowed copy constructor signatures

A copy constructor for a class X is a constructor with a
first parameter of type X & or of type const X &. [Note:
see 12.8 [class.copy] for more information on copy constructors.]

No mention is made of constructors with first parameters of types
volatile X & or const volatile X &. This statement seems to be
in contradiction with 12.8 [class.copy] paragraph 2 which states

A non-template constructor for class X is a copy constructor
if its first parameter is of type X &, const X &, volatile X &
or const volatile X &, ...

12.8 [class.copy] paragraph 5 also mentions the volatile
versions of the
copy constructor, and the comparable paragraphs for copy assignment
(12.8 [class.copy] paragraphs 9 and 10) all allow volatile
versions, so it seems that 12.1 [class.ctor] is at fault.

Proposed resolution (October 2002):

Change 12.1 [class.ctor] paragraph 10 from

A copy constructor for a class X is a constructor with a
first parameter of type X& or of type const X&.
[Note: see 12.8 [class.copy] for more information on
copy constructors. ]

to (note that the dropping of italics is intentional):

A copy constructor (12.8 [class.copy]) is used to copy objects
of class type.

86.
Lifetime of temporaries in query expressions

In
12.2 [class.temporary]
paragraph 5,
should binding a reference to the result of a "?" operation, each
of whose branches is a temporary, extend both temporaries?

Here's an example:

const SFileName &C = noDir ? SFileName("abc") : SFileName("bcd");

Do the temporaries created by the SFileName conversions survive
the end of the full expression?

Notes from 10/00 meeting:

Other problematic examples include cases where the temporary
from one branch is a base class of the temporary from the other (i.e.,
where the implementation must remember which type of temporary must
be destroyed), or where one branch is a temporary and the other is
not. Similar questions also apply to the comma operator. The sense
of the core language working group was that implementations should
be required to support these kinds of code.

Notes from the March 2004 meeting:

We decided that the cleanest model is one in which any "?" operation
that returns a class rvalue always copies one of its operands to
a temporary and returns the temporary as the result of the operation.
(Note that this may involve slicing.) An implementation would be
free to optimize this using the rules in 12.8 [class.copy]
paragraph 15, and in fact we would expect that in many cases
compilers would do such optimizations. For example, the compiler
could construct both rvalues in the above example into a
single temporary, and thus avoid a copy.

124.
Lifetime of temporaries in default initialization of class arrays

Jack Rouse:
12.2 [class.temporary]
states that temporary objects will normally be destroyed at the
end of the full expression in which they are created. This can create
some unique code generation requirements when initializing a class
array with a default constructor that uses a default argument. Consider
the code:

The full expression allocating the array in f(int) includes the
default constructor for S. Therefore according to
1.9 [intro.execution] paragraph 14, it
includes the default argument expression for S(int).
So evaluation of
the full expression should include evaluating the default argument "n"
times and creating "n" temporaries of type T. But the destruction of
the temporaries must be delayed until the end of the full expression
so this requires allocating space at runtime for "n" distinct
temporaries. It is unclear how these temporaries are supposed to be
allocated and deallocated. They cannot readily be autos because a
variable allocation is required.

I believe that many existing implementations will destroy the
temporaries needed by the default constructor after each array element
is initialized. But I can't find anything in the standard that allows
the temporaries to be destroyed early in this case.

I think the standard should allow the early destruction of temporaries
used in the default initialization of class array elements. I believe
early destruction is the status quo, and I don't think the users of
existing C++ compilers have been adversely impacted by it.

199.
Order of destruction of temporaries

[Voted into the WP at the April, 2007 meeting as part of paper
J16/07-0099 = WG21 N2239.]

12.2 [class.temporary]
paragraph 3 simply
states the requirement that temporaries created during the evaluation
of an expression

are destroyed as the last step in evaluating the
full-expression (1.9) that (lexically) contains the point where they
were created.

There is nothing said about the relative order in which these
temporaries are destroyed.

Paragraph 5, dealing with temporaries bound to references, says

the temporaries created during the evaluation of the expression
initializing the reference, except the temporary to which the
reference is bound, are destroyed at the end of the full-expression in
which they are created and in the reverse order of the completion of
their construction.

Is this difference intentional? May temporaries in expressions other
than those initializing references be deleted in non-LIFO order?

Notes from 04/00 meeting:

Steve Adamczyk expressed concern about constraining implementations
that are capable of fine-grained parallelism -- they may be
unable to determine the order of construction without adding
undesirable overhead.

Proposed resolution (April, 2007):

As specified in paper J16/07-0099 = WG21 N2239.

201.
Order of destruction of temporaries in initializers

According to 12.2 [class.temporary]
paragraph 4, an expression appearing as the initializer in an object
definition constitutes a context "in which temporaries are destroyed
at a different point than the end of the full-expression." It goes on
to say that the temporary containing the value of the expression
persists until after the initialization is complete (see also
issue 117). This seems to presume
that the end of the full-expression is a point earlier than the
completion of the initialization.

However, according to
1.9 [intro.execution]
paragraphs 12-13, the
full-expression in such cases is, in fact, the entire initialization.
If this is the case, the behavior described for temporaries in an
initializer expression is simply the normal behavior of temporaries in
any expression, and treating it as an exception to the general rule is
both incorrect and confusing.

If the initializer for an object or
sub-object is a full-expression, the initialization of
the object or sub-object (e.g., by calling a constructor
or copying an expression value) is considered to be part
of the full-expression.

Replace 12.2 [class.temporary] paragraph 4 with:

There are two contexts in which temporaries are
destroyed at a different point than the end of the
full-expression. The first context is when a
default constructor is called to initialize an
element of an array. If the constructor has one
or more default arguments, any temporaries created
in the default argument expressions are destroyed
immediately after return from the constructor.

a=f(a) requires a temporary for either the argument a
or the result of f(a) to avoid undesired aliasing of a.

The note seems to imply that an implementation is allowed to omit
copying "a" to f's formal argument, or to omit using a temporary for
the return value of f. I don't find that license in normative text.

Function f returns an X by value, and in the expression the value is
assigned (not copy-constructed) to "a". I don't see how that
temporary can be omitted. (See also 12.8 [class.copy] p 15)

Since "a" is an lvalue and not a temporary, I don't see how copying
"a" to f's formal parameter can be avoided.

Am I missing something, or is 12.2 [class.temporary] p 2
misleading?

Proposed resolution (October, 2004):

In 12.2 [class.temporary] paragraph 2, change the last
sentence as indicated:

On the other hand, the expression a=f(a) requires a
temporary for either the argument a or the result of
f(a) to avoid undesired aliasing of athe result of f(a), which is then assigned to
a.

Section 12.2 [class.temporary] paragraph 3 says a temp is
destroyed as the last step in
evaluating the full expression. But the expression C().get() has a
reference type. Does 12.2 [class.temporary] paragraph 3 require
that the dereference to get a
boolean result occur before the destructor runs, making the code
valid? Or does the code have undefined behavior?

Bill Gibbons:
It has undefined behavior, though clearly this wasn't intended.
The lvalue-to-rvalue conversion that occurs in the "if" statement is
not currently part of the full-expression.

From section 12.2 [class.temporary] paragraph 3:

Temporary objects are destroyed as the last step in evaluating
the full-expression (1.9 [intro.execution])
that (lexically) contains the point
where they were created.

From section 1.9 [intro.execution] paragraph 12:

A full-expression is an expression that is not a subexpression
of another expression. If a language construct is defined to
produce an implicit call of a function, a use of the language
construct is considered to be an expression for the purposes
of this definition.

The note in section 1.9 [intro.execution] paragraph 12 goes
on to explain that this covers
expressions used as initializers, but it does not discuss
lvalues within temporaries.

It is a small point but it is probably worth correcting
1.9 [intro.execution] paragraph 12.
Instead of the "implicit call of a function" wording, it might
be better to just say that a full-expression includes any implicit
use of the expression value in the enclosing language construct,
and include a note giving implicit calls and lvalue-to-rvalue
conversions as examples.

A full-expression is an expression that is not a
subexpression of another expression. If a language construct is
defined to produce an implicit call of a function, a use of the
language construct is considered to be an expression for the
purposes of this definition. Conversions applied to the result of
an expression in order to satisfy the requirements of the language
construct in which the expression appears are also considered to be
part of the full-expression.

[Note: certain contexts in C++ cause the evaluation
of a full-expression that results from a syntactic construct other
than expression (5.18 [expr.comma]). For example,
in 8.5 [dcl.init] one syntax for
initializer is

( expression-list )

but the resulting construct is a function call upon a constructor
function with expression-list as an argument list; such a
function call is a full-expression. For example, in
8.5 [dcl.init], another
syntax for initializer is

= initializer-clause

but again the resulting construct might be a function call upon a
constructor function with one assignment-expression as an
argument; again, the function call is a full-expression. ][Example:

443.
Wording nit in description of lifetime of temporaries

There seems to be a typo in
12.2 [class.temporary]/5, which says "The temporary to which
the reference is bound or the temporary that is the complete object TO a
subobject OF which the TEMPORARY is bound persists for the lifetime of the
reference except as specified below."

I think this should be "The temporary to which the reference is bound or the
temporary that is the complete object OF a subobject TO which the REFERENCE
is bound persists for the lifetime of the reference except as specified
below."

I used upper-case letters for the parts I think need to be
changed.

Proposed resolution (October, 2004):

Change 12.2 [class.temporary] paragraph 5 as
indicated:

The temporary to which the reference is bound or the temporary
that is the complete object toof a subobject
ofto which the temporaryreference
is bound persists for the lifetime of the reference except as
specified below.

464.
Wording nit on lifetime of temporaries to which references are bound

[...] if obj2 is an object with static or automatic
storage duration created after the temporary is
created, the temporary shall be destroyed after
obj2 is destroyed.

For the temporary to be destroyed after obj2 is destroyed, when obj2 has
static storage, I would say that the reference to the temporary should
also have static storage, but that is IMHO not clear from the
paragraph.

Example:

void f ()
{
const T1& ref = T1();
static T2 obj2;
...
}

Here the temporary would be destoyed before obj2, contrary to the
rule above.

Steve Adamczyk: I agree there's a minor issue here. I think
the clause quoted above meant for obj1 and obj2 to have the same storage
duration. Replacing "obj2 is an object with static or automatic
storage duration" by "obj2 is an object with the same storage duration as
obj1" would, I believe, fix the problem.

Notes from October 2004 meeting:

We agreed with Steve Adamczyk's suggestion.

Proposed resolution (October, 2005):

Change 12.2 [class.temporary] paragraph 5 as follows:

... In addition, the destruction of temporaries bound to references
shall take into account the ordering of destruction of objects with
static or automatic storage duration (3.7.1 [basic.stc.static],
3.7.3 [basic.stc.auto]); that is, if obj1 is an object
with static or automatic storage duration created before the
temporary is created with the same storage duration as the
temporary, the temporary shall be destroyed before obj1
is destroyed; if obj2 is an object with static or
automatic storage duration created after the temporary is
created with the same storage duration as the temporary, the
temporary shall be destroyed after obj2 is destroyed...

296.
Can conversion functions be static?

May user-defined conversion functions be static? That is, should this
compile?

class Widget {
public:
static operator bool() { return true; }
};

All my compilers hate it. I hate it, too. However, I don't see anything
in 12.3.2 [class.conv.fct] that makes it illegal. Is this a
prohibition that arises from
the grammar, i.e., the grammar doesn't allow "static" to be followed by a
conversion-function-id in a member function declaration? Or am I just
overlooking something obvious that forbids static conversion functions?

I believe that clause 3 is correct and that clause 12 is in error.
We worked hard to get the destructor lookup rules in clause 3 to be
right, and I think we failed to notice that a change was also needed
in clause 12.

Mike Miller:

Unfortunately, I don't believe 3.4.3 [basic.lookup.qual] covers
the case of p->AB::~AB(). It's clearly intended to do so, as
evidenced by 3.4.3.1 [class.qual] paragraph 1 ("a
destructor name is looked up as specified in 3.4.3 [basic.lookup.qual]"), but I don't think the language there does so.

The relevant paragraph is 3.4.3 [basic.lookup.qual] paragraph
5. (None of the other paragraphs in that section deal with this topic
at all.) It has two parts. The first is

If a pseudo-destructor-name (5.2.4 [expr.pseudo])
contains a nested-name-specifier, the type-names are
looked up as types in the scope designated by the
nested-name-specifier.

This sentence doesn't apply, because ~AB isn't a
pseudo-destructor-name. 5.2.4 [expr.pseudo] makes
clear that this syntactic production (5.2 [expr.post]
paragraph 1) only applies to cases where the type-name is not a
class-name. p->AB::~AB is covered by the production
using id-expression.

The second part of 3.4.3 [basic.lookup.qual] paragraph 5 says

In a qualified-id of the form:

::optnested-name-specifier~class-name

where the nested-name-specifier designates a namespace name,
and in a qualified-id of the form:

::optnested-name-specifier class-name::~class-name

the class-names are looked up as types in the scope
designated by the nested-name-specifier.

This wording doesn't apply, either. The first one doesn't because
the nested-name-specifier is a class-name, not a
namespace name. The second doesn't because there's only one layer of
qualification.

As far as I can tell, there's no normative text that specifies how
the ~AB is looked up in p->AB::~AB().
3.4.3.1 [class.qual], where all the other
class member qualified lookups are handled, defers to
3.4.3 [basic.lookup.qual], and 3.4.3 [basic.lookup.qual]
doesn't cover the case.

Jason Merrill:
My thoughts on the subject were that the name we use in a destructor call
is really meaningless; as soon as we see the ~ we know what the
user means,
all we're doing from that point is testing their ability to name the
destructor in a conformant way. I think that everyone will agree that

anything::B::~B()

should be well-formed, regardless of the origins of the name "B". I
believe that the rule about looking up the second "B" in the same context
as the first was intended to provide this behavior, but to me this seems
much more heavyweight than necessary. We don't need a whole new type of
lookup to be able to use the same name before and after the ~;
we can just
say that if the two names match, the call is well-formed. This is
significantly simpler to express, both in the standard and in an
implementation.

Anyone writing two different names here is either deliberately writing
obfuscated code, trying to call the destructor of a nested class, or
fighting an ornery compiler (i.e. one that still wants to see
B_alias::~B()). I think we can ignore the first case.
The third would be
handled by reverting to the old rule (look up the name after ~ in the
normal way) with the lexical matching exception described above -- or we
could decide to break such code, do no lookup at all, and only accept a
matching name. In a good implementation, the second should probably get an
error message telling them to write Outer::Inner::~Inner instead.

We discussed this at the meetings, but I don't remember if we came to
any sort of consensus on a direction. I see three options:

Stick with the status quo, i.e. the special lookup rule such that if the
name before ::~ is a class name, the name after ::~
is looked up in the
same scope as the previous one. If we choose this option, we just need
better wording that actually expresses this, as suggested in the issue
list. This option breaks old B_alias::~B code where B_alias
is declared in a different scope from B.

Revert to the old rules, whereby the name after ::~ is looked up just
like a name after ::, with the exception that if it matches the name
before ::~ then it is considered to name the same class. This option
supports old code and code that writes B_alias::~B_alias. It does not
support the q->I1::~I2 usage of 3.4.3 [basic.lookup.qual],
but that seems like deliberate
obfuscation. This option is simpler to implement than #1.

Do no lookup for a name after ::~; it must match the
name before. This
breaks old code as #1, but supports the most important case where the
names match. This option may be slightly simpler to implement than #2.
It is certainly easier to teach.

My order of preference is 2, 3, 1.

Incidentally, it seems to me oddly inconsistent to allow
Namespace::~Class,
but not Outer::~Inner.
Prohibiting the latter makes sense from the
standpoint of avoiding ambiguity, but what was the rationale for allowing
the former?

John Spicer:
I agree that allowing Namespace::~Class is odd.
I'm not sure where this
came from. If we eliminated that special case, then I believe the #1
rule would just be that in A::B1::~B2 you look up B1
and B2 in the same place in all cases.

I don't like #2. I don't think the "old" rules represent a deliberate
design choice, just an error in the way the lookup was described. The
usage that rule permits p->X::~Y
(where Y is a typedef to X defined in X),
but I doubt people really do that. In other words, I think that #1
a more useful special case than #2 does, not that I think either special
case is very important.

One problem with the name matching rule is handling cases like:

A<int> *aip;
aip->A<int>::~A<int>(); // should work
aip->A<int>::~A<char>(); // should not

I would favor #1, while eliminating the special case of
Namespace::~Class.

Proposed resolution (10/01):

Replace the normative text of 3.4.3 [basic.lookup.qual] paragraph 5
after the first sentence with:

252.
Looking up deallocation functions in virtual destructors

There is a mismatch between 12.4 [class.dtor]
paragraph 11 and 12.5 [class.free] paragraph 4 regarding
the lookup of deallocation functions in virtual destructors.
12.4 [class.dtor] says,

At the point of definition of a virtual destructor (including an
implicit definition (12.8 [class.copy])), non-placement
operator delete shall be looked up in the scope of the destructor's
class (3.4.1 [basic.lookup.unqual]) and if found shall be accessible
and unambiguous. [Note: this assures that an operator delete
corresponding to the dynamic type of an object is available for the
delete-expression (12.5 [class.free]). ]

The salient features to note from this description are:

The lookup is "in the scope of the destructor's class," which
implies that only members are found (cf 12.2 [class.temporary]).
(The cross-reference would indicate otherwise, however, since it
refers to the description of looking up unqualified names; this kind
of lookup "spills over" into the surrounding scope.)

Only non-placement operator delete is looked up. Presumably
this means that a placement operator delete is ignored in the
lookup.

On the other hand, 12.5 [class.free] says,

If a delete-expression begins with a unary ::
operator, the deallocation function's name is looked up in global
scope. Otherwise, if the delete-expression is used to
deallocate a class object whose static type has a virtual destructor,
the deallocation function is the one found by the lookup in the
definition of the dynamic type's virtual destructor (12.4 [class.dtor]). Otherwise, if the delete-expression is used to
deallocate an object of class T or array thereof, the static
and dynamic types of the object shall be identical and the
deallocation function's name is looked up in the scope of
T. If this lookup fails to find the name, the name is looked
up in the global scope. If the result of the lookup is ambiguous or
inaccessible, or if the lookup selects a placement deallocation
function, the program is ill-formed.

Points of interest in this description include:

For a class type with a virtual destructor, the lookup is
described as being "in the definition of the dynamic type's
virtual destructor," rather than "in the scope of the dynamic
type." That is, the lookup is assumed to be an unqualified
lookup, presumably terminating in the global scope.

The assumption is made that the lookup in the virtual
destructor was successful ("...the one found...", not "...the
one found..., if any"). This will not be the case if
the deallocation function was not declared as a member somewhere
in the inheritance hierarchy.

The lookup in the non-virtual-destructor case does
find placement deallocation functions and can fail as a result.

Suggested resolution: Change the description of the
lookup in 12.4 [class.dtor] paragraph 11 to match the
one in 12.5 [class.free] paragraph 4.

Proposed resolution (10/00):

Replace 12.4 [class.dtor] paragraph 11 with
the following:

At the point of definition of a virtual destructor (including an
implicit definition), the non-array deallocation function is looked up
in the scope of the destructor's class (10.2 [class.member.lookup]),
and, if no declaration is found, the function is looked up in the
global scope. If the result of this lookup is ambiguous or
inaccessible, or if the lookup selects a placement deallocation
function, the program is ill-formed. [Note: this assures that
a deallocation function corresponding to the dynamic type of an object
is available for the delete-expression (12.5 [class.free]).]

In 12.5 [class.free] paragraph 4, change

...the deallocation function is the one found by the lookup in
the definition of the dynamic type's virtual destructor
(12.4 [class.dtor]).

to

...the deallocation function is the one selected at the point of
definition of the dynamic type's virtual destructor
(12.4 [class.dtor]).

272.
Explicit destructor invocation and qualified-ids

an explicit destructor call must always be written using a member
access operator (5.2.5 [expr.ref]); in particular, the
unary-expression~X() in a member function is not an
explicit destructor call (5.3.1 [expr.unary.op]).

This note is incorrect, as an explicit destructor call can be
written as a qualified-id, e.g., X::~X(), which
does not use a member access operator.

Proposed resolution (04/01):

Change 12.4 [class.dtor] paragraph 12 as follows:

[Note: an explicit destructor call must always be written
using a member access operator (5.2.5 [expr.ref])
or a qualified-id (5.1.1 [expr.prim.general]);
in particular, the unary-expression~X() in a
member function is not an explicit destructor call
(5.3.1 [expr.unary.op]).]

677.
Deleted operator delete and virtual destructors

Deallocation functions can't be virtual because they are static
member functions; however, according to 12.5 [class.free]
paragraph 7, they behave like virtual functions when the class's
destructor is virtual:

Since member allocation and deallocation functions are static
they cannot be virtual. [Note: however, when
the cast-expression of a delete-expression refers to an
object of class type, because the deallocation function actually
called is looked up in the scope of the class that is the dynamic type
of the object, if the destructor is virtual, the effect is the same.

Because the intent is to make any use of a deleted function
diagnosable at compile time, a virtual deleted function can neither
override nor be overridden by a non-deleted function, as described
in 10.3 [class.virtual] paragraph 14:

A function with a deleted definition (8.4 [dcl.fct.def]) shall
not override a function that does not have a deleted
definition. Likewise, a function that does not have a deleted
definition shall not override a function with a deleted definition.

One would assume that a similar kind of prohibition is needed for
deallocation functions in a class hierarchy with virtual destructors,
but it's not clear that the current specification says that.
8.4 [dcl.fct.def] paragraph 10 says,

A program that refers to a deleted function implicitly or explicitly,
other than to declare it, is ill-formed.

Furthermore, the deallocation function is looked up at the point
of definition of a virtual destructor (12.4 [class.dtor]
paragraph 11), and the function found by this lookup is considered
to be “used” (3.2 [basic.def.odr] paragraph 2).
However, it's not completely clear that this “use”
constitutes a “reference” in the sense of
8.4 [dcl.fct.def] paragraph 10, especially in a program in
which an object of a type that would call that deallocation function
is never deleted.

Suggested resolution:

Augment the list of lookup results from a virtual destructor that
render a program ill-formed in 12.4 [class.dtor] paragraph 10
to include a deleted function:

If the result of this lookup is ambiguous or inaccessible, or if the
lookup selects a placement deallocation function or a function with
a deleted definition (8.4 [dcl.fct.def]), the program is
ill-formed.

Proposed resolution (June, 2008):

Change 12.4 [class.dtor] paragraph 10 as follows:

If the result of this lookup is ambiguous or inaccessible, or if the
lookup selects a placement deallocation function or a function with
a deleted definition (8.4 [dcl.fct.def]), the program is
ill-formed.

510.
Default initialization of POD classes?

8.5 [dcl.init] paragraph 10 makes it clear that
non-static POD class objects with no initializer are left uninitialized
and have an indeterminate initial value:

If no initializer is specified for an object, and the object is of
(possibly cv-qualified) non-POD class type (or array thereof), the
object shall be default-initialized; if the object is of
const-qualified type, the underlying class type shall have a
user-declared default constructor. Otherwise, if no initializer is
specified for a non-static object, the object and its subobjects, if
any, have an indeterminate initial value; if the object or any of
its subobjects are of const-qualified type, the program is ill-formed.

12.6 [class.init] paragraph 1, however, implies that all
class objects without initializers, whether POD or not, are
default-initialized:

When no initializer is specified for an object of (possibly
cv-qualified) class type (or array thereof), or the initializer has
the form (), the object is initialized as specified in
8.5 [dcl.init]. The object is default-initialized if there
is no initializer, or value-initialized if the initializer
is ().

Proposed resolution (October, 2005):

Remove the indicated words from 12.6 [class.init] paragraph 1:

When no initializer is specified for an object of (possibly
cv-qualified) class type (or array thereof), or the initializer has
the form (), the object is initialized as specified in
8.5 [dcl.init]. The object is default-initialized if
there is no initializer, or value-initialized if the initializer
is ().

683.
Requirements for trivial subobject special functions

[Voted into the WP at the September, 2008 meeting (resolution
in paper N2757).]

Part of the decision regarding whether a class has a trivial special
function (copy constructor, copy assignment operator, default constructor)
is whether its base and member subobjects have corresponding trivial
member functions. However, with the advent of defaulted functions, it is
now possible for a single class to have both trivial and nontrivial
overloads for those functions. For example,

Although B has a trivial copy constructor and thus
satisfies the requirements in 12.8 [class.copy] paragraph 6,
the copy constructor in B that would be called by the
implicitly-declared copy constructor in D is not
trivial. This could be fixed either by requiring that all the
subobject's copy constructors (or copy assignment operators, or
default constructors) be trivial or that the one that would be
selected by overload resolution be trivial.

Proposed resolution (July, 2008):

Change 8.4 [dcl.fct.def] paragraph 9 as follows:

... A special member function that would be implicitly defined as
deleted shall not be explicitly defaulted. If a special member
function for a class X is defaulted on its first declaration,
no other special member function of the same kind (default
constructor, copy constructor, or copy assignment operator) shall be
declared in class X. A special member function is
user-provided...

Notes from the September, 2008 meeting:

The resolution adopted as part of paper N2757 differs from the
July, 2008 proposed resolution by allowing defaulted and
user-provided special member functions to coexist. Instead, a
trivial class is defined as having no non-trivial copy constructors
or copy assignment operators, and a trivial copy constructor or
assignment operator is defined as invoking only trivial copy
operations for base and member subobjects.

162.
(&C::f)() with nonstatic members

13.3.1.1 [over.match.call]
paragraph 3
says that when a call of the form

(&C::f)()

is written, the set of overloaded functions named by C::f
must not contain
any nonstatic member functions. A footnote gives the rationale: if a member
of C::f is a nonstatic member function,
&C::f is a pointer to member
constant, and therefore the call is invalid.

This is clear, it's implementable, and it doesn't directly contradict
anything else in the standard. However, I'm not sure it's consistent
with some similar cases.

In 13.4 [over.over]
paragraph 5,
second example, it is made amply clear that when &C::f is
used as the address of a function, e.g.,

int (*pf)(int) = &C::f;

the overload set can contain both static and nonstatic member functions.
The function with the matching signature is selected, and if it is
nonstatic &C::f
is a pointer to member function, and otherwise &C::f is
a normal pointer to function.

is a valid call even if the overload set contains both static and
nonstatic member functions. Overload resolution is done, and if a
nonstatic member function is selected, an implicit this-> is added,
if that is possible.

Those paragraphs seem to suggest the general rule that you do overload
resolution first and then you interpret the construct you have
according to the function selected. The fact that there are static
and nonstatic functions in the overload set is irrelevant; it's only
necessary that the chosen function be static or nonstatic to match
the context.

Given that, I think it would be more consistent if the
(&C::f)() case
would also do overload resolution first. If a nonstatic member is
chosen, the program would be ill-formed.

Proposed resolution (04/01):

Change the indicated text in 13.3.1.1 [over.match.call]
paragraph 3:

The fourth case arises from a postfix-expression of the form
&F, where
F names a set of overloaded functions.
In the context of a function call,
the set of functions named by F shall contain only non-member
functions and static member functions. [Footnote:
If F names a non-static member function, &F
is a pointer-to-member, which cannot be used with the function call syntax.]
And in this context using &F behaves the same as using&F is treated the same as
the name F by itself.
Thus, (&F)(expression-listopt)
is simply
(F)(expression-listopt), which is
discussed in 13.3.1.1.1 [over.call.func].
If the function selected by overload resolution according to
13.3.1.1.1 [over.call.func] is
a nonstatic member function, the program is
ill-formed. [Footnote: When F is a nonstatic member
function, a reference of the form &A::F is a
pointer-to-member,
which cannot be used with the function-call syntax, and
a reference of the form &F is an invalid use of the
"&" operator on a nonstatic member function.]
(The resolution of &F in other contexts is described in
13.4 [over.over].)

If the ordinary unqualified lookup of the name finds the declaration
of a class member function, the associated namespaces and classes are
not considered.

to

If the ordinary unqualified lookup of the name finds the declaration
of a class member function, or a block-scope function declaration
that is not a using-declaration, the associated namespaces
and classes are not considered.

Mark Mitchell:
It looks to me like G++ is correct, given 13.3.1.1.1 [over.call.func].
This case is the "unqualified function call" case described in paragraph
3 of that section. ("Unqualified" here means that there is no "x->" or
"x." in front of the call, not that the name is unqualified.)

That paragraph says that you first do name lookup. It then asks you
to look at what declaration is returned. (That's a bit confusing; you
presumably get a set of declarations. Or maybe not; the name lookup
section says that if name lookup finds a non-static member in a context
like this the program is in error. But surely this program is not
erroneous. Hmm.)

Anyhow, you have -- at least -- "S::f(char)" as the result of the
lookup.

The keyword "this" is not in scope, so "all overloaded declarations of
the function name in T become candidate functions and a contrived object
of type T becomes the implied object argument." That means we get
both versions of "f" at this point. Then, "the call is ill-formed,
however, if overload resolution selects one of the non-static members
of T in this case." Since, in this case, "S::f(char)" is the winner,
the program is ill-formed.

Steve Adamczyk:
This result is surprising, because we've selected a function
that we cannot call, when there is another function that can be
called. This should either be ambiguous, or it should select the static
member function. See also 13.3.1 [over.match.funcs] paragraph 2:
"Similarly, when
appropriate, the context can construct an argument list that
contains an implied object argument..."

Notes from October 2002 meeting:

We agreed that g++ has it right, but the standard needs to be clearer.

Proposed resolution (October 2002, revised April 2003):

Change 13.3.1.1.1 [over.call.func] paragraphs 2 and 3 as
follows:

In qualified function calls, the name to be resolved is an
id-expression and is preceded by an -> or .
operator. Since the construct A->B is generally equivalent
to (*A).B, the rest of clause 13 [over]
assumes, without loss of generality, that all member function calls have been
normalized to the form that uses an object and the . operator.
Furthermore, clause 13 [over]
assumes that the postfix-expression that is the left
operand of the . operator has type ``cvT''
where T denotes a class.
[Footnote: Note that cv-qualifiers on the type of
objects are significant in overload resolution for both lvalue and
class rvalue objects. --- end footnote]
Under this assumption, the id-expression in the
call is looked up as a member function of T following the rules for
looking up names in classes (10.2 [class.member.lookup]).
If a member function is found, that function and its overloaded
declarationsThe function declarations found by that lookup
constitute the set of candidate functions. The argument list is the
expression-list in the call augmented by the addition of the
left operand of the . operator in the normalized member
function call as the implied object argument (13.3.1 [over.match.funcs]).

In unqualified function calls, the name is
not qualified by an -> or . operator and has the more
general form of a primary-expression. The name is looked up in the
context of the function call following the normal rules for name lookup in
function calls (3.4.2 [basic.lookup.argdep]
3.4 [basic.lookup]).
If the name resolves to a non-member function declaration, that
function and its overloaded declarationsThe function declarations found by that lookup
constitute the set of candidate functions.
[Footnote: Because of the usual name hiding rules,
these will be introduced by declarations or by using-directives all
found in the same block or all found at namespace scope. --- end footnote]Because of the rules for name lookup,
the set of candidate functions consists (1) entirely of non-member functions
or (2) entirely of member functions of some class T. In
case (1), tThe argument list is the same as
the expression-list in the call.
If the name resolves to a nonstatic member function, then the
function call is actually a member function call.In case (2), the argument list is the expression-list in the
call augmented by the addition of an implied object argument as in
a qualified function call.
If the keyword this (9.3.2 [class.this])
is in scope and refers to the class Tof that member
function, or a derived class thereofof T, then
the function call is transformed into a normalized qualified
function call usingimplied object argument is(*this)as the
postfix-expression
to the left of the . operator. The candidate
functions and argument list are as described for qualified function calls
above. If the keyword this is not in scope or refers to
another class, then name resolution found a static member of some
class T.
In this case,all overloaded declarations of the function name in
T become candidate functions and a contrived object of
type T becomes the implied object argument.
[Footnote: An implied object argument must be
contrived to correspond to the implicit object parameter attributed to member
functions during overload resolution. It is not used in the call to the
selected function. Since the member functions all have the same implicit
object
parameter, the contrived object will not be the cause to select or reject a
function. --- end footnote]
If the argument list is augmented by a contrived object
and The call is ill-formed, however, if overload
resolution selects one of the non-static member functions of
T, the
call is ill-formed in this case.

280.
Access and surrogate call functions

According to 13.3.1.1.2 [over.call.object] paragraph 2, when
the primary-expressionE in the function call syntax
evaluates to a class object of type "cvT", a
surrogate call function corresponding to an appropriate conversion
function declared in a direct or indirect base class B of
T is included or not included in the set of candidate
functions based on class B being accessible.

For instance in the following code sample, as per the paragraph in
question, the expression c(3) calls f2, instead of
the construct being ill-formed due to the conversion function
A::operator fp1 being inaccessible and its corresponding
surrogate call function providing a better match than the surrogate
call function corresponding to C::operator fp2:

The fact that the accessibility of a base class influences the
overload resolution process contradicts the fundamental language rule
(3.4 [basic.lookup] paragraph 1, and 13.3 [over.match] paragraph 2) that access checks are applied only once
name lookup and function overload resolution (if applicable) have
succeeded.

Notes from 4/02 meeting:

There was some concern about whether 10.2 [class.member.lookup] (or
anything else, for that matter) actually defines "ambiguous base class".
See issue 39. See also
issue 156.

Notes from October 2002 meeting:

It was suggested that the ambiguity check is done as part of the
call of the conversion function.

Proposed resolution (revised October 2002):

In 13.3.1.1.2 [over.call.object] paragraph 2, replace the
last sentence

Similarly, surrogate call functions are added to the set of candidate
functions for each conversion function declared in an accessible base
class provided the function is not hidden within T by another
intervening declaration.

with

Similarly, surrogate call functions are added to the set of candidate
functions for each conversion function declared in a base class of
T provided the function is not hidden within T by
another intervening declaration.

Replace 13.3.1.1.2 [over.call.object] paragraph 3

If such a surrogate call function is selected by overload resolution,
its body, as defined above, will be executed to convert E to the
appropriate function and then to invoke that function with the
arguments of the call.

by

If such a surrogate call function is selected by overload resolution,
the corresponding conversion function will be called to convert
E to the appropriate function pointer or reference,
and the function will then be invoked with the arguments of the call.
If the conversion function cannot be called
(e.g., because of an ambiguity), the program is ill-formed.

required to be diagnosed because of the op<<? The reason
being that the class may actually have an op<<(const char *) in it.

What is it? un- or ill-something? Diagnosable? No problem at all?

Steve Adamczyk:
I don't know of any requirement in the standard that the class be complete.
There is a rule that will instantiate a class template in order to be able
to see whether it has any operators. But I wouldn't think one wants to
outlaw the above example merely because the user might have an
operator<<
in the class; if he doesn't, he would not be pleased that the above
is considered invalid.

Mike Miller:
Hmm, interesting question. My initial reaction is that it just
uses ::operator<<; any A::operator<<
simply won't be considered in
overload resolution. I can't find anything in the Standard that
would say any different.

The closest analogy to this situation, I'd guess, would be
deleting a pointer to an incomplete class;
5.3.5 [expr.delete] paragraph 5 says that that's
undefined behavior if the complete type has a non-trivial destructor
or an operator delete. However, I tend to think that that's because
it deals with storage and resource management, not just because it
might have called a different function. Generally, overload
resolution that goes one way when it might have gone another with
more declarations in scope is considered to be not an error, cf
7.3.3 [namespace.udecl] paragraph 9,
14.6.3 [temp.nondep] paragraph 1, etc.

So my bottom line take on it would be that it's okay, it's up to
the programmer to ensure that all necessary declarations are in
scope for overload resolution. Worst case, it would be like the
operator delete in an incomplete class -- undefined behavior, and
thus not required to be diagnosed.

13.3.1.2 [over.match.oper] paragraph 3, bullet 1, says,
"If T1 is a class type, the set of member candidates is the result
of the qualified lookup of T1::operator@
(13.3.1.1.1 [over.call.func])." Obviously, that lookup is
not possible if T1 is
incomplete. Should
13.3.1.2 [over.match.oper] paragraph 3, bullet 1, say
"complete class type"? Or does the inability to perform
the lookup mean that the program is ill-formed?
3.2 [basic.def.odr] paragraph 4 doesn't apply,
I don't think, because you don't know whether you'll be applying a
class member access operator until you know whether the operator
involved is a member or not.

Notes from October 2003 meeting:

We noticed that the title of this issue did not match the
body. We checked the original source and then corrected the title
(so it no longer mentions templates).

We decided that this is similar to other cases like
deleting a pointer to an incomplete class, and it should not be
necessary to have a complete class. There is no undefined
behavior.

Proposed Resolution (October 2003):

Change the first bullet of 13.3.1.2 [over.match.oper] paragraph 3
to read:

If T1 is a complete class type, the set of member candidates
is the result of the qualified lookup of T1::operator@
(13.3.1.1.1 [over.call.func]); otherwise, the set of member
candidates is empty.

60.
Reference binding and valid conversion sequences

Does dropping a cv-qualifier on a reference binding prevent the binding
as far as overload resolution is concerned?
Paragraph 4 says "Other restrictions
on binding a reference to a particular argument do not affect the formation
of a conversion sequence." This was intended to refer to things like access
checking, but some readers have taken that to mean that any aspects of
reference binding not mentioned in this section do not preclude the binding.

Proposed resolution (10/01):

In 13.3.3.1.4 [over.ics.ref] paragraph 4 add the
indicated text:

Other restrictions on binding a reference to a particular argument that
are not based on the types of the reference and the argument do
not affect the formation of a standard conversion sequence, however.

The question is whether &f<int> identifies a unique function.
&g<int> is clearly ambiguous.

13.4 [over.over]
paragraph 1
says that a function template name is considered to name a
set of overloaded functions. I believe it should be expanded to say that
a function template name with an explicit template argument list is also
considered to name a set of overloaded functions.

In the general case, you need to have a destination type in order
to identify a unique function. While it is possible to permit this, I
don't think it is a good idea because such code depends on there only
being one template of that name that is visible.

The EDG front end issues an error on this use of "f".
egcs 1.1.1 allows
it, but the most current snapshot of egcs that I have also issues an error
on it.

It has been pointed out that when dealing with nontemplates, the rules
for taking the address of a single function differ from the rules
for an overload set, but this asymmetry is needed for C compatibility.
This need does not exist for the template case.

My feeling is that a general rule is better than a general rule plus
an exception. The general rule is that you need a destination type
to be sure that the operation will succeed. The exception is when
there is only one template in the set and only then when you provide
values for all of the template arguments.

It is true that in some cases you can provide a shorthand, but only if
you encourage a fragile coding style (that will cause programs to break
when additional templates are added).

I think the standard needs to specify one way or the other how this
case should be handled. My recommendation would be that it is
ill-formed.

If John's recommendation is adopted, this code will become
ill-formed. I bet there will be a lot of explanation for users
necessary why this fails and that they have to change
add<10> to something like
(int (*)(int))add<10>.

This example code is probably common practice because this
use of the STL is typical and is accepted in many current
implementations. I strongly urge that this issue be resolved
in favor of keeping this code valid.

Bill Gibbons: I find this rather surprising. Shouldn't
a template-id which specifies all of the template arguments
be treated like a declaration-only explicit instantiation,
producing a set of ordinary function declarations? And when that
set happens to contain only one function, shouldn't the example
code work?

The consensus of the group was that the add example
should not be an error.

Proposed resolution (October 2002):

In 13.4 add to the end of paragraph 2:

[Note: As described in 14.8.1 [temp.arg.explicit],
if deduction fails and the
function template name is followed by an explicit template
argument list, the template-id is then examined to
see whether it identifies a single function template
specialization. If it does, the template-id is
considered to be an lvalue for that function template
specialization. The target type is not used in that
determination.]

In 14.8.1 [temp.arg.explicit] paragraph 2 insert before
the first example:

In contexts where deduction is done and fails,
or in contexts where deduction is not done,
if a template argument list is specified and it, along with any
default template arguments, identifies a single function template
specialization, then the template-id is an lvalue
for the function template specialization.

221.
Must compound assignment operators be member functions?

Is the intent of 13.5.3 [over.ass] paragraph 1 that
all assignment operators be non-static member functions
(including operator+=, operator*=, etc.) or only
simple assignment operators (operator=)?

Notes from 04/00 meeting:

Nearly all references to "assignment operator" in the IS mean
operator= and not the compound assignment operators. The ARM
was specific that this restriction applied only to operator=.
If it did apply to compound assignment operators, it would be
impossible to overload these operators for bool operands.

Proposed resolution (04/01):

Change the title of 5.17 [expr.ass] from "Assignment
operators" to "Assignment and compound assignment operators."

Change the first sentence of 5.17 [expr.ass]
paragraph 1 from

There are several assignment operators, all of which group
right-to-left. All require a modifiable lvalue as their left operand,
and the type of an assignment expression is that of its left operand.
The result of the assignment operation is the value stored in the left
operand after the assignment has taken place; the result is an lvalue.

to

The assignment operator (=) and the compound assignment
operators all group right-to-left. All require a modifiable lvalue as
their left operand and return an lvalue with the type and value of
the left operand after the assignment has taken place.

Additional note (10/00): Paragraphs 2-6 of
5.17 [expr.ass] should all be understood to apply to
simple assignment only and not to compound assignment operators.

(This then is a copy of the two lines in 5.2 [expr.post]
covering "->dtor")

Alternatively remove the sentence "It implements class member
access using ->" and the syntax line following.

Reasons:

Currently stdc++ is inconsistent when handling expressions of
the form "postfixexpression->scalar_type_dtor()":
If "postfixexpression" is a pointer to the scalar type, it is OK,
but if "postfixexpression" refers to any smart pointer class
(e.g. iterator or allocator::pointer) with class specific
CLASS::operator->() returning pointer to the scalar type, then
it is ill-formed; so while c++98 does allow CLASS::operator->()
returning pointer to scalar type, c++98 prohibits any '->'-expression
involving this overloaded operator function.

Not only is this behaviour inconsistent, but also when
comparing the corresponding chapters of c++pl2 and stdc++98
it looks like an oversight and unintended result.
Mapping between stdc++98 and c++pl2:

For the single line of c++pl2.r.5.2 covering "->dtor",
5.2 [expr.post] has two lines.
Analogously c++pl2.r.5.2.4 has been doubled to 5.2.4 [expr.pseudo]
and 5.2.5 [expr.ref].
From 13.5.6 [over.ref], the sentence forbiding CLASS::operator->()
returning pointer to scalar type has been removed.
Only the single line of c++pl2.r.13.4.6 (<-> c++pl2.r.5.2's
single line) has not gotten its 2nd line when converted
into 13.5.6 [over.ref].

Additionally GCC32 does is right (but against 13.5.6 [over.ref]).

AFAICS this would not break old code except compilers like VC7x
and Comeau4301.

It does not add new functionality, cause any expression
class_type->scalar_type_dtor() even today can be substituted
through (*class_type).scalar_type_dtor().

Without this fix, template functions like
some_allocator<T>::destroy(p)
must use "(*p).~T()" or "(*p).T::~T()" when calling the destructor,
otherwise the simpler versions "p->~T()" or "p->T::~T()"
could be used.

An expression x->m is interpreted
as (x.operator->())->m for a class object x of
type T if T::operator->() exists and if the
operator is selected as the best match function by the overload
resolution mechanism (13.3 [over.match]).

425.
Set of candidates for overloaded built-in operator with float operand

The code is compiled without errors or warnings from EDG-based compilers
(Comeau, Intel), but rejected from others (GCC, MSVC [7.1]). The
question: Who is correct? Where should I file the bug report?

To explain the problem: The EDG seems to see 1.0f*a as a call to the
unambiguous operator*(float,float) and thus casts 'a' to 'float'. The
other compilers have several operators (float*float, float*double,
float*int, ...) available and thus can't decide which cast is
appropriate. I think the latter is the correct behaviour, but I'd like
to hear some comments from the language lawyers about the standard's
point of view on this problem.

Since your first argument is of type float, the (float, float) case is
preferred
over the (double, double) case (the latter would require a floating-point
promotion).

Stave Adamczyk:
Daveed's statement is wrong; as Andreas says, the prototypes in
13.6 [over.built] paragraph 12
have pairs of types, not the same type twice. However, the list of
possibilities considered in Andreas' message is wrong also:
13.6 [over.built] paragraph 12
calls for pairs of promoted arithmetic types, and float is not
a promoted type (it promotes to double -- see
4.6 [conv.fpprom]).

Nevertheless, the example is ambiguous. Let's look at the overload
resolution costs. The right operand is always going to have a
user-defined-conversion cost (the template conversion function
will convert directly to the const version of the second
parameter of the prototype). The left operand is always going to
have a promotion (float --> double) or a standard conversion
(anything else). So the cases with promotions are better
than the others. However, there are several of those
cases, with second parameters of type int, unsigned int, long,
unsigned long, double, and long double, and all of those are
equally good. Therefore the example is ambiguous.

I can't tell if that's "promoted integral types plus (all) floating
types" or "promoted integral types plus (promoted) floating types".
I thought the latter was intended, but indeed the usual arithmetic
conversions could give you "float + float", so it makes sense that
float would be one of the possibilities. We should discuss this to
make sure everyone has the same interpretation.

204.
Exported class templates

14 [temp]
paragraph 7 allows class
templates to be declared exported, including member classes and member
class templates (implicitly by virtue of exporting the
containing template class). However, paragraph 8 does not exclude
exported class templates from the statement that

An exported template need only be declared (and not necessarily
defined) in a translation unit in which it is instantiated.

This is an incorrect implication; however, it is also not dispelled in
14.7.1 [temp.inst]
paragraph 6:

If an implicit instantiation of a class template specialization is
required and the template is declared but not defined, the program is
ill-formed.

This wording says nothing about the translation unit in which the
definition must be provided. Contrast this with
14.7.2 [temp.explicit]
paragraph 3:

A definition of a class template or a class member template shall be
in scope at the point of the explicit instantiation of the class
template or class member template.

John Spicer opined that even though 14 [temp]
paragraph 7 speaks of "declaring a class template exported," that does
not mean that the class template is "an exported template" in the
sense of paragraph 8. He suggested clarifying paragraph 7 to that
effect instead of the change to paragraph 8 suggested above, and
questioned the need for a change to 14.7.1 [temp.inst].

In fact, I think the declaration in "File 1" could be a definition and this
would still satisfy the the requirements of the standard, which definitely
seems wrong.

Proposed Resolution (revised October 2002):

Replace 14 [temp] paragraphs 6, 7, and 8 by the
following text:

A template-declaration may be preceded by the export keyword.
Such a template is said to be exported.
Declaring exported a class template is equivalent to declaring
exported all of its non-inline member functions, static data members,
member classes, member class templates, and non-inline member function
templates.

If a template is exported in one translation unit, it
shall be exported in all translation units in which
it appears; no diagnostic is required.
A declaration of an exported template shall appear with the export
keyword before any point of instantiation (14.6.4.1 [temp.point])
of that template in that translation unit. In addition, the first
declaration of an exported template containing the export keyword
must not follow the definition of that template. The export
keyword shall not be used in a friend declaration.

Templates defined in an unnamed namespace, inline functions, and
inline function templates shall not be exported.
An exported non-class template shall be defined only once in a program;
no diagnostic is required. An exported non-class template
need only be declared (and not necessarily defined) in a translation
unit in which it is instantiated.

A non-exported non-class template must be defined in every translation unit
in which it is implicitly instantiated (14.7.1 [temp.inst]),
unless the corresponding
specialization is explicitly instantiated (14.7.2 [temp.explicit])
in some translation unit; no diagnostic is required.

335.
Allowing export on template members of nontemplate classes

The syntax for "export" permits it only on template declarations.
Clause 14 [temp] paragraph 6 further restricts "export"
to appear only
on namespace scope declarations. This means that you can't export
a member template of a non-template class, as in:

class A {
template <class T> void f(T);
};

You can, of course, put export on the definition:

export template <class T> void A<T>::f(T){}

but in order for the template to be used from other translation units
(the whole point of export) the declaration in the other translation
unit must also be declared export.

There is also the issue of whether or not we should permit this usage:

export struct A {
template <class T> void f(T);
};

My initial reaction is to retain this prohibition as all current uses
of "export" are preceding the "template" keyword.

If we eliminate the requirement that "export" precede "template" there
is a similar issue regarding this case, which is currently prohibited:

534.
template-names and operator-function-ids

Taken literally, 14 [temp] paragraph 2 does not
permit operator functions to be templates:

In a function template declaration, the declarator-id shall be a
template-name (i.e., not a template-id).

and, in 14.2 [temp.names] paragraph 1, a template-name
is defined to be simply an identifier.

Issue 301 considered and rejected the
idea of changing the definition of template-name to include
operator-function-ids and conversion-function-ids.
Either that decision should be reconsidered or the various references
in the text to template-name should be examined to determine
if they should also mention the non-identifier possibilities
for function template names.

184.
Default arguments in template template-parameters

John Spicer:
Where can default values for the template parameters of
template template parameters be specified and where so they apply?

For normal template parameters, defaults can be specified only in
class template declarations and definitions, and they accumulate
across multiple declarations in the same way that function default
arguments do.

I think that defaults for parameters of template template parameters should
be handled differently, though. I see no reason why such a default should
extend beyond the template declaration with which it is associated.
In other words, such defaults are a property of a specific template
declaration and are not part of the interface of the template.

Gabriel Dos Reis:
On the other hand I fail to see the reasons why we should introduce
yet another special rule to handle that situation differently. I
think we should try to keep rules as uniform as possible.
For default values, it has been the case that one
should look for any declaration specifying default values. Breaking
that rules doesn't buy us anything, at least as far as I can see.
My feeling is that [allowing different defaults in different
declarations] is very confusing.

Mike Miller:
I'm with John on this one. Although we don't have the
concept of "prototype scope" for template parameter lists,
the analogy with function parameters would suggest that the
two declarations of T (in the template class definition and
the template member function definition) are separate
declarations and completely unrelated. While it's true that
you accumulate default arguments on top-level declarations in
the same scope, it seems to me a far leap to say that we ought
also to accumulate default arguments in nested declarations.
I would expect those to be treated as being in different
scopes and thus not to share default argument information.

When you look up the name T in the definition of
A<T>::f(),
the declaration you find has no default argument for the
parameter of T, so T<> should not be allowed.

Proposed Resolution (revised October 2002):

In 14.1 [temp.param], add the following as a new paragraph
at the end of this section:

A template-parameter of a template template-parameter
is permitted to have a default template-argument. When such
default arguments are specified, they apply to the template
template-parameter in the scope of the template
template-parameter. [Example:

215.
Template parameters are not allowed in nested-name-specifiers

According to 14.1 [temp.param] paragraph 3, the following
fragment is ill-formed:

template <class T>
class X{
friend void T::foo();
};

In the friend declaration, the T:: part is a
nested-name-specifier (8 [dcl.decl] paragraph 4),
and T must be a class-name or a namespace-name
(5.1.1 [expr.prim.general] paragraph 7). However, according to
14.1 [temp.param] paragraph 3, it is only a
type-name. The fragment should be well-formed, and
instantiations of the template allowed as long as the actual template
argument is a class which provides a function member foo. As
a result of this defect, any usage of template parameters in nested
names is ill-formed, e.g., in the example of 14.6 [temp.res] paragraph 2.

Notes from 04/00 meeting:

The discussion at the meeting revealed a self-contradiction in the
current IS in the description of nested-name-specifiers.
According to the grammar in 5.1.1 [expr.prim.general] paragraph 7,
the components of a nested-name-specifier must be either
class-names or namespace-names, i.e., the constraint is
syntactic rather than semantic. On the other hand, 3.4.3 [basic.lookup.qual] paragraph 1 describes a semantic constraint: only
object, function, and enumerator names are ignored in the lookup for
the component, and the program is ill-formed if the lookup finds
anything other than a class-name or namespace-name. It
was generally agreed that the syntactic constraint should be
eliminated, i.e., that the grammar ought to be changed not to use
class-or-namespace-name.

A related point is the explicit prohibition of use of template
parameters in elaborated-type-specifiers in 7.1.6.3 [dcl.type.elab] paragraph 2. This rule was the result of an
explicit Committee decision and should not be unintentionally voided
by the resolution of this issue.

Proposed resolution (04/01):

Change 5.1.1 [expr.prim.general] paragraph 7 and
A.4 [gram.expr] from

nested-name-specifier:

class-or-namespace-name::nested-name-specifieropt

class-or-namespace-name:: templatenested-name-specifier

class-or-namespace-name:

class-name

namespace-name

to

nested-name-specifier:

type-or-namespace-name::nested-name-specifieropt

type-or-namespace-name:: templatenested-name-specifier

type-or-namespace-name:

type-name

namespace-name

This resolution depends on the resolutions for issues
245 (to change the name lookup rules in
elaborated-type-specifiers to include all type-names)
and 283 (to categorize template
type-parameters as type-names).

Notes from 10/01 meeting:

There was some sentiment for going with simply identifier
in front of the "::", and stronger sentiment for going
with something with a more descriptive name if possible.
See also issue 180.

Notes from April 2003 meeting:

This was partly resolved by the changes for issue
125. However, we also need to add a semantic check in
3.4.3 [basic.lookup.qual] to allow T::foo and we need to
reword the first sentence of 3.4.3 [basic.lookup.qual].

Proposed resolution (October, 2004):

Change 3.4.3 [basic.lookup.qual] paragraph 1 as
follows:

The name of a class or namespace member can be referred to after
the :: scope resolution operator (5.1.1 [expr.prim.general]) applied to a nested-name-specifier that
nominates its class or namespace. During the lookup for a name
preceding the :: scope resolution operator, object,
function, and enumerator names are ignored. If the name found
is not a class-name (clause 9 [class]) or
namespace-name (7.3.1 [namespace.def])does
not designate a class or namespace, the program is
ill-formed. [...]

Notes from the April, 2005 meeting:

The 10/2004 resolution does not take into account the fact that
template type parameters do not designate class types in the context
of the template definition. Further drafting is required.

Proposed resolution (April, 2006):

Change 3.4.3 [basic.lookup.qual] paragraph 1 as
follows:

The name of a class or namespace member can be referred to after
the :: scope resolution operator (5.1.1 [expr.prim.general]) applied to a nested-name-specifier that
nominates its class or namespace. During the lookup for a name
preceding the :: scope resolution operator, object,
function, and enumerator names are ignored. If the name found
is not a class-name (clause 9 [class]) or
namespace-name (7.3.1 [namespace.def])does
not designate a namespace or a class or dependent type, the program is
ill-formed. [...]

226.
Default template arguments for function templates

The prohibition of default template arguments for function
templates is a misbegotten remnant of the time where freestanding
functions were treated as second class citizens and required all
template arguments to be deduced from the function arguments
rather than specified.

The restriction seriously cramps programming style by unnecessarily making
freestanding functions different from member functions, thus making it harder
to write STL-style code.

Suggested resolution:

Replace

A default template-argument shall not be specified in a
function template declaration or a function template definition, nor
in the template-parameter-list of the definition of a member of
a class template.

by

A default template-argument shall not be specified in the
template-parameter-list of the definition of a member of a
class template.

The actual rules are as stated for arguments to class templates.

Notes from 10/00 meeting:

The core language working group was amenable to this change.
Questions arose, however, over the interaction between default
template arguments and template argument deduction: should it be
allowed or forbidden to specify a default argument for a deduced
parameter? If it is allowed, what is the meaning: should one or
the other have priority, or is it an error if the default and
deduced arguments are different?

Notes from the 10/01 meeting:

It was decided that default arguments should be allowed on friend
declarations only when the declaration is a definition. It was
also noted that it is not necessary to insist that if there
is a default argument for a given parameter all following parameters
have default arguments, because (unlike in the class case)
arguments can be deduced if they are not specified.

A default template-argument may be specified in a class
template declaration or a class template definition. A default
template-argument shall not be specified in a function
template declaration or a function template definition, nor in the
template-parameter-list of the definition of a member of a
class template.

with

A default template-argument may be specified in a template
declaration. A default
template-argument shall not be specified in the
template-parameter-lists of the definition of a member
of a class template that appears outside of the member's class.

In 14.1 [temp.param] paragraph 9, replace

A default template-argument shall not be specified in a friend template
declaration.

with

A default template-argument shall not be specified in a friend
class template declaration. If a friend function template declaration
specifies a default template-argument, that declaration shall be
a definition and shall be the only declaration of the function template
in the translation unit.

In 14.1 [temp.param] paragraph 11, replace

If a template-parameter has a default template-argument,
all subsequent template-parameters shall have a default
template-argument supplied.

with

If a template-parameter of a class template has a default
template-argument, all subsequent template-parameters
shall have a default template-argument supplied.
[Note: This is not a requirement for function templates
because template arguments might be deduced (14.8.2 [temp.deduct]).]

In 14.8 [temp.fct.spec] paragraph 1, replace

Template arguments can either be explicitly specified when
naming the function template specialization or be deduced
(14.8.2 [temp.deduct]) from the context, e.g. from the
function arguments in a call to the function template
specialization.

with

Template arguments can be explicitly specified when naming the
function template specialization, deduced from the context
(14.8.2 [temp.deduct]), e.g., deduced from the function
arguments in a call to the function template specialization), or
obtained from default template arguments.

In 14.8.1 [temp.arg.explicit] paragraph 2, replace

Trailing template arguments that can be deduced
(14.8.2 [temp.deduct]) may be omitted from the list
of explicit template-arguments.

with

Trailing template arguments that can be deduced
(14.8.2 [temp.deduct]) or obtained from default
template-arguments may be omitted from the list of
explicit template-arguments.

In 14.8.2 [temp.deduct] paragraph 1, replace

The values can be either explicitly specified or, in some
cases, deduced from the use.

with

The values can be explicitly specified or, in some cases,
be deduced from the use or obtained from default
template-arguments.

In 14.8.2 [temp.deduct] paragraph 4, replace

The resulting substituted and adjusted function type is used as
the type of the function template for template argument
deduction. When all template arguments have been deduced, all
uses of template parameters in nondeduced contexts are replaced
with the corresponding deduced argument values. If the
substitution results in an invalid type, as described above,
type deduction fails.

with

The resulting substituted and adjusted function type is used as
the type of the function template for template argument
deduction. If a template argument has not been deduced, its
default template argument, if any, is used. [Example:

When all template arguments have been deduced or obtained from
default template arguments, all uses of template parameters in
nondeduced contexts are replaced with the corresponding deduced
or default argument values. If the substitution results in an
invalid type, as described above, type deduction fails.

The issue is whether the access to the default argument type BASE::PI
is checked before or after it is known that BASE is a base class of
the template. To some extent, one needs to develop the list of
template arguments (and therefore evaluate the default argument)
before one can instantiate the template, and
one does not know what base classes the template has until it has
been instantiated.

The convincing argument here is that if we had only the declaration
of the template (including the default argument), we would expect
it to be usable in exactly the same way as the version with the
definition. However, the special access needed is visible only
when the definition is available. So the above should be an error,
and information from the definition cannot affect the access of
the default arguments.

Proposed Resolution (April 2003):

Add a new paragraph 16 to 14.1 [temp.param] after
paragraph 15:

Since a default template-argument is encountered before any
base-clause there is no special access to members used in a default
template-argument. [Example:

We decided that template parameter default arguments should
have their access checked in the context where they appear
without special access for the entity declared (i.e., they are
different than normal function default arguments). One reason:
we don't know the instance of the template when we need the
value. Second reason: compilers want to parse and throw away the
form of the template parameter default argument, not save it and
check it for each instantiation.

Class templates should be treated the same as function templates
in this regard. The base class information is in the same category
as friend declarations inside the class itself -- not available.
If the body were used one would need to instantiate it in order
to know whether one can name it.

Proposed resolution (October, 2004):

Add the following as a new paragraph following the last
paragraph of 11 [class.access] (but before the new
paragraph inserted by the resolution of issue 372, if adopted):

The names in a default template-argument (14.1 [temp.param]) have their access checked in the context in which
they appear rather than at any points of use of the default
template-argument. [Example:

This is an error because X is not a member template;
14.2 [temp.names] paragraph 5 says:

If a name prefixed by the keyword template is not the name
of a member template, the program is ill-formed.

In a way this makes perfect sense: X is found to be a template
using ordinary lookup even though p has a dependent type.
However, I think this makes the use of the template prefix
even harder to teach.

Was this intentionally outlawed?

Proposed Resolution (4/02):

Elide the first use of the word "member" in
14.2 [temp.names] paragraph 5 so that its first sentence reads:

If a name prefixed by the keyword template is not the name of a
member template, the program is ill-formed.

This is ill-formed according to the standard, since operator+ is
not a template-name.

Suggested resolution:

I think the right rule is

template-name:

identifieroperator-function-idconversion-function-id

John Spicer adds that there's some question about whether
conversion functions should be included, as they cannot have template
argument lists.

Notes from 4/02 meeting:

If the change is made as a syntax change, we'll need a semantic
restriction to avoid operator+<int> as a class.
Clark Nelson will work on a compromise proposal -- not the minimal
change to the syntax proposed, not the maximal change either.

Clark Nelson (April 2003):

The proposed solution (adding operator-function-id as an
alternative for template-name) would have a large impact on
the language described by the grammar. Specifically, for example,
operator+<int> would become a syntactically valid
class-name.

On the other hand, a change with (I believe) exactly the desired
effect on the language accepted, would be to modify
operator-function-id itself:

operator-function-id:

operatoroperatoroperatoroperator<template-argument-listopt>

(Steve Adamczyk: this change was already made by
issue 38 and is in TC1.)

Then there is the first sentence of 14.2 [temp.names]
paragraph 3:

After name lookup (3.4 [basic.lookup])
finds that a name is a
template-name, if this name is followed by a
<, the < is always taken as the
beginning of a template-argument-list and never as a name
followed by the less-than operator.

This description seems to be adequate for names of class templates.
As far as I can tell, the only ambiguity it resolves is from something
that starts with new X <, in the
scope of a class template X. But as far as I can tell is
already inadequate for names of function templates, and is even worse
for operator function templates.

Probably < should always be interpreted as
introducing a template-argument-list if any member of the
overload set is a function template. After all, function pointers are
very rarely compared for ordering, and it's not clear what other rule
might be workable.

I'm inclined to propose the simplest rule possible for
operator-function-ids: if one is followed by
<, then what follows is interpreted as a
template-argument-list, unconditionally. Of course, if no
template for that operator has been declared, then there's an error.

Also, note that if the operator in question is < or <<, it is possible to run into a problem similar to the famous >> nested template argument list closing delimiter problem.
However, since in this case (at least) one of the < characters has a radically different interpretation than the other, and for other reasons as well, this is unlikely to be nearly as much of a practical problem as the >> problem.

Notes from April 2003 meeting:

We felt that the operator functions should not be special-cased.
They should be treated like any other name.

September 2003:

Clark Nelson has provided the changes in N1490=03-0073.

Notes from October 2003 meeting:

We reviewed Clark Nelson's N1490. Clark will revise it and
introduce a new syntax term for an identifier or
the name of an operator function.

Notes from the April, 2005 meeting:

The CWG suggested a new approach to resolving this issue: the
existing term template-id will be renamed
to class-template-id, the term template-id will be
defined to include operator functions with template arguments, and any
current uses of template-id (such as in the definition
of elaborated-type-specifier) where an operator function is not
appropriate will be changed to refer to class-template-id.

Proposed resolution (April, 2006):

As specified in document J16/05-0156 = WG21 N1896, except that:

In change 9 (3.4.5 [basic.lookup.classref]), omit the change from
“entire postfix-expression” to
“nested-name-specifier.”

In change a (3.4.3.1 [class.qual] paragraph 1,
third bullet), omit the change from “entire
postfix-expression” to “qualified-id.”

If a name prefixed by the keyword template is not the name of
a template, the program is ill-formed. [Note: the
keyword template may not be applied to non-template members
of class templates. —end note] Furthermore, names of
member templates shall not be prefixed by the
keyword template if the postfix-expression
or qualified-id does not appear in the scope of a template.
[Note: just as is the case with the typename prefix,
the template prefix is allowed in cases where it is not
strictly necessary; i.e., when the nested-name-specifier
or the expression on the left of the ->
or ., or the nested-name-specifier is not
dependent on a template-parameter, or the use does not
appear in the scope of a template. —end note]

246.
Jumps in function-try-block handlers

Is it permitted to jump from a handler of a
function-try-block into the body of the function?

15 [except] paragraph 2 would appear to disallow
such a jump:

A goto, break, return, or continue
statement can be used to transfer control out of a try block or
handler, but not into one.

However, 15.3 [except.handle] paragraph 14 mentions
only constructors and destructors for the prohibition:

If the handlers of a function-try-block contain a jump into the
body of a constructor or destructor, the program is ill-formed.

Is this paragraph simply reemphasizing the more general
restriction, or does it assume that such a jump would be permitted
for functions other than constructors or destructors? If the
former interpretation is correct, it is confusing and should be
either eliminated or turned into a note. If the latter
interpretation is accurate, 15 [except] paragraph 2
must be revised.

John Spicer:
I don't think the standard really addresses this case. There
is wording about access checking of things used as template arguments,
but that doesn't address accessing members of the template argument
type (or template) from within the template.

This example is similar, but does not use template template arguments.

This gets an error from most compilers, though the standard is probably
mute on this as well. An error makes sense -- if there is no error,
there is a hole in the access checking. (The special rule about
no access checks on template parameters is not a hole, because the access
is checked on the type passed in as an argument. But when you look
up something in the scope of a template parameter type, you need to
check the access to the member found.)

The logic in the template template parameter case should be similar:
anytime you look up something in a template-dependent class, the
member's access must be checked, because it could be different for
different template instances.

Proposed Resolution (October 2002):

Change the last sentence of 14.3 [temp.arg]
paragraph 3 from:

For a template-argument of class type, the template definition has no
special access rights to the inaccessible members of the template
argument type.

to:

For a template-argument that is a class type or a class template, the
template definition has no special access rights to the members
of the template-argument. [Example:

The question is: If C is derived from A as above, is it allowed to
access A::N before the classes opening '{'?

The main problem is that you need to access U's protected parts in C's
base-clause. This pattern is common when using policies, Andrei's Loki
library was bitten by it as he tried to make some parts of the policies
'protected' but some compilers rejected the code. They were right to
reject it, I think it's
11.4 [class.friend]/2 that applies here and prevents the code
above to be legal, although it addresses a different and reasonable
example. To me, it seems wrong to reject the code as it is perfectly
reasonable to write such stuff. The questions are:

Do you agree it's reasonable?

Is it a DR or is it a request for an extension?

Is DR 372 the right place to address it or shall it be a new DR?

Steve Adamczyk:
In other words, the point of the issue is over what range access derived
from base class specifiers is granted, and whether any part of that range
is the base specifier list itself, either the parts afterwards or the whole
base specifier list. (Clark Nelson confirms this is what he was
asking with the original question.)
Personally, I find it somewhat disturbing that access might
arrive incrementally; I'd prefer that the access happen all
at once, at the opening brace of the class.

Notes from October 2003 meeting:

We decided it makes sense to delay the access checking for the
base class specifiers until the opening brace of the class is
seen. In other words, the base specifiers will be checked using
the full access available for the class, and the order of the
base classes is not significant in that determination. The
implementors present all said they already had code to handle
accumulation of delayed access checks, because it is already
needed in other contexts.

Proposed resolution (October, 2004):

Change the last sentence of 14.3 [temp.arg]
paragraph 3 as indicated:

For a template-argumentofthat is a class
type or a class template, the template definition
has no special access rights to the inaccessible members of the
template argument typetemplate-argument.
[Example:

The 10/2004 resolution is not sufficient to implement the CWG's
intent to allow these examples: clause 11 [class.access]
paragraph 1 grants protected access only to “members and
friends” of derived classes, not to their
base-specifiers. The resolution needs to be extended to say
either that access in base-specifiers is determined as if they
were members of the class being defined or that access is granted to
the class as an entity, including its base-specifiers. See
also issue 500, which touches on the same
issue and should be resolved in the same way.

Proposed resolution (October, 2005):

Change the second bullet of 11 [class.access] paragraph
1 as indicated:

protected; that is, its name can be used only by
members and friends of the class in which it is declared, and by
members and friends of classes derived from this classby
classes derived from that class, and by their friends (see
11.5 [class.protected]).

Change 11 [class.access] paragraph 2 as indicated:

A member of a class can also access all the names declared in the
class of which it is a memberto which the class has access.

Change 11 [class.access] paragraph 6 as indicated:

All access controls in clause 11 [class.access] affect the
ability to access a class member name from a particular scope. The
access control for names used in the definition of a class member that
appears outside of the member's class definition is done as if the
entire member definition appeared in the scope of the member's
class.For purposes of access control, the base-specifiers
of a class and the definitions of class members that appear outside of
the class definition are considered to be within the scope of that
class. In particular...

Change the example and commentary in 11 [class.access]
paragraphs 6-7 as indicated:

Here, all the uses of A::I are well-formed
because A::f and A::x are members of
class A and g is a friend of class A. This
implies, for example, that access checking on the first use
of A::I must be deferred until it is determined that this use
of A::I is as the return type of a member of
class A. Similarly, the use of A::B as a
base-specifier is well-formed because D is derived
from A, so access checking of base-specifiers must be
deferred until the entire base-specifier-list has been seen.
—end example]

In 11.4 [class.friend] paragraph 2, replace the following
text:

Declaring a class to be a friend implies that the names of private
and protected members from the class granting friendship can be
accessed in declarations of members of the befriended
class. [Note: this means that access to private and protected
names is also granted to member functions of the friend class (as if
the functions were each friends) and to the static data member
definitions of the friend class. This also means that private and
protected type names from the class granting friendship can be used in
the base-clause of a nested class of the friend class. However,
the declarations of members of classes nested within the friend class
cannot access the names of private and protected members from the
class granting friendship. Also, because the base-clause of the
friend class is not part of its member declarations,
the base-clause of the friend class cannot access the names of
the private and protected members from the class granting
friendship. For example,

Declaring a class to be a friend implies that the names of private and
protected members from the class granting friendship can be accessed
in the base-specifiers and member declarations of the befriended
class. [Example:

For a template-argumentofthat is a class type
or a class template, the template definition has no special
access rights to the inaccessible members of the template
argument type.template-argument. [Example:

Like a member function, a friend function (11.4 [class.friend])
defined within a nested class is in the lexical scope of that class;
it obeys the same rules for name binding as a static member function
of that class (9.4 [class.static]), but itand
has no special access rights to members of an enclosing class.

354.
Null as nontype template argument

The standard does not permit a null value to be used as a nontype template
argument for a nontype template parameter that is a pointer.

This code is accepted by EDG, Microsoft, Borland and Cfront, but rejected
by g++ and Sun:

template <int *p> struct A {};
A<(int*)0> ai;

I'm not sure this was ever explicitly considered by the committee.
Is there any reason to permit this kind of usage?

Jason Merrill:
I suppose it might be useful for a program to be able to express a
degenerate case using a null template argument. I think allowing it would
be harmless.

Notes from October 2004 meeting:

CWG decided that it would be desirable to allow null pointers
as nontype template arguments, even though they are not
representable in some current ABIs. There was some discussion
over whether to allow a bare 0 to be used with a pointer
nontype template parameter. The following case was decisive:

The current wording of 14.3 [temp.arg] paragraph 7
disambiguates the function call in favor of the int
version. If the null pointer conversion were allowed for pointer
nontype template parameters, this case would become ambiguous, so
it was decided to require a cast.

Proposed resolution (April, 2005):

In 14.3.2 [temp.arg.nontype] paragraph 1, insert the
following after the third bullet:

a constant expression that evaluates to a null pointer
value (4.10 [conv.ptr]); or

a constant expression that evaluates to a null member
pointer value (4.11 [conv.mem]); or

Add the indicated text to the note in the second bullet of
14.3.2 [temp.arg.nontype] paragraph 5:

[Note: In particular, neither the null pointer conversion
(4.10 [conv.ptr]) nor the derived-to-base conversion
(4.10 [conv.ptr]) are applied. Although 0 is a valid
template-argument for a non-type template-parameter of integral
type, it is not a valid template-argument for a non-type
template-parameter of pointer type. However, (int*)0 is a valid
template-argument for a non-type template-parameter of type
“pointer to int.” —end note]

Replace the normative wording of 14.4 [temp.type] paragraph 1 with the following:

Two template-ids refer to the same class or function
if

their template-names refer to the same template, and

their corresponding type template-arguments are the
same type, and

their corresponding non-type template-arguments of
integral or enumeration type have identical values, and

their corresponding non-type template-arguments of
pointer type refer to the same external object or function or are
both the null pointer value, and

their corresponding non-type template-arguments of
pointer-to-member type refer to the same class member or are both
the null member pointer value, and

their corresponding non-type template-argumentss for
template parameters of reference type refer to the same external
object or function, and

their corresponding template template-arguments refer
to the same template.

The change to 14.4 [temp.type] paragraph 1 shown in
document J16/07-0118 = WG21 N2258, in which the syntactic
non-terminal template-argument is changed to the English
term “template argument” is sufficient to remove the
confusion about whether the value before or after conversion is
used in matching template-ids.

679.
Equivalence of template-ids and operator function templates

In order for two template-ids to refer to the same function,
14.4 [temp.type] paragraph 1, bullet 1 requires that

their template-names refer to the same
template

This makes it impossible for two template-ids referring
to operator function templates to be equivalent, because only
simple-template-ids have a template-name, and a
template-id referring to an operator function template is
not a simple-template-id (14.2 [temp.names]
paragraph 1).

Suggested resolution:

Change 14.4 [temp.type] paragraph 1, bullet 1 to read,

their template-names or
operator-function-ids refer to the same template

Proposed resolution (June, 2008):

Change 14.4 [temp.type] paragraph 1, first bullet, as
follows:

their template-names or
operator-function-ids refer to the same template,
and

582.
Template conversion functions

The wholesale replacement of the phrase “template
function” by the resolution of issue 105 seems to have overlooked the similar phrase “template
conversion function.” This phrase appears a number of times in
13.3.3.1.2 [over.ics.user] paragraph 3, 14.5.2 [temp.mem] paragraphs 5-8, and 14.8.2 [temp.deduct]
paragraph 1. It should be systematically replaced in similar
fashion to the resolution of issue 105.

Proposed resolution (October, 2006):

Change 13.3.3.1.2 [over.ics.user] paragraph 3 as
follows:

If the user-defined conversion is specified by a template
conversion functionspecialization of a conversion function
template, the second standard conversion sequence must have exact
match rank.

Change 14.5.2 [temp.mem] paragraph 5 as follows:

A specialization of a template conversion
functionconversion function template is referenced in the
same way as a non-template conversion function that converts to the
same type.

Change 14.5.2 [temp.mem] paragraph 6 as follows:

A specialization of a template conversion
functionconversion function template is not found by name
lookup. Instead, any template conversion
functionsconversion function templates visible in the
context of the use are considered.

Change 14.5.2 [temp.mem] paragraph 7 as follows:

A using-declarationusing-declaration in a
derived class cannot refer to a specialization of a template
conversion functionconversion function template in a base
class.

Template argument deduction is done by comparing the return type of
the template conversion functionconversion function
template (call it P) with the type that is required as
the result of the conversion (call it A) as described in
14.8.2.5 [temp.deduct.type].

329.
Evaluation of friends of templates

When a function is defined in a friend function declaration in a class
template, the function is defined at each instantiation of the class
template. The function is defined even if it is never used. The same
restrictions on multiple declarations and definitions which apply to
non-template function declarations and definitions also apply to these
implicit definitions. [Note: if the function definition is ill-formed
for a given specialization of the enclosing class template, the program
is ill-formed even if the function is never used. ]

This means that the following program is invalid, even without the call
of f(ai):

The EDG front end issues an error on this case even if f(ai)
is never
called. Of the compilers I tried (g++, Sun, Microsoft, Borland) we
are the only ones to issue such an error.

This issue came up because there is a library that either deliberately or
accidentally makes use of friend functions that are not valid for certain
instantiations.

The wording in the standard is the result of a deliberate decision made
long ago, but given the fact that most implementations do otherwise it
raises the issue of whether we did the right thing.

Upon further investigation, the current rule was adopted as the resolution
to issue 6.47 in my series of template issue papers. At the time the
issue was discussed (7/96) most compilers did evaluate such friends.
So it seems that a number of compilers have changed their behavior
since then.

Based on current practice, I think the standard should be changed to
evaluate such friends only when used.

Proposed resolution (October 2002):

Change section 14.5.4 [temp.friend]
paragraph 5 from:

When a function is defined
in a friend function declaration in a class template,
the function is defined at each instantiation of the class template.
The function is defined even if it is never used.
The same restrictions on multiple declarations and definitions
which apply to non-template function declarations and definitions
also apply to these implicit definitions.
[Note:
if the function definition is ill-formed for a given specialization of the
enclosing class template, the program is ill-formed even if the function
is never used.
]

to:

When a function is defined
in a friend function declaration in a class template,
the function is instantiated when the function is used.
The same restrictions on multiple declarations and definitions
that apply to non-template function declarations and definitions
also apply to these implicit definitions.

410.
Paragraph missed in changes for issue 166

14.5.4 [temp.friend] paragraph 2 was overlooked when the
changes for issue 166 were made.

The friend declaration of f<>(int) is now valid.

A friend function declaration that is not a template declaration and
in which the name of the friend is an unqualified template-id shall
refer to a specialization of a function template declared in the
nearest enclosing namespace scope. [Example:

A friend function declaration that is not a template declaration and
in which the name of the friend is an unqualified template-id shall
refer to a specialization of a function template declared in the
nearest enclosing namespace scope. [Example:

517.
Partial specialization following explicit instantiation

If a template is partially specialized then that partial
specialization shall be declared before the first use of that partial
specialization that would cause an implicit instantiation to take
place, in every translation unit in which such a use occurs; no
diagnostic is required.

This leaves the impression that an explicit instantiation of the
primary template may precede the declaration of an applicable partial
specialization. Is the following example well-formed?

If a template is partially specialized then that partial
specialization shall be declared before the first use of that partial
specialization that would cause an implicit instantiation to take
place, in every translation unit in which such a use occurs; no
diagnostic is required.

with:

A partial specialization shall be declared before the first use of a
class template specialization that would make use of the partial
specialization as the result of an implicit or explicit instantiation
in every translation unit in which such a use occurs; no diagnostic is
required.

214.
Partial ordering of function templates is underspecified

In 14.5.6.2 [temp.func.order], partial ordering is explained in
terms of template argument deduction. However, the exact procedure for
doing so is not specified. A number of details are missing, they are
explained as sub-issues below.

14.5.6.2 [temp.func.order] paragraph 2 refers to
14.8.2 [temp.deduct] for argument deduction. This is the
wrong reference; it explains how explicit arguments are processed
(paragraph 2) and how function parameter types are adjusted (paragraph
3). Neither of these steps is meaningful in the context of partial
ordering. Next in deduction follows one of the steps in 14.8.2.1 [temp.deduct.call], 14.8.2.2 [temp.deduct.funcaddr], 14.8.2.3 [temp.deduct.conv], or 14.8.2.5 [temp.deduct.type]. The standard
does not specify which of these contexts apply to partial
ordering.

Because 14.8.2.1 [temp.deduct.call] and 14.8.2.3 [temp.deduct.conv] both start with actual function parameters, it is
meaningful to assume that partial ordering uses 14.8.2.5 [temp.deduct.type], which only requires types. With that assumption,
the example in 14.5.6.2 [temp.func.order] paragraph 5 becomes
incorrect, considering the two templates

Here, #2 is at least as specialized as #1: With a synthetic type
U, #2 becomes g(U&); argument deduction against
#1 succeeds with T=U&. However, #1 is not at least as
specialized as #2: Deducing g(U) against g(T&)
fails. Therefore, the second template is more specialized than the
first, and the call g(x) is not ambiguous.

According to John Spicer, the intent of the partial ordering was
that it uses deduction as in a function call (14.8.2.1 [temp.deduct.call]), which is indicated by the mentioning of "exact
match" in 14.5.6.2 [temp.func.order] paragraph 4. If that is
indeed the intent, it should be specified how values are obtained for
the step in 14.8.2.1 [temp.deduct.call] paragraph 1, where the
types of the arguments are determined. Also, since 14.8.2.1 [temp.deduct.call] paragraph 2 drops references from the parameter
type, symmetrically, references should be dropped from the argument
type (which is done in 5 [expr] paragraph 2, for a true
function call).

14.5.6.2 [temp.func.order] paragraph 4 requires an "exact
match" for the "deduced parameter types". It is not clear whether this
refers to the template parameters, or the parameters of the template
function. Considering the example

Here, #3 is clearly at least as specialized as #1. To determine
whether #1 is at least as specialized as #3, a unique type U
is synthesized, and deduction of g<U>(U) is performed
against #3. Following the rules in 14.8.2.1 [temp.deduct.call],
deduction succeeds with T=U. Since the template argument is
U, and the deduced template parameter is also U, we
have an exact match between the template parameters. Even though the
conversion from U to U const & is an exact
match, it is not clear whether the added qualification should be taken
into account, as it is in other places.

Issue 200 covers a related issue,
illustrated by the following example:

A template is more specialized than another if, and
only if, it is at least as specialized as the other
template and that template is not at least as
specialized as the first.

To paraphrase, given two templates A & B, if A's template
parameters can be deduced by B, but B's cannot be deduced by
A, then A is more specialized than B. Deduction is done as
if for a function call. In particular, except for conversion
operators, the return type is not involved in deduction.
This leads to the following templates and use being
unordered. (This example is culled from G++ bug report 4672
http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view&pr=4672)

It looks like #2 is more specialized that #1, but
14.5.6.2 [temp.func.order] does not make it so, as neither template can
deduce 'T' from the other template's function parameters.

Possible Resolutions:

There are several possible solutions, however through
experimentation I have discounted two of them.

Option 1:

When deducing function ordering, if the return type of one of
the templates uses a template parameter, then return types
should be used for deduction. This, unfortunately, makes
existing well formed programs ill formed. For example

Here, neither #1 nor #2 can deduce the other, as the return
types fail to match. Considering only the function parameters
gives #2 more specialized than #1, and hence makes the call
#3 well formed.

Option 2:

As option 1, but only consider the return type when deducing
the template whose return type involves template parameters.
This has the same flaw as option 1, and that example is
similarly ill formed, as #1's return type 'X<T,0>' fails to
match 'int' so #1 cannot deduce #2. In the converse direction,
return types are not considered, but the function parameters
fail to deduce.

Option 3:

It is observed that the original example is only callable
with a template-id-expr to supply a value for the first,
undeducible, parameter. If that parameter were deducible it
would also appear within at least one of the function
parameters. We can alter paragraph 4 of [temp.func.order]
to indicate that it is not necessary to deduce the parameters
which are provided explicitly, when the call has the form
of a template-id-expr. This is a safe extension as it only
serves to make ill formed programs well formed. It is also
in line with the concept that deduction for function
specialization order should proceed in a similar manner to
function calling, in that explicitly provided parameter
values are taken into consideration.

Suggested resolution:

Insert after the first sentence of paragraph 4 in
14.5.6.2 [temp.func.order]

Should any template parameters remain undeduced, and
the function call be of the form of a template-id-expr,
those template parameters provided in the
template-id-expr may be arbitrarily synthesized prior
to determining whether the deduced arguments generate
a valid function type.

(April 2002) John Spicer and John Wiegley have written a
paper on this. See 02-0051/N1393.

Proposed resolution (October 2002):

Change 14.5.6.2 [temp.func.order] paragraph 2 to read:

Partial ordering selects which of two function templates is more
specialized than the other by transforming each template in turn
(see next paragraph) and performing template argument deduction
using the function parameter types, or in the case of a conversion
function the return type. The deduction process determines whether
one of the templates is more specialized than the other. If so, the
more specialized template is the one chosen by the partial ordering
process.

Change 14.5.6.2 [temp.func.order] paragraph 3 to read:

To produce the transformed template, for each type, non-type, or template
template parameter synthesize a unique type, value, or class template
respectively and substitute it for each occurrence of that parameter
in the function type of the template.

Using the transformed function template's function parameter list, or
in the case of a conversion function its transformed return type,
perform type deduction against the function parameter list (or return
type) of the other function. The mechanism for performing these
deductions is given in 14.8.2.x.

Remove the text of 14.5.6.2 [temp.func.order] paragraph 5 but
retain the example. The removed text is:

A template is more specialized than another if, and only if, it is
at least as specialized as the other template and that template is not
at least as specialized as the first.

Insert the following section before 14.8.2.5
(Note that this would either be a new 14.8.2.4, or would be given
a number like 14.8.2.3a. If neither of these is possible from
a troff point of view, this could be made 14.8.2.5.
)

Template argument deduction is done by comparing certain types associated with
the two function templates being compared.

Two sets of types are used to determine the partial ordering. For each of
the templates involved there is the original function type and the
transformed function type. [Note:
The creation of the transformed type is
described in 14.5.6.2 [temp.func.order].]
The deduction process uses the
transformed type as the argument template and the original type of the
other template as the parameter template. This process is done twice
for each type involved in the partial ordering comparison: once using
the transformed template-1 as the argument template and template-2 as
the parameter template and again using the transformed template-2 as
the argument template and template-1 as the parameter template.

The types used to determine the ordering depend on the context in which
the partial ordering is

In the context of a function call, the function parameter types
are used.

In the context of a call to a conversion operator, the return types of
the conversion function templates are used.

In other contexts (14.5.6.2 [temp.func.order]),
the function template's function type is used.

Each type from the parameter template and the corresponding type from the
argument template are used as the types of P and A.

Before the partial ordering is done, certain transformations are performed
on the types used for partial ordering:

If P is a reference type, P is replaced by the type
referred to.

If A is a reference type, A is replaced by the type
referred to.

If both P and A were reference types (before being replaced
with the type referred to above), determine which
of the two types (if any) is more cv-qualified than the other; otherwise
the types are considered to be equally cv-qualified for partial ordering
purposes. The result of this determination will be used below.

Remove any top-level cv-qualifiers:

If P is a cv-qualified type, P is replaced by the
cv-unqualified version of P.

If A is a cv-qualified type, A is replaced by the
cv-unqualified version of A.

Using the resulting types P and A the deduction is then
done as described in (14.8.2.5 [temp.deduct.type]).
If deduction succeeds for a given type,
the type from the argument template is considered to be at least as specialized
as the type from the parameter template.

If, for a given type, deduction succeeds in both directions (i.e., the
types are identical after the transformations above) if the type from
the argument template is more cv-qualified than the type from the
parameter template (as described above) that type is considered to be
more specialized than the other. If neither type is more cv-qualified
than the other then neither type is more specialized than the other.

If for each type being considered a given template is at least as specialized
for all types and more specialized for some set of types and the
other template is not more specialized for any types or is not
at least as specialized for any types, then
the given template is more specialized than the other template.
Otherwise, neither template
is more specialized than the other.

In most cases, all template parameters must have values in order for
deduction to succeed, but for partial ordering purposes a template
parameter may remain without a value provided it is not used in the
types being used for partial ordering. [Note:
A template parameter used
in a non-deduced context is considered used.]

180.
typename and elaborated types

Mike Miller:
A question about typename came up in the discussion of
issue 68 that is somewhat relevant
to the idea of omitting
typename in contexts where it is clear that a type is
required: consider something like

template <class T>
class X {
friend class T::nested;
};

Is typename required here? If so, where would it go? (The
grammar doesn't seem to allow it anywhere in an
elaborated-type-specifier that has a class-key.)

Bill Gibbons:
The class applies to the last identifier in the qualified name,
since all the previous names must be classes or namespaces. Since the
name is specified to be a class it does not need typename.
[However,] it looks like
14.6 [temp.res]
paragraph 3 requires
typename and the following paragraphs
do not exempt this case. This is not what we agreed on.

Proposed resolution (04/01):

In 14.6 [temp.res] paragraph 5, change

The keyword typename is not permitted in a
base-specifier or in a mem-initializer; in these
contexts a qualified-name that depends on a
template-parameter (14.6.2 [temp.dep]) is
implicitly assumed to be a type name.

to

A qualified name used as the name in a mem-initializer-id,
a base-specifier, or an elaborated-type-specifier
(in the class-key and enum forms) is implicitly
assumed to name a type, without the use of the typename
keyword. [Note: the typename keyword is not
permitted by the syntax of these constructs.]

(The expected resolution for issue 254 will remove the typename forms from the
grammar for elaborated-type-specifier. If that
resolution is adopted, the parenthetical phrase "(in the
class-key and enum forms)" in the preceding
wording should be removed because those will be the only forms
of elaborated-type-specifier.)

This has been consolidated with the edits for some other
issues. See N1376=02-0034.

382.
Allow typename outside of templates

P. J. Plauger, among others, has noted that typename is hard
to use, because in a given context it's either required or forbidden,
and it's often hard to tell which.
It would make life easier for programmers if typename
could be allowed in places where it is not required, e.g., outside
of templates.

Notes from the April 2003 meeting:

There was unanimity on relaxing this requirement on typename.
The question was how much to relax it. Everyone agreed on allowing
it on all qualified names, which is an easy fix (no syntax change
required). But should it be allowed other places? P.J. Plauger
said he'd like to see it allowed anywhere a type name is allowed,
and that it could actually be a decades-late assist for the infamous
"the ice is thin here" typedef problem noted in K&R I.

Proposed resolution (April 2003):

Replace the text at the start of 14.6 [temp.res] paragraph 3:

A qualified-id that refers to a type and in which
the nested-name-specifier
depends on a template-parameter (14.6.2 [temp.dep])
shall be prefixed by the keyword
typename to indicate that
the qualified-id denotes a type, forming an
elaborated-type-specifier (7.1.6.3 [dcl.type.elab]).

With:

The keyword typename can only be applied to a qualified-id. A
qualified-id that refers to a type and in which
the nested-name-specifier
depends on a template-parameter (14.6.2 [temp.dep])
shall be prefixed by the keyword
typename to indicate that the qualified-id
denotes a type, forming
an elaborated-type-specifier (7.1.6.3 [dcl.type.elab]).
If a qualified-id which
has been prefixed by the keyword typename does not
denote a type the program is ill-formed.
[ Note: The keyword is only required on a qualified-id within a
template declaration or definition in which the
nested-name-specifier depends on a template-parameter. ]

Remove 14.6 [temp.res] paragraph 5:

The keyword typename shall only be used in template
declarations and definitions, including in the return type of a function template or
member function template, in the return type for the definition of a member function
of a class template or of a class nested within a class template, and in the
type-specifier for the definition of a static member of a class template or
of a class nested within a class template. The keyword typename shall be
applied only to qualified names, but those names need not be dependent. The keyword
typename shall be used only in contexts in which dependent names
can be used. This includes template declarations and definitions but excludes explicit
specialization declarations and explicit instantiation declarations. The keyword
typename
is not permitted in a base-specifier or in a mem-initializer; in these
contexts a qualified-id that depends on a template-parameter (temp.dep) is
implicitly assumed to be a type name.

Note: the claim here that a qualified name preceded by
typename forms an elaborated type specifier conflicts with
the changes made in issue 254 (see
N1376=02-0034), which introduces typename-specifier.

Notes from October 2003 meeting:

We considered whether typename should be allowed in more
places, and decided we only wanted to allow it in qualified
names (for now at least).

AWhen aqualified-idthat refers to a
type and in which the nested-name-specifier depends on a
template-parameter (14.6.2 [temp.dep]) is
intended to refer to a type, it shall be prefixed by the
keyword typenameto indicate that the qualified-id
denotes a type, forming a typename-specifier. If
the qualified-id in a typename-specifier does not
denote a type, the program is ill-formed.

Change 14.6 [temp.res] paragraph 5 as
follows:

The keyword typename shall only be used in template
declarations and definitions, including in the return type of a
function template or member function template, in the return type
for the definition of a member function of a class template or of
a class nested within a class template, and in the
type-specifier for the definition of a static member of a
class template or of a class nested within a class template. The
keyword typename shall be applied only to qualified
names, but those names need not be dependent. The keyword
typename shall be used only in contexts in which
dependent names can be used. This includes template declarations
and definitions but excludes explicit specialization declarations
and explicit instantiation declarations. A qualified name
used as the name in a mem-initializer-id, a
base-specifier, or an elaborated-type-specifier is
implicitly assumed to name a type, without the use of the
typename keyword. [Note: the typename
keyword is not permitted by the syntax of these
constructs. —end note]

409.
Obsolete paragraph missed by changes for issue 224

Paragraph 6 of 14.6 [temp.res] is obsolete as result of
issue 224, and needs to be revised.

Within the definition of a class template or within the definition of
a member of a class template, the keyword typename is not required
when referring to the unqualified name of a previously declared member
of the class template that declares a type. The keyword typename
shall always be specified when the member is referred to using a qual-
ified name, even if the qualifier is simply the class template name.
[Example:

Within the definition of a class template or within the definition of
a member of a class template, the keyword typename is not
required when referring to the unqualified name of a previously
declared member of the class template that declares a type.
The keyword typename shall always be specified when the
member is referred to using a qualified name, even if the qualifier is
simply the class template name. [Example:

559.
Editing error in issue 382 resolution

Part of the resolution for issue 224 was
the addition of the phrase “but does not refer to a member of
the current instantiation” to 14.6 [temp.res]
paragraph 3. When the resolution of issue 382
was added to the current working draft, however, that phrase was
inadvertently removed. Equivalent phrasing should be restored.

Proposed resolution (April, 2006):

Replace the first sentence of 14.6 [temp.res] paragraph 3
with the following text:

When a qualified-id is intended to refer to a type that is not
a member of the current instantiation (14.6.2.1 [temp.dep.type]) and its nested-name-specifier depends on a
template-parameter (14.6.2 [temp.dep]), it shall be
prefixed by the keyword typename, forming
a typename-specifier.

666.
Dependent qualified-ids without the typename keyword

A name used in a template declaration or definition and that is
dependent on a template-parameter is assumed not to name a type unless
the applicable name lookup finds a type name or the name is qualified
by the keyword typename.

If a specialization of a template is instantiated for a set of
template-arguments such that the qualified-id prefixed
by typename does not denote a type, the specialization is
ill-formed.

It is not clear whether this is intended to, or is sufficient to,
render a specialization ill-formed if a dependent qualified-id
that is not prefixed by typename actually does
denote a type. For example,

If, for a given set of template arguments, a specialization of a template
is instantiated that refers to a qualified-id that denotes a type,
and the nested-name-specifier of the qualified-id depends
on a template parameter, the qualified-id shall either be prefixed
by typename or shall be used in a context in which it implicitly
names a type as described above. [Example:

According to one
analysis, because the expression A::foo_ on line #1
is non-dependent, it must be analyzed in the definition
context. It that context, it violates the restrictions of
9.2 [class.mem] paragraph 10 on how the name of a
nonstatic data member of a class can be used and thus should be
treated as an error.

On the other hand, the description of the transformation of
an id-expression into a class member access expression
(9.3.1 [class.mfct.non-static] paragraph 3) does not have any special
treatment of templates; when C<int>::foo() is
instantiated, the reference to A::foo_ turns out to be to a
base class member and is thus transformed into
(*this).A::foo_ and is thus not an error.

Proposed resolution (October, 2005):

Change 9.3.1 [class.mfct.non-static] paragraph 3 as indicated:

When an id-expression (5.1.1 [expr.prim.general]) that is not
part of a class member access syntax (5.2.5 [expr.ref])
and not used to form a pointer to member (5.3.1 [expr.unary.op]) is used in the body of a non-static member function
of class X or used in the mem-initializer for a
constructor of class X, if name lookup (3.4.1 [basic.lookup.unqual]) resolves the name in the id-expression to a
non-static non-type member of class X or of a base class
of Xsome class C,
the id-expression is transformed into a class member access
expression (5.2.5 [expr.ref]) using (*this)
(9.3.2 [class.this]) as the
postfix-expression to the left of the .
operator. [Note: If C is not X or a base
class of X, the class member access expression is ill-formed.
—end note]The member name then refers to the
member of the object for which the function is called. Similarly
during name lookup...

524.
Can function-notation calls to operator functions be dependent?

The description of dependent function calls in
14.6.2 [temp.dep] paragraph 1 applies only to
identifiers in postfix-notation function calls and to operator
notation calls for operator functions:

In an expression of the form:

postfix-expression(expression-listopt)

where the postfix-expression is an identifier,
the identifier denotes a dependent name if and only if
any of the expressions in the expression-list is a
type-dependent expression (14.6.2.2 [temp.dep.expr]). If an
operand of an operator is a type-dependent expression, the operator
also denotes a dependent name.

It would appear from the related passage in
14.6.4.2 [temp.dep.candidate] paragraph 1 that the description of
postfix-notation function calls should apply to all
unqualified-ids that are not template-ids,
including operator-function-ids, not just to
identifiers:

For a function call that depends on a template parameter, if the
function name is an unqualified-id but not
a template-id, the candidate functions are found...

Proposed resolution (October, 2005):

Change 14.6.2 [temp.dep] paragraph 1 as
indicated:

...In an expression of the form:

postfix-expression ( expression-listopt)

where the postfix-expression is an identifierunqualified-id but not a template-id,
the identifierunqualified-id denotes
a dependent name if and only if any of the expressions in
the expression-list is a type-dependent expression
(14.6.2.2 [temp.dep.expr])...

Change 14.6.4.2 [temp.dep.candidate] paragraph 1 as
indicated:

For a function call that depends on a template parameter, if the
function name is an unqualified-id but not
a template-id, or if the function is called using operator
notation, the candidate functions are found using the
usual lookup rules (3.4.1 [basic.lookup.unqual], 3.4.2 [basic.lookup.argdep]) except that...

224.
Definition of dependent names

The definition of when a type is dependent, given in
14.6.2.1 [temp.dep.type], is essentially syntactic: if the
reference is a qualified-id and one of the class-names
in the nested-name-specifier is dependent, the type is
dependent. This approach leads to surprising results:

The decision on whether a name is dependent or non-dependent should
be based on lookup, not on the form of the name: if the name can be
looked up in the definition context and cannot be anything else as the
result of specialization, the name should be non-dependent.

See papers J16/00-0028 = WG21 N1251 and
J16/00-0056 = WG21 N1279.

Proposed resolution (10/00):

Replace section 14.6.2.1 [temp.dep.type] with the
following:

In the definition of a class template, a nested class of a class
template, a member of a class template, or a member of a nested class
of a class template, a name refers to the current
instantiation if it is

the injected-class-name (clause 9 [class]) of the
class template or nested class,

in the definition of a primary class template, the name of the
class template followed by the template argument list of the
primary template (as described below) enclosed in <>,

in the definition of a nested class of a class template,
the name of the nested class referenced as a member of the
current instantiation, or

in the definition of a partial specialization, the name of
the class template followed by the template argument list of
the partial specialization enclosed in <>.

The template argument list of a primary template is a
template argument list in which the nth template
argument has the value of the nth template
parameter of the class template.

A template argument that is equivalent to a template
parameter (i.e., has the same constant value or the same type
as the template parameter) can be used in place of that
template parameter in a reference to the current
instantiation. In the case of a nontype template argument,
the argument must have been given the value of the
template parameter and not an expression involving the
template parameter.

An unqualified name that, when looked up, refers to a member
of a class template. [Note: This can only occur when
looking up a name in a scope enclosed by the definition of a
class template.]

A qualified-id in which the nested-name-specifier
refers to the current instantiation.

[Example:

template <class T> class A {
static const int i = 5;
int n1[i]; // i refers to a member of the current instantiation
int n2[A::i]; // A::i refers to a member of the current instantiation
int n3[A<T>::i]; // A<T>::i refers to a member of the current instantiation
int f();
};
template <class T> int A<T>::f()
{
return i; // i refers to a member of the current instantiation
}

—end example]

A name is a member of an unknown specialization if the
name is a qualified-id in which the
nested-name-specifier names a dependent type that is not
the current instantiation.

A type is dependent if it is

a template parameter,

a member of an unknown specialization,

a nested class that is a member of the current
instantiation,

a cv-qualified type where the cv-unqualified type is dependent,

a compound type constructed from any dependent type,

an array type constructed from any dependent type or whose
size is specified by a constant expression that is value-dependent, or

a template-id in which either the template name is a
template parameter or any of the template arguments is a dependent
type or an expression that is type-dependent or value-dependent.

[Note: Because typedefs to not introduce new types, but
instead simply refer to other types, a name that refers to a
typedef that is a member of the current instantiation is dependent
only if the type referred to is dependent.]

In 14.6.2.2 [temp.dep.expr] paragraph 3, replace

a nested-name-specifier that contains a
class-name that names a dependent type.

with

a nested-name-specifier or qualified-id that
names a member of an unknown specialization.

In 14.6.2.2 [temp.dep.expr], add the following
paragraph:

A class member access expression (5.2.5 [expr.ref]) is
type-dependent if the type of the referenced member is dependent.
[Note: In an expression of the form x.y or
xp->y the type of the expression is usually the type
of the member y of the class of x (or the class
pointed to by xp). However, if x or xp
refers to a dependent type that is not the current instantiation,
the type of y is always dependent. If x or
xp refers to a non-dependent type or refers to the
current instantiation, the type of y is the type of the
class member access expression.]

In 14.6 [temp.res] paragraph 3, replace

A qualified-name that refers to a type and that depends
on a template-parameter (14.6.2 [temp.dep]) shall
be prefixed by the keyword typename.

with

A qualified-id that refers to a type and that depends on
a template-parameter (14.6.2 [temp.dep]) but
does not refer to a member of the current instantiation shall be
prefixed by the keyword typename.

Note: the wording for this paragraph was changed in TC1. The
words shown here are the pre-TC1 words.

In 14.2 [temp.names] paragraph 4, replace

When the name of a member template specialization appears after
. or -> in a postfix-expression, or
after a nested-name-specifier in a qualified-id,
and the postfix-expression or qualified-id explicitly
depends on a template-parameter (14.6.2 [temp.dep]),
the member template name must be prefixed by the keyword
template. Otherwise the name is assumed to name a
non-template.

with

When the name of a member template specialization appears after
. or -> in a postfix-expression, or
after a nested-name-specifier in a qualified-id,
and the postfix-expression or qualified-id explicitly
depends on a template-parameter (14.6.2 [temp.dep])
but does not refer to a member of the current instantiation
(14.6.2.1 [temp.dep.type]), the member template name must
be prefixed by the keyword template. Otherwise the name
is assumed to name a non-template.