File tree Expand file tree Collapse file tree 2 files changed +53
-0
lines changed Expand file tree Collapse file tree 2 files changed +53
-0
lines changed Original file line number Diff line number Diff line change @@ -2009,6 +2009,31 @@ auto Parser::parse_this_expression(ExpressionAST*& yyast) -> bool {
20092009 auto ast = make_node<ThisExpressionAST>(pool_);
20102010 yyast = ast;
20112011 ast->thisLoc = thisLoc;
2012+ ast->valueCategory = ValueCategory::kPrValue ;
2013+
2014+ for (auto current = scope_; current; current = current->parent ()) {
2015+ if (auto classSymbol = symbol_cast<ClassSymbol>(current->owner ())) {
2016+ // maybe a this expression in a field initializer
2017+ ast->type = control_->getPointerType (classSymbol->type ());
2018+ break ;
2019+ }
2020+
2021+ if (auto functionSymbol = symbol_cast<FunctionSymbol>(current->owner ())) {
2022+ if (auto classSymbol =
2023+ symbol_cast<ClassSymbol>(functionSymbol->enclosingSymbol ())) {
2024+ auto functionType = type_cast<FunctionType>(functionSymbol->type ());
2025+ const auto cv = functionType->cvQualifiers ();
2026+ if (cv != CvQualifiers::kNone ) {
2027+ auto elementType = control_->getQualType (classSymbol->type (), cv);
2028+ ast->type = control_->getPointerType (elementType);
2029+ } else {
2030+ ast->type = control_->getPointerType (classSymbol->type ());
2031+ }
2032+ }
2033+
2034+ break ;
2035+ }
2036+ }
20122037
20132038 return true ;
20142039}
Original file line number Diff line number Diff line change 1+ // RUN: %cxx -verify -fcheck %s
2+
3+ struct X {
4+ void f () { static_assert (__is_same (decltype (this ), X*)); }
5+
6+ void f () const { static_assert (__is_same (decltype (this ), const X*)); }
7+
8+ void f () volatile { static_assert (__is_same (decltype (this ), volatile X*)); }
9+
10+ void f () const volatile {
11+ static_assert (__is_same (decltype (this ), const volatile X*));
12+ }
13+
14+ void g ();
15+ void g () const ;
16+ void g () volatile;
17+ void g () const volatile;
18+ };
19+
20+ void X::g () { static_assert (__is_same (decltype (this ), X*)); }
21+
22+ void X::g () const { static_assert (__is_same (decltype (this ), const X*)); }
23+
24+ void X::g () volatile { static_assert (__is_same (decltype (this ), volatile X*)); }
25+
26+ void X::g () const volatile {
27+ static_assert (__is_same (decltype (this ), const volatile X*));
28+ }
You can’t perform that action at this time.
0 commit comments