[expr.prim.this]

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

## 7.5 Primary expressions [[expr.prim]](expr.prim#this)

### 7.5.3 This [expr.prim.this]

[1](#1)

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

The keyword this names a pointer to the object for which an implicit object member
function ([[class.mfct.non.static]](class.mfct.non.static "11.4.3 Non-static member functions")) is invoked or a non-static data member's
initializer ([[class.mem]](class.mem "11.4 Class members")) is evaluated[.](#1.sentence-1)

[2](#2)

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

The [*current class*](#def:class,current "7.5.3 This [expr.prim.this]") at a program point is
the class associated with the innermost class scope containing that point[.](#2.sentence-1)

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

A [*lambda-expression*](expr.prim.lambda.general#nt:lambda-expression "7.5.6.1 General [expr.prim.lambda.general]") does not introduce a class scope[.](#2.sentence-2)

â *end note*]

[3](#3)

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

If the expression this appears within the predicate of a contract assertion ([[basic.contract.general]](basic.contract.general "6.11.1 General"))
(including as the result of an implicit transformation ([[expr.prim.id.general]](expr.prim.id.general "7.5.5.1 General"))
and including in the bodies of nested [*lambda-expression*](expr.prim.lambda.general#nt:lambda-expression "7.5.6.1 General [expr.prim.lambda.general]")*s*)
and the current class
encloses the contract assertion,const is combined with the [*cv-qualifier-seq*](dcl.decl.general#nt:cv-qualifier-seq "9.3.1 General [dcl.decl.general]") used to generate the resulting type (see below)[.](#3.sentence-1)

[4](#4)

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

If a declaration declares a member function or member function template of a
class X, the expression this is a prvalue of type âpointer to[*cv-qualifier-seq*](dcl.decl.general#nt:cv-qualifier-seq "9.3.1 General [dcl.decl.general]") Xâ
wherever X is the current class
between the optional[*cv-qualifier-seq*](dcl.decl.general#nt:cv-qualifier-seq "9.3.1 General [dcl.decl.general]") and the end of the [*function-definition*](dcl.fct.def.general#nt:function-definition "9.6.1 General [dcl.fct.def.general]"),[*member-declarator*](class.mem.general#nt:member-declarator "11.4.1 General [class.mem.general]"), or [*declarator*](dcl.decl.general#nt:declarator "9.3.1 General [dcl.decl.general]")[.](#4.sentence-1)

It shall not appear within
the declaration of
a static or explicit object member function
of the current class (although its type and value category
are defined within such member functions as they are within an implicit object
member function)[.](#4.sentence-2)

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

This is because declaration matching does not
occur until the complete declarator is known[.](#4.sentence-3)

â *end note*]

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

In a [*trailing-return-type*](dcl.decl.general#nt:trailing-return-type "9.3.1 General [dcl.decl.general]"),
the class being defined is not required to be complete
for purposes of [class member access](expr.ref "7.6.1.5 Class member access [expr.ref]")[.](#4.sentence-4)

Class members declared later are not visible[.](#4.sentence-5)

[*Example [1](#example-1)*: struct A {char g(); template<class T> auto f(T t) -> decltype(t + g()){ return t + g(); }};template auto A::f(int t) -> decltype(t + g()); â *end example*]

â *end note*]

[5](#5)

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

Otherwise, if a [*member-declarator*](class.mem.general#nt:member-declarator "11.4.1 General [class.mem.general]") declares a non-static data
member ([[class.mem]](class.mem "11.4 Class members")) of a class X, the expression this is
a prvalue of type âpointer to Xâ
wherever X is the current class
within the
optional default member initializer ([[class.mem]](class.mem "11.4 Class members"))[.](#5.sentence-1)

[6](#6)

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

The expression this shall not appear in any other context[.](#6.sentence-1)

[*Example [2](#example-2)*: class Outer {int a[sizeof(*this)]; // error: not inside a member functionunsigned int sz = sizeof(*this); // OK, in default member initializervoid f() {int b[sizeof(*this)]; // OKstruct Inner {int c[sizeof(*this)]; // error: not inside a member function of Inner}; }}; â *end example*]
