[expr.prim.id.general]

# 7 Expressions [[expr]](./#expr)

## 7.5 Primary expressions [[expr.prim]](expr.prim#id.general)

### 7.5.5 Names [[expr.prim.id]](expr.prim.id#general)

#### 7.5.5.1 General [expr.prim.id.general]

[id-expression:](#nt:id-expression "7.5.5.1 General [expr.prim.id.general]")  
[*unqualified-id*](expr.prim.id.unqual#nt:unqualified-id "7.5.5.2 Unqualified names [expr.prim.id.unqual]")  
[*qualified-id*](expr.prim.id.qual#nt:qualified-id "7.5.5.3 Qualified names [expr.prim.id.qual]")  
[*pack-index-expression*](expr.prim.pack.index#nt:pack-index-expression "7.5.5.4 Pack indexing expression [expr.prim.pack.index]")

[1](#1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/expressions.tex#L1368)

An [*id-expression*](#nt:id-expression "7.5.5.1 General [expr.prim.id.general]") is a restricted form of a[*primary-expression*](expr.prim.grammar#nt:primary-expression "7.5.1 Grammar [expr.prim.grammar]")[.](#1.sentence-1)

[*Note [1](#note-1)*:

An [*id-expression*](#nt:id-expression "7.5.5.1 General [expr.prim.id.general]") can appear after[. and -> operators](expr.ref "7.6.1.5 Class member access [expr.ref]")[.](#1.sentence-2)

â *end note*]

[2](#2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/expressions.tex#L1378)

If an [*id-expression*](#nt:id-expression "7.5.5.1 General [expr.prim.id.general]") E denotes
a non-static non-type member of some class C at a point where
the current class ([[expr.prim.this]](expr.prim.this "7.5.3 This")) is X and

- [(2.1)](#2.1)

E is potentially evaluated orC is X or a base class of X, and

- [(2.2)](#2.2)

E is not the [*id-expression*](#nt:id-expression "7.5.5.1 General [expr.prim.id.general]") of
a class member access expression ([[expr.ref]](expr.ref "7.6.1.5 Class member access")), and

- [(2.3)](#2.3)

E is not the [*id-expression*](#nt:id-expression "7.5.5.1 General [expr.prim.id.general]") of
a [*reflect-expression*](expr.reflect#nt:reflect-expression "7.6.2.10 The reflection operator [expr.reflect]") ([[expr.reflect]](expr.reflect "7.6.2.10 The reflection operator")), and

- [(2.4)](#2.4)

if E is a [*qualified-id*](expr.prim.id.qual#nt:qualified-id "7.5.5.3 Qualified names [expr.prim.id.qual]"),E is not the un-parenthesized operand of
the unary & operator ([[expr.unary.op]](expr.unary.op "7.6.2.2 Unary operators")),

the [*id-expression*](#nt:id-expression "7.5.5.1 General [expr.prim.id.general]") is transformed into
a class member access expression using (*this) as the object expression[.](#2.sentence-1)

If this transformation occurs
in the predicate of a precondition assertion of a constructor of X or a postcondition assertion of a destructor of X,
the expression is ill-formed[.](#2.sentence-2)

[*Note [2](#note-2)*:

If C is not X or a base class of X,
the class member access expression is ill-formed[.](#2.sentence-3)

Also, if the [*id-expression*](#nt:id-expression "7.5.5.1 General [expr.prim.id.general]") occurs within
a static or explicit object member function,
the class member access is ill-formed[.](#2.sentence-4)

â *end note*]

This transformation does not apply in
the template definition context ([[temp.dep.type]](temp.dep.type "13.8.3.2 Dependent types"))[.](#2.sentence-5)

[*Example [1](#example-1)*: struct C {bool b;
 C() pre(b) // error pre(&this->b) // OK pre(sizeof(b) > 0); // OK, b is not potentially evaluated.}; â *end example*]

[3](#3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/expressions.tex#L1423)

If an [*id-expression*](#nt:id-expression "7.5.5.1 General [expr.prim.id.general]") E denotes
a member M of an anonymous union ([[class.union.anon]](class.union.anon "11.5.2 Anonymous unions")) U:

- [(3.1)](#3.1)

  If U is a non-static data member,E refers to M as a member of the lookup context of the terminal name of E (after any implicit transformation to
a class member access expression)[.](#3.1.sentence-1)
  [*Example [2](#example-2)*:
  o.x is interpreted as o.u.x,
where u names the anonymous union member[.](#3.1.sentence-2)
 â *end example*]

- [(3.2)](#3.2)

  Otherwise, E is interpreted as a class member access ([[expr.ref]](expr.ref "7.6.1.5 Class member access"))
that designates the member subobject M of
the anonymous union variable for U[.](#3.2.sentence-1)
  [*Note [3](#note-3)*:
  Under this interpretation, E no longer denotes a non-static data member[.](#3.2.sentence-2)
 â *end note*]
  [*Example [3](#example-3)*:
  N​::​x is interpreted as N​::​u.x,
where u names the anonymous union variable[.](#3.2.sentence-3)
 â *end example*]

[4](#4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/expressions.tex#L1449)

An [*id-expression*](#nt:id-expression "7.5.5.1 General [expr.prim.id.general]") or [*splice-expression*](expr.prim.splice#nt:splice-expression "7.5.9 Expression splicing [expr.prim.splice]") that designates a non-static data member or
implicit object member function of a class can only be used:

- [(4.1)](#4.1)

as part of a class member access
(after any implicit transformation (see above))
in which the
object expression
refers to the member's class
or a class derived from
that class, or

- [(4.2)](#4.2)

to form a pointer to member ([[expr.unary.op]](expr.unary.op "7.6.2.2 Unary operators")), or

- [(4.3)](#4.3)

if that [*id-expression*](#nt:id-expression "7.5.5.1 General [expr.prim.id.general]") or [*splice-expression*](expr.prim.splice#nt:splice-expression "7.5.9 Expression splicing [expr.prim.splice]") designates a non-static data member
and it appears in an unevaluated operand[.](#4.sentence-1)
  [*Example [4](#example-4)*: struct S {int m;};int i = sizeof(S::m); // OKint j = sizeof(S::m + 42); // OKint S::*k = &[:^^S::m:]; // OK â *end example*]

[5](#5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/expressions.tex#L1479)

For an [*id-expression*](#nt:id-expression "7.5.5.1 General [expr.prim.id.general]") that denotes an overload set,
overload resolution is performed
to select a unique function ([[over.match]](over.match "12.2 Overload resolution"), [[over.over]](over.over "12.3 Address of an overload set"))[.](#5.sentence-1)

[*Note [4](#note-4)*:

A program cannot refer to a function
with a trailing [*requires-clause*](temp.pre#nt:requires-clause "13.1 Preamble [temp.pre]") whose [*constraint-expression*](temp.constr.decl#nt:constraint-expression "13.5.3 Constrained declarations [temp.constr.decl]") is not satisfied,
because such functions are never selected by overload resolution[.](#5.sentence-2)

[*Example [5](#example-5)*: template<typename T> struct A {static void f(int) requires false;};

void g() { A<int>::f(0); // error: cannot call fvoid (*p1)(int) = A<int>::f; // error: cannot take the address of fdecltype(A<int>::f)* p2 = nullptr; // error: the type decltype(A<int>​::​f) is invalid}

In each case, the constraints of f are not satisfied[.](#5.sentence-3)

In the declaration of p2,
those constraints need to be satisfied
even thoughf is an [unevaluated operand](expr.context#def:unevaluated_operand "7.2.3 Context dependence [expr.context]")[.](#5.sentence-4)

â *end example*]

â *end note*]
