clang  9.0.0svn
SemaExprMember.cpp
Go to the documentation of this file.
1 //===--- SemaExprMember.cpp - Semantic Analysis for Expressions -----------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file implements semantic analysis member access expressions.
10 //
11 //===----------------------------------------------------------------------===//
12 #include "clang/Sema/Overload.h"
13 #include "clang/AST/ASTLambda.h"
14 #include "clang/AST/DeclCXX.h"
15 #include "clang/AST/DeclObjC.h"
16 #include "clang/AST/DeclTemplate.h"
17 #include "clang/AST/ExprCXX.h"
18 #include "clang/AST/ExprObjC.h"
19 #include "clang/Lex/Preprocessor.h"
20 #include "clang/Sema/Lookup.h"
21 #include "clang/Sema/Scope.h"
22 #include "clang/Sema/ScopeInfo.h"
24 
25 using namespace clang;
26 using namespace sema;
27 
28 typedef llvm::SmallPtrSet<const CXXRecordDecl*, 4> BaseSet;
29 
30 /// Determines if the given class is provably not derived from all of
31 /// the prospective base classes.
32 static bool isProvablyNotDerivedFrom(Sema &SemaRef, CXXRecordDecl *Record,
33  const BaseSet &Bases) {
34  auto BaseIsNotInSet = [&Bases](const CXXRecordDecl *Base) {
35  return !Bases.count(Base->getCanonicalDecl());
36  };
37  return BaseIsNotInSet(Record) && Record->forallBases(BaseIsNotInSet);
38 }
39 
40 enum IMAKind {
41  /// The reference is definitely not an instance member access.
43 
44  /// The reference may be an implicit instance member access.
46 
47  /// The reference may be to an instance member, but it might be invalid if
48  /// so, because the context is not an instance method.
50 
51  /// The reference may be to an instance member, but it is invalid if
52  /// so, because the context is from an unrelated class.
54 
55  /// The reference is definitely an implicit instance member access.
57 
58  /// The reference may be to an unresolved using declaration.
60 
61  /// The reference is a contextually-permitted abstract member reference.
63 
64  /// The reference may be to an unresolved using declaration and the
65  /// context is not an instance method.
67 
68  // The reference refers to a field which is not a member of the containing
69  // class, which is allowed because we're in C++11 mode and the context is
70  // unevaluated.
72 
73  /// All possible referrents are instance members and the current
74  /// context is not an instance method.
76 
77  /// All possible referrents are instance members of an unrelated
78  /// class.
80 };
81 
82 /// The given lookup names class member(s) and is not being used for
83 /// an address-of-member expression. Classify the type of access
84 /// according to whether it's possible that this reference names an
85 /// instance member. This is best-effort in dependent contexts; it is okay to
86 /// conservatively answer "yes", in which case some errors will simply
87 /// not be caught until template-instantiation.
89  const LookupResult &R) {
90  assert(!R.empty() && (*R.begin())->isCXXClassMember());
91 
93 
94  bool isStaticContext = SemaRef.CXXThisTypeOverride.isNull() &&
95  (!isa<CXXMethodDecl>(DC) || cast<CXXMethodDecl>(DC)->isStatic());
96 
97  if (R.isUnresolvableResult())
98  return isStaticContext ? IMA_Unresolved_StaticContext : IMA_Unresolved;
99 
100  // Collect all the declaring classes of instance members we find.
101  bool hasNonInstance = false;
102  bool isField = false;
103  BaseSet Classes;
104  for (NamedDecl *D : R) {
105  // Look through any using decls.
106  D = D->getUnderlyingDecl();
107 
108  if (D->isCXXInstanceMember()) {
109  isField |= isa<FieldDecl>(D) || isa<MSPropertyDecl>(D) ||
110  isa<IndirectFieldDecl>(D);
111 
112  CXXRecordDecl *R = cast<CXXRecordDecl>(D->getDeclContext());
113  Classes.insert(R->getCanonicalDecl());
114  } else
115  hasNonInstance = true;
116  }
117 
118  // If we didn't find any instance members, it can't be an implicit
119  // member reference.
120  if (Classes.empty())
121  return IMA_Static;
122 
123  // C++11 [expr.prim.general]p12:
124  // An id-expression that denotes a non-static data member or non-static
125  // member function of a class can only be used:
126  // (...)
127  // - if that id-expression denotes a non-static data member and it
128  // appears in an unevaluated operand.
129  //
130  // This rule is specific to C++11. However, we also permit this form
131  // in unevaluated inline assembly operands, like the operand to a SIZE.
132  IMAKind AbstractInstanceResult = IMA_Static; // happens to be 'false'
133  assert(!AbstractInstanceResult);
134  switch (SemaRef.ExprEvalContexts.back().Context) {
137  if (isField && SemaRef.getLangOpts().CPlusPlus11)
138  AbstractInstanceResult = IMA_Field_Uneval_Context;
139  break;
140 
142  AbstractInstanceResult = IMA_Abstract;
143  break;
144 
149  break;
150  }
151 
152  // If the current context is not an instance method, it can't be
153  // an implicit member reference.
154  if (isStaticContext) {
155  if (hasNonInstance)
157 
158  return AbstractInstanceResult ? AbstractInstanceResult
160  }
161 
162  CXXRecordDecl *contextClass;
163  if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC))
164  contextClass = MD->getParent()->getCanonicalDecl();
165  else
166  contextClass = cast<CXXRecordDecl>(DC);
167 
168  // [class.mfct.non-static]p3:
169  // ...is used in the body of a non-static member function of class X,
170  // if name lookup (3.4.1) resolves the name in the id-expression to a
171  // non-static non-type member of some class C [...]
172  // ...if C is not X or a base class of X, the class member access expression
173  // is ill-formed.
174  if (R.getNamingClass() &&
175  contextClass->getCanonicalDecl() !=
176  R.getNamingClass()->getCanonicalDecl()) {
177  // If the naming class is not the current context, this was a qualified
178  // member name lookup, and it's sufficient to check that we have the naming
179  // class as a base class.
180  Classes.clear();
181  Classes.insert(R.getNamingClass()->getCanonicalDecl());
182  }
183 
184  // If we can prove that the current context is unrelated to all the
185  // declaring classes, it can't be an implicit member reference (in
186  // which case it's an error if any of those members are selected).
187  if (isProvablyNotDerivedFrom(SemaRef, contextClass, Classes))
188  return hasNonInstance ? IMA_Mixed_Unrelated :
189  AbstractInstanceResult ? AbstractInstanceResult :
191 
192  return (hasNonInstance ? IMA_Mixed : IMA_Instance);
193 }
194 
195 /// Diagnose a reference to a field with no object available.
196 static void diagnoseInstanceReference(Sema &SemaRef,
197  const CXXScopeSpec &SS,
198  NamedDecl *Rep,
199  const DeclarationNameInfo &nameInfo) {
200  SourceLocation Loc = nameInfo.getLoc();
201  SourceRange Range(Loc);
202  if (SS.isSet()) Range.setBegin(SS.getRange().getBegin());
203 
204  // Look through using shadow decls and aliases.
205  Rep = Rep->getUnderlyingDecl();
206 
207  DeclContext *FunctionLevelDC = SemaRef.getFunctionLevelDeclContext();
208  CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(FunctionLevelDC);
209  CXXRecordDecl *ContextClass = Method ? Method->getParent() : nullptr;
210  CXXRecordDecl *RepClass = dyn_cast<CXXRecordDecl>(Rep->getDeclContext());
211 
212  bool InStaticMethod = Method && Method->isStatic();
213  bool IsField = isa<FieldDecl>(Rep) || isa<IndirectFieldDecl>(Rep);
214 
215  if (IsField && InStaticMethod)
216  // "invalid use of member 'x' in static member function"
217  SemaRef.Diag(Loc, diag::err_invalid_member_use_in_static_method)
218  << Range << nameInfo.getName();
219  else if (ContextClass && RepClass && SS.isEmpty() && !InStaticMethod &&
220  !RepClass->Equals(ContextClass) && RepClass->Encloses(ContextClass))
221  // Unqualified lookup in a non-static member function found a member of an
222  // enclosing class.
223  SemaRef.Diag(Loc, diag::err_nested_non_static_member_use)
224  << IsField << RepClass << nameInfo.getName() << ContextClass << Range;
225  else if (IsField)
226  SemaRef.Diag(Loc, diag::err_invalid_non_static_member_use)
227  << nameInfo.getName() << Range;
228  else
229  SemaRef.Diag(Loc, diag::err_member_call_without_object)
230  << Range;
231 }
232 
233 /// Builds an expression which might be an implicit member expression.
236  SourceLocation TemplateKWLoc,
237  LookupResult &R,
238  const TemplateArgumentListInfo *TemplateArgs,
239  const Scope *S) {
240  switch (ClassifyImplicitMemberAccess(*this, R)) {
241  case IMA_Instance:
242  return BuildImplicitMemberExpr(SS, TemplateKWLoc, R, TemplateArgs, true, S);
243 
244  case IMA_Mixed:
245  case IMA_Mixed_Unrelated:
246  case IMA_Unresolved:
247  return BuildImplicitMemberExpr(SS, TemplateKWLoc, R, TemplateArgs, false,
248  S);
249 
251  Diag(R.getNameLoc(), diag::warn_cxx98_compat_non_static_member_use)
252  << R.getLookupNameInfo().getName();
253  LLVM_FALLTHROUGH;
254  case IMA_Static:
255  case IMA_Abstract:
258  if (TemplateArgs || TemplateKWLoc.isValid())
259  return BuildTemplateIdExpr(SS, TemplateKWLoc, R, false, TemplateArgs);
260  return BuildDeclarationNameExpr(SS, R, false);
261 
263  case IMA_Error_Unrelated:
265  R.getLookupNameInfo());
266  return ExprError();
267  }
268 
269  llvm_unreachable("unexpected instance member access kind");
270 }
271 
272 /// Determine whether input char is from rgba component set.
273 static bool
274 IsRGBA(char c) {
275  switch (c) {
276  case 'r':
277  case 'g':
278  case 'b':
279  case 'a':
280  return true;
281  default:
282  return false;
283  }
284 }
285 
286 // OpenCL v1.1, s6.1.7
287 // The component swizzle length must be in accordance with the acceptable
288 // vector sizes.
289 static bool IsValidOpenCLComponentSwizzleLength(unsigned len)
290 {
291  return (len >= 1 && len <= 4) || len == 8 || len == 16;
292 }
293 
294 /// Check an ext-vector component access expression.
295 ///
296 /// VK should be set in advance to the value kind of the base
297 /// expression.
298 static QualType
300  SourceLocation OpLoc, const IdentifierInfo *CompName,
301  SourceLocation CompLoc) {
302  // FIXME: Share logic with ExtVectorElementExpr::containsDuplicateElements,
303  // see FIXME there.
304  //
305  // FIXME: This logic can be greatly simplified by splitting it along
306  // halving/not halving and reworking the component checking.
307  const ExtVectorType *vecType = baseType->getAs<ExtVectorType>();
308 
309  // The vector accessor can't exceed the number of elements.
310  const char *compStr = CompName->getNameStart();
311 
312  // This flag determines whether or not the component is one of the four
313  // special names that indicate a subset of exactly half the elements are
314  // to be selected.
315  bool HalvingSwizzle = false;
316 
317  // This flag determines whether or not CompName has an 's' char prefix,
318  // indicating that it is a string of hex values to be used as vector indices.
319  bool HexSwizzle = (*compStr == 's' || *compStr == 'S') && compStr[1];
320 
321  bool HasRepeated = false;
322  bool HasIndex[16] = {};
323 
324  int Idx;
325 
326  // Check that we've found one of the special components, or that the component
327  // names must come from the same set.
328  if (!strcmp(compStr, "hi") || !strcmp(compStr, "lo") ||
329  !strcmp(compStr, "even") || !strcmp(compStr, "odd")) {
330  HalvingSwizzle = true;
331  } else if (!HexSwizzle &&
332  (Idx = vecType->getPointAccessorIdx(*compStr)) != -1) {
333  bool HasRGBA = IsRGBA(*compStr);
334  do {
335  // Ensure that xyzw and rgba components don't intermingle.
336  if (HasRGBA != IsRGBA(*compStr))
337  break;
338  if (HasIndex[Idx]) HasRepeated = true;
339  HasIndex[Idx] = true;
340  compStr++;
341  } while (*compStr && (Idx = vecType->getPointAccessorIdx(*compStr)) != -1);
342 
343  // Emit a warning if an rgba selector is used earlier than OpenCL 2.2
344  if (HasRGBA || (*compStr && IsRGBA(*compStr))) {
345  if (S.getLangOpts().OpenCL && S.getLangOpts().OpenCLVersion < 220) {
346  const char *DiagBegin = HasRGBA ? CompName->getNameStart() : compStr;
347  S.Diag(OpLoc, diag::ext_opencl_ext_vector_type_rgba_selector)
348  << StringRef(DiagBegin, 1)
349  << S.getLangOpts().OpenCLVersion << SourceRange(CompLoc);
350  }
351  }
352  } else {
353  if (HexSwizzle) compStr++;
354  while ((Idx = vecType->getNumericAccessorIdx(*compStr)) != -1) {
355  if (HasIndex[Idx]) HasRepeated = true;
356  HasIndex[Idx] = true;
357  compStr++;
358  }
359  }
360 
361  if (!HalvingSwizzle && *compStr) {
362  // We didn't get to the end of the string. This means the component names
363  // didn't come from the same set *or* we encountered an illegal name.
364  S.Diag(OpLoc, diag::err_ext_vector_component_name_illegal)
365  << StringRef(compStr, 1) << SourceRange(CompLoc);
366  return QualType();
367  }
368 
369  // Ensure no component accessor exceeds the width of the vector type it
370  // operates on.
371  if (!HalvingSwizzle) {
372  compStr = CompName->getNameStart();
373 
374  if (HexSwizzle)
375  compStr++;
376 
377  while (*compStr) {
378  if (!vecType->isAccessorWithinNumElements(*compStr++, HexSwizzle)) {
379  S.Diag(OpLoc, diag::err_ext_vector_component_exceeds_length)
380  << baseType << SourceRange(CompLoc);
381  return QualType();
382  }
383  }
384  }
385 
386  // OpenCL mode requires swizzle length to be in accordance with accepted
387  // sizes. Clang however supports arbitrary lengths for other languages.
388  if (S.getLangOpts().OpenCL && !HalvingSwizzle) {
389  unsigned SwizzleLength = CompName->getLength();
390 
391  if (HexSwizzle)
392  SwizzleLength--;
393 
394  if (IsValidOpenCLComponentSwizzleLength(SwizzleLength) == false) {
395  S.Diag(OpLoc, diag::err_opencl_ext_vector_component_invalid_length)
396  << SwizzleLength << SourceRange(CompLoc);
397  return QualType();
398  }
399  }
400 
401  // The component accessor looks fine - now we need to compute the actual type.
402  // The vector type is implied by the component accessor. For example,
403  // vec4.b is a float, vec4.xy is a vec2, vec4.rgb is a vec3, etc.
404  // vec4.s0 is a float, vec4.s23 is a vec3, etc.
405  // vec4.hi, vec4.lo, vec4.e, and vec4.o all return vec2.
406  unsigned CompSize = HalvingSwizzle ? (vecType->getNumElements() + 1) / 2
407  : CompName->getLength();
408  if (HexSwizzle)
409  CompSize--;
410 
411  if (CompSize == 1)
412  return vecType->getElementType();
413 
414  if (HasRepeated) VK = VK_RValue;
415 
416  QualType VT = S.Context.getExtVectorType(vecType->getElementType(), CompSize);
417  // Now look up the TypeDefDecl from the vector type. Without this,
418  // diagostics look bad. We want extended vector types to appear built-in.
419  for (Sema::ExtVectorDeclsType::iterator
421  E = S.ExtVectorDecls.end();
422  I != E; ++I) {
423  if ((*I)->getUnderlyingType() == VT)
424  return S.Context.getTypedefType(*I);
425  }
426 
427  return VT; // should never get here (a typedef type should always be found).
428 }
429 
431  IdentifierInfo *Member,
432  const Selector &Sel,
433  ASTContext &Context) {
434  if (Member)
435  if (ObjCPropertyDecl *PD = PDecl->FindPropertyDeclaration(
437  return PD;
438  if (ObjCMethodDecl *OMD = PDecl->getInstanceMethod(Sel))
439  return OMD;
440 
441  for (const auto *I : PDecl->protocols()) {
442  if (Decl *D = FindGetterSetterNameDeclFromProtocolList(I, Member, Sel,
443  Context))
444  return D;
445  }
446  return nullptr;
447 }
448 
450  IdentifierInfo *Member,
451  const Selector &Sel,
452  ASTContext &Context) {
453  // Check protocols on qualified interfaces.
454  Decl *GDecl = nullptr;
455  for (const auto *I : QIdTy->quals()) {
456  if (Member)
457  if (ObjCPropertyDecl *PD = I->FindPropertyDeclaration(
459  GDecl = PD;
460  break;
461  }
462  // Also must look for a getter or setter name which uses property syntax.
463  if (ObjCMethodDecl *OMD = I->getInstanceMethod(Sel)) {
464  GDecl = OMD;
465  break;
466  }
467  }
468  if (!GDecl) {
469  for (const auto *I : QIdTy->quals()) {
470  // Search in the protocol-qualifier list of current protocol.
471  GDecl = FindGetterSetterNameDeclFromProtocolList(I, Member, Sel, Context);
472  if (GDecl)
473  return GDecl;
474  }
475  }
476  return GDecl;
477 }
478 
481  bool IsArrow, SourceLocation OpLoc,
482  const CXXScopeSpec &SS,
483  SourceLocation TemplateKWLoc,
484  NamedDecl *FirstQualifierInScope,
485  const DeclarationNameInfo &NameInfo,
486  const TemplateArgumentListInfo *TemplateArgs) {
487  // Even in dependent contexts, try to diagnose base expressions with
488  // obviously wrong types, e.g.:
489  //
490  // T* t;
491  // t.f;
492  //
493  // In Obj-C++, however, the above expression is valid, since it could be
494  // accessing the 'f' property if T is an Obj-C interface. The extra check
495  // allows this, while still reporting an error if T is a struct pointer.
496  if (!IsArrow) {
497  const PointerType *PT = BaseType->getAs<PointerType>();
498  if (PT && (!getLangOpts().ObjC ||
499  PT->getPointeeType()->isRecordType())) {
500  assert(BaseExpr && "cannot happen with implicit member accesses");
501  Diag(OpLoc, diag::err_typecheck_member_reference_struct_union)
502  << BaseType << BaseExpr->getSourceRange() << NameInfo.getSourceRange();
503  return ExprError();
504  }
505  }
506 
507  assert(BaseType->isDependentType() ||
508  NameInfo.getName().isDependentName() ||
509  isDependentScopeSpecifier(SS));
510 
511  // Get the type being accessed in BaseType. If this is an arrow, the BaseExpr
512  // must have pointer type, and the accessed type is the pointee.
514  Context, BaseExpr, BaseType, IsArrow, OpLoc,
515  SS.getWithLocInContext(Context), TemplateKWLoc, FirstQualifierInScope,
516  NameInfo, TemplateArgs);
517 }
518 
519 /// We know that the given qualified member reference points only to
520 /// declarations which do not belong to the static type of the base
521 /// expression. Diagnose the problem.
523  Expr *BaseExpr,
524  QualType BaseType,
525  const CXXScopeSpec &SS,
526  NamedDecl *rep,
527  const DeclarationNameInfo &nameInfo) {
528  // If this is an implicit member access, use a different set of
529  // diagnostics.
530  if (!BaseExpr)
531  return diagnoseInstanceReference(SemaRef, SS, rep, nameInfo);
532 
533  SemaRef.Diag(nameInfo.getLoc(), diag::err_qualified_member_of_unrelated)
534  << SS.getRange() << rep << BaseType;
535 }
536 
537 // Check whether the declarations we found through a nested-name
538 // specifier in a member expression are actually members of the base
539 // type. The restriction here is:
540 //
541 // C++ [expr.ref]p2:
542 // ... In these cases, the id-expression shall name a
543 // member of the class or of one of its base classes.
544 //
545 // So it's perfectly legitimate for the nested-name specifier to name
546 // an unrelated class, and for us to find an overload set including
547 // decls from classes which are not superclasses, as long as the decl
548 // we actually pick through overload resolution is from a superclass.
550  QualType BaseType,
551  const CXXScopeSpec &SS,
552  const LookupResult &R) {
553  CXXRecordDecl *BaseRecord =
554  cast_or_null<CXXRecordDecl>(computeDeclContext(BaseType));
555  if (!BaseRecord) {
556  // We can't check this yet because the base type is still
557  // dependent.
558  assert(BaseType->isDependentType());
559  return false;
560  }
561 
562  for (LookupResult::iterator I = R.begin(), E = R.end(); I != E; ++I) {
563  // If this is an implicit member reference and we find a
564  // non-instance member, it's not an error.
565  if (!BaseExpr && !(*I)->isCXXInstanceMember())
566  return false;
567 
568  // Note that we use the DC of the decl, not the underlying decl.
569  DeclContext *DC = (*I)->getDeclContext();
570  while (DC->isTransparentContext())
571  DC = DC->getParent();
572 
573  if (!DC->isRecord())
574  continue;
575 
576  CXXRecordDecl *MemberRecord = cast<CXXRecordDecl>(DC)->getCanonicalDecl();
577  if (BaseRecord->getCanonicalDecl() == MemberRecord ||
578  !BaseRecord->isProvablyNotDerivedFrom(MemberRecord))
579  return false;
580  }
581 
582  DiagnoseQualifiedMemberReference(*this, BaseExpr, BaseType, SS,
584  R.getLookupNameInfo());
585  return true;
586 }
587 
588 namespace {
589 
590 // Callback to only accept typo corrections that are either a ValueDecl or a
591 // FunctionTemplateDecl and are declared in the current record or, for a C++
592 // classes, one of its base classes.
593 class RecordMemberExprValidatorCCC : public CorrectionCandidateCallback {
594 public:
595  explicit RecordMemberExprValidatorCCC(const RecordType *RTy)
596  : Record(RTy->getDecl()) {
597  // Don't add bare keywords to the consumer since they will always fail
598  // validation by virtue of not being associated with any decls.
599  WantTypeSpecifiers = false;
600  WantExpressionKeywords = false;
601  WantCXXNamedCasts = false;
602  WantFunctionLikeCasts = false;
603  WantRemainingKeywords = false;
604  }
605 
606  bool ValidateCandidate(const TypoCorrection &candidate) override {
607  NamedDecl *ND = candidate.getCorrectionDecl();
608  // Don't accept candidates that cannot be member functions, constants,
609  // variables, or templates.
610  if (!ND || !(isa<ValueDecl>(ND) || isa<FunctionTemplateDecl>(ND)))
611  return false;
612 
613  // Accept candidates that occur in the current record.
614  if (Record->containsDecl(ND))
615  return true;
616 
617  if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(Record)) {
618  // Accept candidates that occur in any of the current class' base classes.
619  for (const auto &BS : RD->bases()) {
620  if (const RecordType *BSTy =
621  dyn_cast_or_null<RecordType>(BS.getType().getTypePtrOrNull())) {
622  if (BSTy->getDecl()->containsDecl(ND))
623  return true;
624  }
625  }
626  }
627 
628  return false;
629  }
630 
631 private:
632  const RecordDecl *const Record;
633 };
634 
635 }
636 
637 static bool LookupMemberExprInRecord(Sema &SemaRef, LookupResult &R,
638  Expr *BaseExpr,
639  const RecordType *RTy,
640  SourceLocation OpLoc, bool IsArrow,
641  CXXScopeSpec &SS, bool HasTemplateArgs,
642  SourceLocation TemplateKWLoc,
643  TypoExpr *&TE) {
644  SourceRange BaseRange = BaseExpr ? BaseExpr->getSourceRange() : SourceRange();
645  RecordDecl *RDecl = RTy->getDecl();
646  if (!SemaRef.isThisOutsideMemberFunctionBody(QualType(RTy, 0)) &&
647  SemaRef.RequireCompleteType(OpLoc, QualType(RTy, 0),
648  diag::err_typecheck_incomplete_tag,
649  BaseRange))
650  return true;
651 
652  if (HasTemplateArgs || TemplateKWLoc.isValid()) {
653  // LookupTemplateName doesn't expect these both to exist simultaneously.
654  QualType ObjectType = SS.isSet() ? QualType() : QualType(RTy, 0);
655 
656  bool MOUS;
657  return SemaRef.LookupTemplateName(R, nullptr, SS, ObjectType, false, MOUS,
658  TemplateKWLoc);
659  }
660 
661  DeclContext *DC = RDecl;
662  if (SS.isSet()) {
663  // If the member name was a qualified-id, look into the
664  // nested-name-specifier.
665  DC = SemaRef.computeDeclContext(SS, false);
666 
667  if (SemaRef.RequireCompleteDeclContext(SS, DC)) {
668  SemaRef.Diag(SS.getRange().getEnd(), diag::err_typecheck_incomplete_tag)
669  << SS.getRange() << DC;
670  return true;
671  }
672 
673  assert(DC && "Cannot handle non-computable dependent contexts in lookup");
674 
675  if (!isa<TypeDecl>(DC)) {
676  SemaRef.Diag(R.getNameLoc(), diag::err_qualified_member_nonclass)
677  << DC << SS.getRange();
678  return true;
679  }
680  }
681 
682  // The record definition is complete, now look up the member.
683  SemaRef.LookupQualifiedName(R, DC, SS);
684 
685  if (!R.empty())
686  return false;
687 
688  DeclarationName Typo = R.getLookupName();
689  SourceLocation TypoLoc = R.getNameLoc();
690 
691  struct QueryState {
692  Sema &SemaRef;
693  DeclarationNameInfo NameInfo;
694  Sema::LookupNameKind LookupKind;
696  };
697  QueryState Q = {R.getSema(), R.getLookupNameInfo(), R.getLookupKind(),
698  R.redeclarationKind()};
699  TE = SemaRef.CorrectTypoDelayed(
700  R.getLookupNameInfo(), R.getLookupKind(), nullptr, &SS,
701  llvm::make_unique<RecordMemberExprValidatorCCC>(RTy),
702  [=, &SemaRef](const TypoCorrection &TC) {
703  if (TC) {
704  assert(!TC.isKeyword() &&
705  "Got a keyword as a correction for a member!");
706  bool DroppedSpecifier =
707  TC.WillReplaceSpecifier() &&
708  Typo.getAsString() == TC.getAsString(SemaRef.getLangOpts());
709  SemaRef.diagnoseTypo(TC, SemaRef.PDiag(diag::err_no_member_suggest)
710  << Typo << DC << DroppedSpecifier
711  << SS.getRange());
712  } else {
713  SemaRef.Diag(TypoLoc, diag::err_no_member) << Typo << DC << BaseRange;
714  }
715  },
716  [=](Sema &SemaRef, TypoExpr *TE, TypoCorrection TC) mutable {
717  LookupResult R(Q.SemaRef, Q.NameInfo, Q.LookupKind, Q.Redecl);
718  R.clear(); // Ensure there's no decls lingering in the shared state.
721  for (NamedDecl *ND : TC)
722  R.addDecl(ND);
723  R.resolveKind();
724  return SemaRef.BuildMemberReferenceExpr(
725  BaseExpr, BaseExpr->getType(), OpLoc, IsArrow, SS, SourceLocation(),
726  nullptr, R, nullptr, nullptr);
727  },
729 
730  return false;
731 }
732 
734  ExprResult &BaseExpr, bool &IsArrow,
735  SourceLocation OpLoc, CXXScopeSpec &SS,
736  Decl *ObjCImpDecl, bool HasTemplateArgs,
737  SourceLocation TemplateKWLoc);
738 
741  SourceLocation OpLoc, bool IsArrow,
742  CXXScopeSpec &SS,
743  SourceLocation TemplateKWLoc,
744  NamedDecl *FirstQualifierInScope,
745  const DeclarationNameInfo &NameInfo,
746  const TemplateArgumentListInfo *TemplateArgs,
747  const Scope *S,
748  ActOnMemberAccessExtraArgs *ExtraArgs) {
749  if (BaseType->isDependentType() ||
750  (SS.isSet() && isDependentScopeSpecifier(SS)))
751  return ActOnDependentMemberExpr(Base, BaseType,
752  IsArrow, OpLoc,
753  SS, TemplateKWLoc, FirstQualifierInScope,
754  NameInfo, TemplateArgs);
755 
756  LookupResult R(*this, NameInfo, LookupMemberName);
757 
758  // Implicit member accesses.
759  if (!Base) {
760  TypoExpr *TE = nullptr;
761  QualType RecordTy = BaseType;
762  if (IsArrow) RecordTy = RecordTy->getAs<PointerType>()->getPointeeType();
764  *this, R, nullptr, RecordTy->getAs<RecordType>(), OpLoc, IsArrow,
765  SS, TemplateArgs != nullptr, TemplateKWLoc, TE))
766  return ExprError();
767  if (TE)
768  return TE;
769 
770  // Explicit member accesses.
771  } else {
772  ExprResult BaseResult = Base;
773  ExprResult Result =
774  LookupMemberExpr(*this, R, BaseResult, IsArrow, OpLoc, SS,
775  ExtraArgs ? ExtraArgs->ObjCImpDecl : nullptr,
776  TemplateArgs != nullptr, TemplateKWLoc);
777 
778  if (BaseResult.isInvalid())
779  return ExprError();
780  Base = BaseResult.get();
781 
782  if (Result.isInvalid())
783  return ExprError();
784 
785  if (Result.get())
786  return Result;
787 
788  // LookupMemberExpr can modify Base, and thus change BaseType
789  BaseType = Base->getType();
790  }
791 
792  return BuildMemberReferenceExpr(Base, BaseType,
793  OpLoc, IsArrow, SS, TemplateKWLoc,
794  FirstQualifierInScope, R, TemplateArgs, S,
795  false, ExtraArgs);
796 }
797 
800  SourceLocation loc,
801  IndirectFieldDecl *indirectField,
802  DeclAccessPair foundDecl,
803  Expr *baseObjectExpr,
804  SourceLocation opLoc) {
805  // First, build the expression that refers to the base object.
806 
807  // Case 1: the base of the indirect field is not a field.
808  VarDecl *baseVariable = indirectField->getVarDecl();
809  CXXScopeSpec EmptySS;
810  if (baseVariable) {
811  assert(baseVariable->getType()->isRecordType());
812 
813  // In principle we could have a member access expression that
814  // accesses an anonymous struct/union that's a static member of
815  // the base object's class. However, under the current standard,
816  // static data members cannot be anonymous structs or unions.
817  // Supporting this is as easy as building a MemberExpr here.
818  assert(!baseObjectExpr && "anonymous struct/union is static data member?");
819 
820  DeclarationNameInfo baseNameInfo(DeclarationName(), loc);
821 
822  ExprResult result
823  = BuildDeclarationNameExpr(EmptySS, baseNameInfo, baseVariable);
824  if (result.isInvalid()) return ExprError();
825 
826  baseObjectExpr = result.get();
827  }
828 
829  assert((baseVariable || baseObjectExpr) &&
830  "referencing anonymous struct/union without a base variable or "
831  "expression");
832 
833  // Build the implicit member references to the field of the
834  // anonymous struct/union.
835  Expr *result = baseObjectExpr;
837  FI = indirectField->chain_begin(), FEnd = indirectField->chain_end();
838 
839  // Case 2: the base of the indirect field is a field and the user
840  // wrote a member expression.
841  if (!baseVariable) {
842  FieldDecl *field = cast<FieldDecl>(*FI);
843 
844  bool baseObjectIsPointer = baseObjectExpr->getType()->isPointerType();
845 
846  // Make a nameInfo that properly uses the anonymous name.
847  DeclarationNameInfo memberNameInfo(field->getDeclName(), loc);
848 
849  // Build the first member access in the chain with full information.
850  result =
851  BuildFieldReferenceExpr(result, baseObjectIsPointer, SourceLocation(),
852  SS, field, foundDecl, memberNameInfo)
853  .get();
854  if (!result)
855  return ExprError();
856  }
857 
858  // In all cases, we should now skip the first declaration in the chain.
859  ++FI;
860 
861  while (FI != FEnd) {
862  FieldDecl *field = cast<FieldDecl>(*FI++);
863 
864  // FIXME: these are somewhat meaningless
865  DeclarationNameInfo memberNameInfo(field->getDeclName(), loc);
866  DeclAccessPair fakeFoundDecl =
867  DeclAccessPair::make(field, field->getAccess());
868 
869  result =
870  BuildFieldReferenceExpr(result, /*isarrow*/ false, SourceLocation(),
871  (FI == FEnd ? SS : EmptySS), field,
872  fakeFoundDecl, memberNameInfo)
873  .get();
874  }
875 
876  return result;
877 }
878 
879 static ExprResult
880 BuildMSPropertyRefExpr(Sema &S, Expr *BaseExpr, bool IsArrow,
881  const CXXScopeSpec &SS,
882  MSPropertyDecl *PD,
883  const DeclarationNameInfo &NameInfo) {
884  // Property names are always simple identifiers and therefore never
885  // require any interesting additional storage.
886  return new (S.Context) MSPropertyRefExpr(BaseExpr, PD, IsArrow,
889  NameInfo.getLoc());
890 }
891 
892 /// Build a MemberExpr AST node.
894  Sema &SemaRef, ASTContext &C, Expr *Base, bool isArrow,
895  SourceLocation OpLoc, const CXXScopeSpec &SS, SourceLocation TemplateKWLoc,
896  ValueDecl *Member, DeclAccessPair FoundDecl,
897  const DeclarationNameInfo &MemberNameInfo, QualType Ty, ExprValueKind VK,
898  ExprObjectKind OK, const TemplateArgumentListInfo *TemplateArgs = nullptr) {
899  assert((!isArrow || Base->isRValue()) && "-> base must be a pointer rvalue");
901  C, Base, isArrow, OpLoc, SS.getWithLocInContext(C), TemplateKWLoc, Member,
902  FoundDecl, MemberNameInfo, TemplateArgs, Ty, VK, OK);
903  SemaRef.MarkMemberReferenced(E);
904  return E;
905 }
906 
907 /// Determine if the given scope is within a function-try-block handler.
908 static bool IsInFnTryBlockHandler(const Scope *S) {
909  // Walk the scope stack until finding a FnTryCatchScope, or leave the
910  // function scope. If a FnTryCatchScope is found, check whether the TryScope
911  // flag is set. If it is not, it's a function-try-block handler.
912  for (; S != S->getFnParent(); S = S->getParent()) {
913  if (S->getFlags() & Scope::FnTryCatchScope)
914  return (S->getFlags() & Scope::TryScope) != Scope::TryScope;
915  }
916  return false;
917 }
918 
919 static VarDecl *
921  const TemplateArgumentListInfo *TemplateArgs,
922  const DeclarationNameInfo &MemberNameInfo,
923  SourceLocation TemplateKWLoc) {
924  if (!TemplateArgs) {
926  MemberNameInfo.getBeginLoc());
927  return nullptr;
928  }
929 
930  DeclResult VDecl = S.CheckVarTemplateId(
931  VarTempl, TemplateKWLoc, MemberNameInfo.getLoc(), *TemplateArgs);
932  if (VDecl.isInvalid())
933  return nullptr;
934  VarDecl *Var = cast<VarDecl>(VDecl.get());
935  if (!Var->getTemplateSpecializationKind())
937  MemberNameInfo.getLoc());
938  return Var;
939 }
940 
943  SourceLocation OpLoc, bool IsArrow,
944  const CXXScopeSpec &SS,
945  SourceLocation TemplateKWLoc,
946  NamedDecl *FirstQualifierInScope,
947  LookupResult &R,
948  const TemplateArgumentListInfo *TemplateArgs,
949  const Scope *S,
950  bool SuppressQualifierCheck,
951  ActOnMemberAccessExtraArgs *ExtraArgs) {
952  QualType BaseType = BaseExprType;
953  if (IsArrow) {
954  assert(BaseType->isPointerType());
955  BaseType = BaseType->castAs<PointerType>()->getPointeeType();
956  }
957  R.setBaseObjectType(BaseType);
958 
959  // C++1z [expr.ref]p2:
960  // For the first option (dot) the first expression shall be a glvalue [...]
961  if (!IsArrow && BaseExpr && BaseExpr->isRValue()) {
962  ExprResult Converted = TemporaryMaterializationConversion(BaseExpr);
963  if (Converted.isInvalid())
964  return ExprError();
965  BaseExpr = Converted.get();
966  }
967 
968 
969  const DeclarationNameInfo &MemberNameInfo = R.getLookupNameInfo();
970  DeclarationName MemberName = MemberNameInfo.getName();
971  SourceLocation MemberLoc = MemberNameInfo.getLoc();
972 
973  if (R.isAmbiguous())
974  return ExprError();
975 
976  // [except.handle]p10: Referring to any non-static member or base class of an
977  // object in the handler for a function-try-block of a constructor or
978  // destructor for that object results in undefined behavior.
979  const auto *FD = getCurFunctionDecl();
980  if (S && BaseExpr && FD &&
981  (isa<CXXDestructorDecl>(FD) || isa<CXXConstructorDecl>(FD)) &&
982  isa<CXXThisExpr>(BaseExpr->IgnoreImpCasts()) &&
984  Diag(MemberLoc, diag::warn_cdtor_function_try_handler_mem_expr)
985  << isa<CXXDestructorDecl>(FD);
986 
987  if (R.empty()) {
988  // Rederive where we looked up.
989  DeclContext *DC = (SS.isSet()
990  ? computeDeclContext(SS, false)
991  : BaseType->getAs<RecordType>()->getDecl());
992 
993  if (ExtraArgs) {
994  ExprResult RetryExpr;
995  if (!IsArrow && BaseExpr) {
996  SFINAETrap Trap(*this, true);
997  ParsedType ObjectType;
998  bool MayBePseudoDestructor = false;
999  RetryExpr = ActOnStartCXXMemberReference(getCurScope(), BaseExpr,
1000  OpLoc, tok::arrow, ObjectType,
1001  MayBePseudoDestructor);
1002  if (RetryExpr.isUsable() && !Trap.hasErrorOccurred()) {
1003  CXXScopeSpec TempSS(SS);
1004  RetryExpr = ActOnMemberAccessExpr(
1005  ExtraArgs->S, RetryExpr.get(), OpLoc, tok::arrow, TempSS,
1006  TemplateKWLoc, ExtraArgs->Id, ExtraArgs->ObjCImpDecl);
1007  }
1008  if (Trap.hasErrorOccurred())
1009  RetryExpr = ExprError();
1010  }
1011  if (RetryExpr.isUsable()) {
1012  Diag(OpLoc, diag::err_no_member_overloaded_arrow)
1013  << MemberName << DC << FixItHint::CreateReplacement(OpLoc, "->");
1014  return RetryExpr;
1015  }
1016  }
1017 
1018  Diag(R.getNameLoc(), diag::err_no_member)
1019  << MemberName << DC
1020  << (BaseExpr ? BaseExpr->getSourceRange() : SourceRange());
1021  return ExprError();
1022  }
1023 
1024  // Diagnose lookups that find only declarations from a non-base
1025  // type. This is possible for either qualified lookups (which may
1026  // have been qualified with an unrelated type) or implicit member
1027  // expressions (which were found with unqualified lookup and thus
1028  // may have come from an enclosing scope). Note that it's okay for
1029  // lookup to find declarations from a non-base type as long as those
1030  // aren't the ones picked by overload resolution.
1031  if ((SS.isSet() || !BaseExpr ||
1032  (isa<CXXThisExpr>(BaseExpr) &&
1033  cast<CXXThisExpr>(BaseExpr)->isImplicit())) &&
1034  !SuppressQualifierCheck &&
1035  CheckQualifiedMemberReference(BaseExpr, BaseType, SS, R))
1036  return ExprError();
1037 
1038  // Construct an unresolved result if we in fact got an unresolved
1039  // result.
1040  if (R.isOverloadedResult() || R.isUnresolvableResult()) {
1041  // Suppress any lookup-related diagnostics; we'll do these when we
1042  // pick a member.
1043  R.suppressDiagnostics();
1044 
1045  UnresolvedMemberExpr *MemExpr
1047  BaseExpr, BaseExprType,
1048  IsArrow, OpLoc,
1049  SS.getWithLocInContext(Context),
1050  TemplateKWLoc, MemberNameInfo,
1051  TemplateArgs, R.begin(), R.end());
1052 
1053  return MemExpr;
1054  }
1055 
1056  assert(R.isSingleResult());
1057  DeclAccessPair FoundDecl = R.begin().getPair();
1058  NamedDecl *MemberDecl = R.getFoundDecl();
1059 
1060  // FIXME: diagnose the presence of template arguments now.
1061 
1062  // If the decl being referenced had an error, return an error for this
1063  // sub-expr without emitting another error, in order to avoid cascading
1064  // error cases.
1065  if (MemberDecl->isInvalidDecl())
1066  return ExprError();
1067 
1068  // Handle the implicit-member-access case.
1069  if (!BaseExpr) {
1070  // If this is not an instance member, convert to a non-member access.
1071  if (!MemberDecl->isCXXInstanceMember()) {
1072  // If this is a variable template, get the instantiated variable
1073  // declaration corresponding to the supplied template arguments
1074  // (while emitting diagnostics as necessary) that will be referenced
1075  // by this expression.
1076  assert((!TemplateArgs || isa<VarTemplateDecl>(MemberDecl)) &&
1077  "How did we get template arguments here sans a variable template");
1078  if (isa<VarTemplateDecl>(MemberDecl)) {
1079  MemberDecl = getVarTemplateSpecialization(
1080  *this, cast<VarTemplateDecl>(MemberDecl), TemplateArgs,
1081  R.getLookupNameInfo(), TemplateKWLoc);
1082  if (!MemberDecl)
1083  return ExprError();
1084  }
1085  return BuildDeclarationNameExpr(SS, R.getLookupNameInfo(), MemberDecl,
1086  FoundDecl, TemplateArgs);
1087  }
1088  SourceLocation Loc = R.getNameLoc();
1089  if (SS.getRange().isValid())
1090  Loc = SS.getRange().getBegin();
1091  CheckCXXThisCapture(Loc);
1092  BaseExpr = new (Context) CXXThisExpr(Loc, BaseExprType,/*isImplicit=*/true);
1093  }
1094 
1095  // Check the use of this member.
1096  if (DiagnoseUseOfDecl(MemberDecl, MemberLoc))
1097  return ExprError();
1098 
1099  if (FieldDecl *FD = dyn_cast<FieldDecl>(MemberDecl))
1100  return BuildFieldReferenceExpr(BaseExpr, IsArrow, OpLoc, SS, FD, FoundDecl,
1101  MemberNameInfo);
1102 
1103  if (MSPropertyDecl *PD = dyn_cast<MSPropertyDecl>(MemberDecl))
1104  return BuildMSPropertyRefExpr(*this, BaseExpr, IsArrow, SS, PD,
1105  MemberNameInfo);
1106 
1107  if (IndirectFieldDecl *FD = dyn_cast<IndirectFieldDecl>(MemberDecl))
1108  // We may have found a field within an anonymous union or struct
1109  // (C++ [class.union]).
1110  return BuildAnonymousStructUnionMemberReference(SS, MemberLoc, FD,
1111  FoundDecl, BaseExpr,
1112  OpLoc);
1113 
1114  if (VarDecl *Var = dyn_cast<VarDecl>(MemberDecl)) {
1115  return BuildMemberExpr(*this, Context, BaseExpr, IsArrow, OpLoc, SS,
1116  TemplateKWLoc, Var, FoundDecl, MemberNameInfo,
1117  Var->getType().getNonReferenceType(), VK_LValue,
1118  OK_Ordinary);
1119  }
1120 
1121  if (CXXMethodDecl *MemberFn = dyn_cast<CXXMethodDecl>(MemberDecl)) {
1122  ExprValueKind valueKind;
1123  QualType type;
1124  if (MemberFn->isInstance()) {
1125  valueKind = VK_RValue;
1126  type = Context.BoundMemberTy;
1127  } else {
1128  valueKind = VK_LValue;
1129  type = MemberFn->getType();
1130  }
1131 
1132  return BuildMemberExpr(*this, Context, BaseExpr, IsArrow, OpLoc, SS,
1133  TemplateKWLoc, MemberFn, FoundDecl, MemberNameInfo,
1134  type, valueKind, OK_Ordinary);
1135  }
1136  assert(!isa<FunctionDecl>(MemberDecl) && "member function not C++ method?");
1137 
1138  if (EnumConstantDecl *Enum = dyn_cast<EnumConstantDecl>(MemberDecl)) {
1139  return BuildMemberExpr(*this, Context, BaseExpr, IsArrow, OpLoc, SS,
1140  TemplateKWLoc, Enum, FoundDecl, MemberNameInfo,
1141  Enum->getType(), VK_RValue, OK_Ordinary);
1142  }
1143  if (VarTemplateDecl *VarTempl = dyn_cast<VarTemplateDecl>(MemberDecl)) {
1145  *this, VarTempl, TemplateArgs, MemberNameInfo, TemplateKWLoc))
1146  return BuildMemberExpr(*this, Context, BaseExpr, IsArrow, OpLoc, SS,
1147  TemplateKWLoc, Var, FoundDecl, MemberNameInfo,
1148  Var->getType().getNonReferenceType(), VK_LValue,
1149  OK_Ordinary);
1150  return ExprError();
1151  }
1152 
1153  // We found something that we didn't expect. Complain.
1154  if (isa<TypeDecl>(MemberDecl))
1155  Diag(MemberLoc, diag::err_typecheck_member_reference_type)
1156  << MemberName << BaseType << int(IsArrow);
1157  else
1158  Diag(MemberLoc, diag::err_typecheck_member_reference_unknown)
1159  << MemberName << BaseType << int(IsArrow);
1160 
1161  Diag(MemberDecl->getLocation(), diag::note_member_declared_here)
1162  << MemberName;
1163  R.suppressDiagnostics();
1164  return ExprError();
1165 }
1166 
1167 /// Given that normal member access failed on the given expression,
1168 /// and given that the expression's type involves builtin-id or
1169 /// builtin-Class, decide whether substituting in the redefinition
1170 /// types would be profitable. The redefinition type is whatever
1171 /// this translation unit tried to typedef to id/Class; we store
1172 /// it to the side and then re-use it in places like this.
1174  const ObjCObjectPointerType *opty
1175  = base.get()->getType()->getAs<ObjCObjectPointerType>();
1176  if (!opty) return false;
1177 
1178  const ObjCObjectType *ty = opty->getObjectType();
1179 
1180  QualType redef;
1181  if (ty->isObjCId()) {
1182  redef = S.Context.getObjCIdRedefinitionType();
1183  } else if (ty->isObjCClass()) {
1185  } else {
1186  return false;
1187  }
1188 
1189  // Do the substitution as long as the redefinition type isn't just a
1190  // possibly-qualified pointer to builtin-id or builtin-Class again.
1191  opty = redef->getAs<ObjCObjectPointerType>();
1192  if (opty && !opty->getObjectType()->getInterface())
1193  return false;
1194 
1195  base = S.ImpCastExprToType(base.get(), redef, CK_BitCast);
1196  return true;
1197 }
1198 
1199 static bool isRecordType(QualType T) {
1200  return T->isRecordType();
1201 }
1203  if (const PointerType *PT = T->getAs<PointerType>())
1204  return PT->getPointeeType()->isRecordType();
1205  return false;
1206 }
1207 
1208 /// Perform conversions on the LHS of a member access expression.
1209 ExprResult
1211  if (IsArrow && !Base->getType()->isFunctionType())
1212  return DefaultFunctionArrayLvalueConversion(Base);
1213 
1214  return CheckPlaceholderExpr(Base);
1215 }
1216 
1217 /// Look up the given member of the given non-type-dependent
1218 /// expression. This can return in one of two ways:
1219 /// * If it returns a sentinel null-but-valid result, the caller will
1220 /// assume that lookup was performed and the results written into
1221 /// the provided structure. It will take over from there.
1222 /// * Otherwise, the returned expression will be produced in place of
1223 /// an ordinary member expression.
1224 ///
1225 /// The ObjCImpDecl bit is a gross hack that will need to be properly
1226 /// fixed for ObjC++.
1228  ExprResult &BaseExpr, bool &IsArrow,
1229  SourceLocation OpLoc, CXXScopeSpec &SS,
1230  Decl *ObjCImpDecl, bool HasTemplateArgs,
1231  SourceLocation TemplateKWLoc) {
1232  assert(BaseExpr.get() && "no base expression");
1233 
1234  // Perform default conversions.
1235  BaseExpr = S.PerformMemberExprBaseConversion(BaseExpr.get(), IsArrow);
1236  if (BaseExpr.isInvalid())
1237  return ExprError();
1238 
1239  QualType BaseType = BaseExpr.get()->getType();
1240  assert(!BaseType->isDependentType());
1241 
1242  DeclarationName MemberName = R.getLookupName();
1243  SourceLocation MemberLoc = R.getNameLoc();
1244 
1245  // For later type-checking purposes, turn arrow accesses into dot
1246  // accesses. The only access type we support that doesn't follow
1247  // the C equivalence "a->b === (*a).b" is ObjC property accesses,
1248  // and those never use arrows, so this is unaffected.
1249  if (IsArrow) {
1250  if (const PointerType *Ptr = BaseType->getAs<PointerType>())
1251  BaseType = Ptr->getPointeeType();
1252  else if (const ObjCObjectPointerType *Ptr
1253  = BaseType->getAs<ObjCObjectPointerType>())
1254  BaseType = Ptr->getPointeeType();
1255  else if (BaseType->isRecordType()) {
1256  // Recover from arrow accesses to records, e.g.:
1257  // struct MyRecord foo;
1258  // foo->bar
1259  // This is actually well-formed in C++ if MyRecord has an
1260  // overloaded operator->, but that should have been dealt with
1261  // by now--or a diagnostic message already issued if a problem
1262  // was encountered while looking for the overloaded operator->.
1263  if (!S.getLangOpts().CPlusPlus) {
1264  S.Diag(OpLoc, diag::err_typecheck_member_reference_suggestion)
1265  << BaseType << int(IsArrow) << BaseExpr.get()->getSourceRange()
1266  << FixItHint::CreateReplacement(OpLoc, ".");
1267  }
1268  IsArrow = false;
1269  } else if (BaseType->isFunctionType()) {
1270  goto fail;
1271  } else {
1272  S.Diag(MemberLoc, diag::err_typecheck_member_reference_arrow)
1273  << BaseType << BaseExpr.get()->getSourceRange();
1274  return ExprError();
1275  }
1276  }
1277 
1278  // Handle field access to simple records.
1279  if (const RecordType *RTy = BaseType->getAs<RecordType>()) {
1280  TypoExpr *TE = nullptr;
1281  if (LookupMemberExprInRecord(S, R, BaseExpr.get(), RTy, OpLoc, IsArrow, SS,
1282  HasTemplateArgs, TemplateKWLoc, TE))
1283  return ExprError();
1284 
1285  // Returning valid-but-null is how we indicate to the caller that
1286  // the lookup result was filled in. If typo correction was attempted and
1287  // failed, the lookup result will have been cleared--that combined with the
1288  // valid-but-null ExprResult will trigger the appropriate diagnostics.
1289  return ExprResult(TE);
1290  }
1291 
1292  // Handle ivar access to Objective-C objects.
1293  if (const ObjCObjectType *OTy = BaseType->getAs<ObjCObjectType>()) {
1294  if (!SS.isEmpty() && !SS.isInvalid()) {
1295  S.Diag(SS.getRange().getBegin(), diag::err_qualified_objc_access)
1296  << 1 << SS.getScopeRep()
1298  SS.clear();
1299  }
1300 
1301  IdentifierInfo *Member = MemberName.getAsIdentifierInfo();
1302 
1303  // There are three cases for the base type:
1304  // - builtin id (qualified or unqualified)
1305  // - builtin Class (qualified or unqualified)
1306  // - an interface
1307  ObjCInterfaceDecl *IDecl = OTy->getInterface();
1308  if (!IDecl) {
1309  if (S.getLangOpts().ObjCAutoRefCount &&
1310  (OTy->isObjCId() || OTy->isObjCClass()))
1311  goto fail;
1312  // There's an implicit 'isa' ivar on all objects.
1313  // But we only actually find it this way on objects of type 'id',
1314  // apparently.
1315  if (OTy->isObjCId() && Member->isStr("isa"))
1316  return new (S.Context) ObjCIsaExpr(BaseExpr.get(), IsArrow, MemberLoc,
1317  OpLoc, S.Context.getObjCClassType());
1318  if (ShouldTryAgainWithRedefinitionType(S, BaseExpr))
1319  return LookupMemberExpr(S, R, BaseExpr, IsArrow, OpLoc, SS,
1320  ObjCImpDecl, HasTemplateArgs, TemplateKWLoc);
1321  goto fail;
1322  }
1323 
1324  if (S.RequireCompleteType(OpLoc, BaseType,
1325  diag::err_typecheck_incomplete_tag,
1326  BaseExpr.get()))
1327  return ExprError();
1328 
1329  ObjCInterfaceDecl *ClassDeclared = nullptr;
1330  ObjCIvarDecl *IV = IDecl->lookupInstanceVariable(Member, ClassDeclared);
1331 
1332  if (!IV) {
1333  // Attempt to correct for typos in ivar names.
1334  auto Validator = llvm::make_unique<DeclFilterCCC<ObjCIvarDecl>>();
1335  Validator->IsObjCIvarLookup = IsArrow;
1336  if (TypoCorrection Corrected = S.CorrectTypo(
1337  R.getLookupNameInfo(), Sema::LookupMemberName, nullptr, nullptr,
1338  std::move(Validator), Sema::CTK_ErrorRecovery, IDecl)) {
1339  IV = Corrected.getCorrectionDeclAs<ObjCIvarDecl>();
1340  S.diagnoseTypo(
1341  Corrected,
1342  S.PDiag(diag::err_typecheck_member_reference_ivar_suggest)
1343  << IDecl->getDeclName() << MemberName);
1344 
1345  // Figure out the class that declares the ivar.
1346  assert(!ClassDeclared);
1347 
1348  Decl *D = cast<Decl>(IV->getDeclContext());
1349  if (auto *Category = dyn_cast<ObjCCategoryDecl>(D))
1350  D = Category->getClassInterface();
1351 
1352  if (auto *Implementation = dyn_cast<ObjCImplementationDecl>(D))
1353  ClassDeclared = Implementation->getClassInterface();
1354  else if (auto *Interface = dyn_cast<ObjCInterfaceDecl>(D))
1355  ClassDeclared = Interface;
1356 
1357  assert(ClassDeclared && "cannot query interface");
1358  } else {
1359  if (IsArrow &&
1360  IDecl->FindPropertyDeclaration(
1362  S.Diag(MemberLoc, diag::err_property_found_suggest)
1363  << Member << BaseExpr.get()->getType()
1364  << FixItHint::CreateReplacement(OpLoc, ".");
1365  return ExprError();
1366  }
1367 
1368  S.Diag(MemberLoc, diag::err_typecheck_member_reference_ivar)
1369  << IDecl->getDeclName() << MemberName
1370  << BaseExpr.get()->getSourceRange();
1371  return ExprError();
1372  }
1373  }
1374 
1375  assert(ClassDeclared);
1376 
1377  // If the decl being referenced had an error, return an error for this
1378  // sub-expr without emitting another error, in order to avoid cascading
1379  // error cases.
1380  if (IV->isInvalidDecl())
1381  return ExprError();
1382 
1383  // Check whether we can reference this field.
1384  if (S.DiagnoseUseOfDecl(IV, MemberLoc))
1385  return ExprError();
1386  if (IV->getAccessControl() != ObjCIvarDecl::Public &&
1388  ObjCInterfaceDecl *ClassOfMethodDecl = nullptr;
1389  if (ObjCMethodDecl *MD = S.getCurMethodDecl())
1390  ClassOfMethodDecl = MD->getClassInterface();
1391  else if (ObjCImpDecl && S.getCurFunctionDecl()) {
1392  // Case of a c-function declared inside an objc implementation.
1393  // FIXME: For a c-style function nested inside an objc implementation
1394  // class, there is no implementation context available, so we pass
1395  // down the context as argument to this routine. Ideally, this context
1396  // need be passed down in the AST node and somehow calculated from the
1397  // AST for a function decl.
1398  if (ObjCImplementationDecl *IMPD =
1399  dyn_cast<ObjCImplementationDecl>(ObjCImpDecl))
1400  ClassOfMethodDecl = IMPD->getClassInterface();
1401  else if (ObjCCategoryImplDecl* CatImplClass =
1402  dyn_cast<ObjCCategoryImplDecl>(ObjCImpDecl))
1403  ClassOfMethodDecl = CatImplClass->getClassInterface();
1404  }
1405  if (!S.getLangOpts().DebuggerSupport) {
1406  if (IV->getAccessControl() == ObjCIvarDecl::Private) {
1407  if (!declaresSameEntity(ClassDeclared, IDecl) ||
1408  !declaresSameEntity(ClassOfMethodDecl, ClassDeclared))
1409  S.Diag(MemberLoc, diag::err_private_ivar_access)
1410  << IV->getDeclName();
1411  } else if (!IDecl->isSuperClassOf(ClassOfMethodDecl))
1412  // @protected
1413  S.Diag(MemberLoc, diag::err_protected_ivar_access)
1414  << IV->getDeclName();
1415  }
1416  }
1417  bool warn = true;
1418  if (S.getLangOpts().ObjCWeak) {
1419  Expr *BaseExp = BaseExpr.get()->IgnoreParenImpCasts();
1420  if (UnaryOperator *UO = dyn_cast<UnaryOperator>(BaseExp))
1421  if (UO->getOpcode() == UO_Deref)
1422  BaseExp = UO->getSubExpr()->IgnoreParenCasts();
1423 
1424  if (DeclRefExpr *DE = dyn_cast<DeclRefExpr>(BaseExp))
1425  if (DE->getType().getObjCLifetime() == Qualifiers::OCL_Weak) {
1426  S.Diag(DE->getLocation(), diag::err_arc_weak_ivar_access);
1427  warn = false;
1428  }
1429  }
1430  if (warn) {
1431  if (ObjCMethodDecl *MD = S.getCurMethodDecl()) {
1432  ObjCMethodFamily MF = MD->getMethodFamily();
1433  warn = (MF != OMF_init && MF != OMF_dealloc &&
1434  MF != OMF_finalize &&
1435  !S.IvarBacksCurrentMethodAccessor(IDecl, MD, IV));
1436  }
1437  if (warn)
1438  S.Diag(MemberLoc, diag::warn_direct_ivar_access) << IV->getDeclName();
1439  }
1440 
1441  ObjCIvarRefExpr *Result = new (S.Context) ObjCIvarRefExpr(
1442  IV, IV->getUsageType(BaseType), MemberLoc, OpLoc, BaseExpr.get(),
1443  IsArrow);
1444 
1445  if (IV->getType().getObjCLifetime() == Qualifiers::OCL_Weak) {
1446  if (!S.isUnevaluatedContext() &&
1447  !S.Diags.isIgnored(diag::warn_arc_repeated_use_of_weak, MemberLoc))
1448  S.getCurFunction()->recordUseOfWeak(Result);
1449  }
1450 
1451  return Result;
1452  }
1453 
1454  // Objective-C property access.
1455  const ObjCObjectPointerType *OPT;
1456  if (!IsArrow && (OPT = BaseType->getAs<ObjCObjectPointerType>())) {
1457  if (!SS.isEmpty() && !SS.isInvalid()) {
1458  S.Diag(SS.getRange().getBegin(), diag::err_qualified_objc_access)
1459  << 0 << SS.getScopeRep() << FixItHint::CreateRemoval(SS.getRange());
1460  SS.clear();
1461  }
1462 
1463  // This actually uses the base as an r-value.
1464  BaseExpr = S.DefaultLvalueConversion(BaseExpr.get());
1465  if (BaseExpr.isInvalid())
1466  return ExprError();
1467 
1468  assert(S.Context.hasSameUnqualifiedType(BaseType,
1469  BaseExpr.get()->getType()));
1470 
1471  IdentifierInfo *Member = MemberName.getAsIdentifierInfo();
1472 
1473  const ObjCObjectType *OT = OPT->getObjectType();
1474 
1475  // id, with and without qualifiers.
1476  if (OT->isObjCId()) {
1477  // Check protocols on qualified interfaces.
1478  Selector Sel = S.PP.getSelectorTable().getNullarySelector(Member);
1479  if (Decl *PMDecl =
1480  FindGetterSetterNameDecl(OPT, Member, Sel, S.Context)) {
1481  if (ObjCPropertyDecl *PD = dyn_cast<ObjCPropertyDecl>(PMDecl)) {
1482  // Check the use of this declaration
1483  if (S.DiagnoseUseOfDecl(PD, MemberLoc))
1484  return ExprError();
1485 
1486  return new (S.Context)
1488  OK_ObjCProperty, MemberLoc, BaseExpr.get());
1489  }
1490 
1491  if (ObjCMethodDecl *OMD = dyn_cast<ObjCMethodDecl>(PMDecl)) {
1492  Selector SetterSel =
1494  S.PP.getSelectorTable(),
1495  Member);
1496  ObjCMethodDecl *SMD = nullptr;
1497  if (Decl *SDecl = FindGetterSetterNameDecl(OPT,
1498  /*Property id*/ nullptr,
1499  SetterSel, S.Context))
1500  SMD = dyn_cast<ObjCMethodDecl>(SDecl);
1501 
1502  return new (S.Context)
1504  OK_ObjCProperty, MemberLoc, BaseExpr.get());
1505  }
1506  }
1507  // Use of id.member can only be for a property reference. Do not
1508  // use the 'id' redefinition in this case.
1509  if (IsArrow && ShouldTryAgainWithRedefinitionType(S, BaseExpr))
1510  return LookupMemberExpr(S, R, BaseExpr, IsArrow, OpLoc, SS,
1511  ObjCImpDecl, HasTemplateArgs, TemplateKWLoc);
1512 
1513  return ExprError(S.Diag(MemberLoc, diag::err_property_not_found)
1514  << MemberName << BaseType);
1515  }
1516 
1517  // 'Class', unqualified only.
1518  if (OT->isObjCClass()) {
1519  // Only works in a method declaration (??!).
1520  ObjCMethodDecl *MD = S.getCurMethodDecl();
1521  if (!MD) {
1522  if (ShouldTryAgainWithRedefinitionType(S, BaseExpr))
1523  return LookupMemberExpr(S, R, BaseExpr, IsArrow, OpLoc, SS,
1524  ObjCImpDecl, HasTemplateArgs, TemplateKWLoc);
1525 
1526  goto fail;
1527  }
1528 
1529  // Also must look for a getter name which uses property syntax.
1530  Selector Sel = S.PP.getSelectorTable().getNullarySelector(Member);
1531  ObjCInterfaceDecl *IFace = MD->getClassInterface();
1532  if (!IFace)
1533  goto fail;
1534 
1535  ObjCMethodDecl *Getter;
1536  if ((Getter = IFace->lookupClassMethod(Sel))) {
1537  // Check the use of this method.
1538  if (S.DiagnoseUseOfDecl(Getter, MemberLoc))
1539  return ExprError();
1540  } else
1541  Getter = IFace->lookupPrivateMethod(Sel, false);
1542  // If we found a getter then this may be a valid dot-reference, we
1543  // will look for the matching setter, in case it is needed.
1544  Selector SetterSel =
1546  S.PP.getSelectorTable(),
1547  Member);
1548  ObjCMethodDecl *Setter = IFace->lookupClassMethod(SetterSel);
1549  if (!Setter) {
1550  // If this reference is in an @implementation, also check for 'private'
1551  // methods.
1552  Setter = IFace->lookupPrivateMethod(SetterSel, false);
1553  }
1554 
1555  if (Setter && S.DiagnoseUseOfDecl(Setter, MemberLoc))
1556  return ExprError();
1557 
1558  if (Getter || Setter) {
1559  return new (S.Context) ObjCPropertyRefExpr(
1560  Getter, Setter, S.Context.PseudoObjectTy, VK_LValue,
1561  OK_ObjCProperty, MemberLoc, BaseExpr.get());
1562  }
1563 
1564  if (ShouldTryAgainWithRedefinitionType(S, BaseExpr))
1565  return LookupMemberExpr(S, R, BaseExpr, IsArrow, OpLoc, SS,
1566  ObjCImpDecl, HasTemplateArgs, TemplateKWLoc);
1567 
1568  return ExprError(S.Diag(MemberLoc, diag::err_property_not_found)
1569  << MemberName << BaseType);
1570  }
1571 
1572  // Normal property access.
1573  return S.HandleExprPropertyRefExpr(OPT, BaseExpr.get(), OpLoc, MemberName,
1574  MemberLoc, SourceLocation(), QualType(),
1575  false);
1576  }
1577 
1578  // Handle 'field access' to vectors, such as 'V.xx'.
1579  if (BaseType->isExtVectorType()) {
1580  // FIXME: this expr should store IsArrow.
1581  IdentifierInfo *Member = MemberName.getAsIdentifierInfo();
1582  ExprValueKind VK;
1583  if (IsArrow)
1584  VK = VK_LValue;
1585  else {
1586  if (PseudoObjectExpr *POE = dyn_cast<PseudoObjectExpr>(BaseExpr.get()))
1587  VK = POE->getSyntacticForm()->getValueKind();
1588  else
1589  VK = BaseExpr.get()->getValueKind();
1590  }
1591 
1592  QualType ret = CheckExtVectorComponent(S, BaseType, VK, OpLoc,
1593  Member, MemberLoc);
1594  if (ret.isNull())
1595  return ExprError();
1596  Qualifiers BaseQ =
1597  S.Context.getCanonicalType(BaseExpr.get()->getType()).getQualifiers();
1598  ret = S.Context.getQualifiedType(ret, BaseQ);
1599 
1600  return new (S.Context)
1601  ExtVectorElementExpr(ret, VK, BaseExpr.get(), *Member, MemberLoc);
1602  }
1603 
1604  // Adjust builtin-sel to the appropriate redefinition type if that's
1605  // not just a pointer to builtin-sel again.
1606  if (IsArrow && BaseType->isSpecificBuiltinType(BuiltinType::ObjCSel) &&
1608  BaseExpr = S.ImpCastExprToType(
1609  BaseExpr.get(), S.Context.getObjCSelRedefinitionType(), CK_BitCast);
1610  return LookupMemberExpr(S, R, BaseExpr, IsArrow, OpLoc, SS,
1611  ObjCImpDecl, HasTemplateArgs, TemplateKWLoc);
1612  }
1613 
1614  // Failure cases.
1615  fail:
1616 
1617  // Recover from dot accesses to pointers, e.g.:
1618  // type *foo;
1619  // foo.bar
1620  // This is actually well-formed in two cases:
1621  // - 'type' is an Objective C type
1622  // - 'bar' is a pseudo-destructor name which happens to refer to
1623  // the appropriate pointer type
1624  if (const PointerType *Ptr = BaseType->getAs<PointerType>()) {
1625  if (!IsArrow && Ptr->getPointeeType()->isRecordType() &&
1626  MemberName.getNameKind() != DeclarationName::CXXDestructorName) {
1627  S.Diag(OpLoc, diag::err_typecheck_member_reference_suggestion)
1628  << BaseType << int(IsArrow) << BaseExpr.get()->getSourceRange()
1629  << FixItHint::CreateReplacement(OpLoc, "->");
1630 
1631  // Recurse as an -> access.
1632  IsArrow = true;
1633  return LookupMemberExpr(S, R, BaseExpr, IsArrow, OpLoc, SS,
1634  ObjCImpDecl, HasTemplateArgs, TemplateKWLoc);
1635  }
1636  }
1637 
1638  // If the user is trying to apply -> or . to a function name, it's probably
1639  // because they forgot parentheses to call that function.
1640  if (S.tryToRecoverWithCall(
1641  BaseExpr, S.PDiag(diag::err_member_reference_needs_call),
1642  /*complain*/ false,
1643  IsArrow ? &isPointerToRecordType : &isRecordType)) {
1644  if (BaseExpr.isInvalid())
1645  return ExprError();
1646  BaseExpr = S.DefaultFunctionArrayConversion(BaseExpr.get());
1647  return LookupMemberExpr(S, R, BaseExpr, IsArrow, OpLoc, SS,
1648  ObjCImpDecl, HasTemplateArgs, TemplateKWLoc);
1649  }
1650 
1651  S.Diag(OpLoc, diag::err_typecheck_member_reference_struct_union)
1652  << BaseType << BaseExpr.get()->getSourceRange() << MemberLoc;
1653 
1654  return ExprError();
1655 }
1656 
1657 /// The main callback when the parser finds something like
1658 /// expression . [nested-name-specifier] identifier
1659 /// expression -> [nested-name-specifier] identifier
1660 /// where 'identifier' encompasses a fairly broad spectrum of
1661 /// possibilities, including destructor and operator references.
1662 ///
1663 /// \param OpKind either tok::arrow or tok::period
1664 /// \param ObjCImpDecl the current Objective-C \@implementation
1665 /// decl; this is an ugly hack around the fact that Objective-C
1666 /// \@implementations aren't properly put in the context chain
1668  SourceLocation OpLoc,
1669  tok::TokenKind OpKind,
1670  CXXScopeSpec &SS,
1671  SourceLocation TemplateKWLoc,
1672  UnqualifiedId &Id,
1673  Decl *ObjCImpDecl) {
1674  if (SS.isSet() && SS.isInvalid())
1675  return ExprError();
1676 
1677  // Warn about the explicit constructor calls Microsoft extension.
1678  if (getLangOpts().MicrosoftExt &&
1680  Diag(Id.getSourceRange().getBegin(),
1681  diag::ext_ms_explicit_constructor_call);
1682 
1683  TemplateArgumentListInfo TemplateArgsBuffer;
1684 
1685  // Decompose the name into its component parts.
1686  DeclarationNameInfo NameInfo;
1687  const TemplateArgumentListInfo *TemplateArgs;
1688  DecomposeUnqualifiedId(Id, TemplateArgsBuffer,
1689  NameInfo, TemplateArgs);
1690 
1691  DeclarationName Name = NameInfo.getName();
1692  bool IsArrow = (OpKind == tok::arrow);
1693 
1694  NamedDecl *FirstQualifierInScope
1695  = (!SS.isSet() ? nullptr : FindFirstQualifierInScope(S, SS.getScopeRep()));
1696 
1697  // This is a postfix expression, so get rid of ParenListExprs.
1698  ExprResult Result = MaybeConvertParenListExprToParenExpr(S, Base);
1699  if (Result.isInvalid()) return ExprError();
1700  Base = Result.get();
1701 
1702  if (Base->getType()->isDependentType() || Name.isDependentName() ||
1703  isDependentScopeSpecifier(SS)) {
1704  return ActOnDependentMemberExpr(Base, Base->getType(), IsArrow, OpLoc, SS,
1705  TemplateKWLoc, FirstQualifierInScope,
1706  NameInfo, TemplateArgs);
1707  }
1708 
1709  ActOnMemberAccessExtraArgs ExtraArgs = {S, Id, ObjCImpDecl};
1710  ExprResult Res = BuildMemberReferenceExpr(
1711  Base, Base->getType(), OpLoc, IsArrow, SS, TemplateKWLoc,
1712  FirstQualifierInScope, NameInfo, TemplateArgs, S, &ExtraArgs);
1713 
1714  if (!Res.isInvalid() && isa<MemberExpr>(Res.get()))
1715  CheckMemberAccessOfNoDeref(cast<MemberExpr>(Res.get()));
1716 
1717  return Res;
1718 }
1719 
1720 void Sema::CheckMemberAccessOfNoDeref(const MemberExpr *E) {
1721  QualType ResultTy = E->getType();
1722 
1723  // Do not warn on member accesses to arrays since this returns an array
1724  // lvalue and does not actually dereference memory.
1725  if (isa<ArrayType>(ResultTy))
1726  return;
1727 
1728  if (E->isArrow()) {
1729  if (const auto *Ptr = dyn_cast<PointerType>(
1730  E->getBase()->getType().getDesugaredType(Context))) {
1731  if (Ptr->getPointeeType()->hasAttr(attr::NoDeref))
1732  ExprEvalContexts.back().PossibleDerefs.insert(E);
1733  }
1734  }
1735 }
1736 
1737 ExprResult
1738 Sema::BuildFieldReferenceExpr(Expr *BaseExpr, bool IsArrow,
1739  SourceLocation OpLoc, const CXXScopeSpec &SS,
1740  FieldDecl *Field, DeclAccessPair FoundDecl,
1741  const DeclarationNameInfo &MemberNameInfo) {
1742  // x.a is an l-value if 'a' has a reference type. Otherwise:
1743  // x.a is an l-value/x-value/pr-value if the base is (and note
1744  // that *x is always an l-value), except that if the base isn't
1745  // an ordinary object then we must have an rvalue.
1746  ExprValueKind VK = VK_LValue;
1748  if (!IsArrow) {
1749  if (BaseExpr->getObjectKind() == OK_Ordinary)
1750  VK = BaseExpr->getValueKind();
1751  else
1752  VK = VK_RValue;
1753  }
1754  if (VK != VK_RValue && Field->isBitField())
1755  OK = OK_BitField;
1756 
1757  // Figure out the type of the member; see C99 6.5.2.3p3, C++ [expr.ref]
1758  QualType MemberType = Field->getType();
1759  if (const ReferenceType *Ref = MemberType->getAs<ReferenceType>()) {
1760  MemberType = Ref->getPointeeType();
1761  VK = VK_LValue;
1762  } else {
1763  QualType BaseType = BaseExpr->getType();
1764  if (IsArrow) BaseType = BaseType->getAs<PointerType>()->getPointeeType();
1765 
1766  Qualifiers BaseQuals = BaseType.getQualifiers();
1767 
1768  // GC attributes are never picked up by members.
1769  BaseQuals.removeObjCGCAttr();
1770 
1771  // CVR attributes from the base are picked up by members,
1772  // except that 'mutable' members don't pick up 'const'.
1773  if (Field->isMutable()) BaseQuals.removeConst();
1774 
1775  Qualifiers MemberQuals =
1776  Context.getCanonicalType(MemberType).getQualifiers();
1777 
1778  assert(!MemberQuals.hasAddressSpace());
1779 
1780  Qualifiers Combined = BaseQuals + MemberQuals;
1781  if (Combined != MemberQuals)
1782  MemberType = Context.getQualifiedType(MemberType, Combined);
1783  }
1784 
1785  auto *CurMethod = dyn_cast<CXXMethodDecl>(CurContext);
1786  if (!(CurMethod && CurMethod->isDefaulted()))
1787  UnusedPrivateFields.remove(Field);
1788 
1789  ExprResult Base = PerformObjectMemberConversion(BaseExpr, SS.getScopeRep(),
1790  FoundDecl, Field);
1791  if (Base.isInvalid())
1792  return ExprError();
1793 
1794  // Build a reference to a private copy for non-static data members in
1795  // non-static member functions, privatized by OpenMP constructs.
1796  if (getLangOpts().OpenMP && IsArrow &&
1797  !CurContext->isDependentContext() &&
1798  isa<CXXThisExpr>(Base.get()->IgnoreParenImpCasts())) {
1799  if (auto *PrivateCopy = isOpenMPCapturedDecl(Field)) {
1800  return getOpenMPCapturedExpr(PrivateCopy, VK, OK,
1801  MemberNameInfo.getLoc());
1802  }
1803  }
1804 
1805  return BuildMemberExpr(*this, Context, Base.get(), IsArrow, OpLoc, SS,
1806  /*TemplateKWLoc=*/SourceLocation(), Field, FoundDecl,
1807  MemberNameInfo, MemberType, VK, OK);
1808 }
1809 
1810 /// Builds an implicit member access expression. The current context
1811 /// is known to be an instance method, and the given unqualified lookup
1812 /// set is known to contain only instance members, at least one of which
1813 /// is from an appropriate type.
1814 ExprResult
1816  SourceLocation TemplateKWLoc,
1817  LookupResult &R,
1818  const TemplateArgumentListInfo *TemplateArgs,
1819  bool IsKnownInstance, const Scope *S) {
1820  assert(!R.empty() && !R.isAmbiguous());
1821 
1822  SourceLocation loc = R.getNameLoc();
1823 
1824  // If this is known to be an instance access, go ahead and build an
1825  // implicit 'this' expression now.
1826  // 'this' expression now.
1827  QualType ThisTy = getCurrentThisType();
1828  assert(!ThisTy.isNull() && "didn't correctly pre-flight capture of 'this'");
1829 
1830  Expr *baseExpr = nullptr; // null signifies implicit access
1831  if (IsKnownInstance) {
1832  SourceLocation Loc = R.getNameLoc();
1833  if (SS.getRange().isValid())
1834  Loc = SS.getRange().getBegin();
1835  CheckCXXThisCapture(Loc);
1836  baseExpr = new (Context) CXXThisExpr(loc, ThisTy, /*isImplicit=*/true);
1837  }
1838 
1839  return BuildMemberReferenceExpr(baseExpr, ThisTy,
1840  /*OpLoc*/ SourceLocation(),
1841  /*IsArrow*/ true,
1842  SS, TemplateKWLoc,
1843  /*FirstQualifierInScope*/ nullptr,
1844  R, TemplateArgs, S);
1845 }
ObjCPropertyRefExpr - A dot-syntax expression to access an ObjC property.
Definition: ExprObjC.h:570
SourceLocation getLoc() const
getLoc - Returns the main location of the declaration name.
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
This is the scope of a C++ try statement.
Definition: Scope.h:101
static const Decl * getCanonicalDecl(const Decl *D)
static DiagnosticBuilder Diag(DiagnosticsEngine *Diags, const LangOptions &Features, FullSourceLoc TokLoc, const char *TokBegin, const char *TokRangeBegin, const char *TokRangeEnd, unsigned DiagID)
Produce a diagnostic highlighting some portion of a literal.
ExtVectorDeclsType ExtVectorDecls
ExtVectorDecls - This is a list all the extended vector types.
Definition: Sema.h:596
ExternalSemaSource * getExternalSource() const
Definition: Sema.h:1276
Smart pointer class that efficiently represents Objective-C method names.
SelectorTable & getSelectorTable()
Definition: Preprocessor.h:827
PointerType - C99 6.7.5.1 - Pointer Declarators.
Definition: Type.h:2542
QualType getPointeeType() const
Definition: Type.h:2555
A (possibly-)qualified type.
Definition: Type.h:634
Simple class containing the result of Sema::CorrectTypo.
ObjCInterfaceDecl * getClassInterface()
Definition: DeclObjC.cpp:1143
bool IvarBacksCurrentMethodAccessor(ObjCInterfaceDecl *IFace, ObjCMethodDecl *Method, ObjCIvarDecl *IV)
IvarBacksCurrentMethodAccessor - This routine returns &#39;true&#39; if &#39;IV&#39; is an ivar synthesized for &#39;Meth...
The reference may be to an instance member, but it might be invalid if so, because the context is not...
SourceRange getSourceRange() const LLVM_READONLY
Return the source range that covers this unqualified-id.
Definition: DeclSpec.h:1133
static MemberExpr * BuildMemberExpr(Sema &SemaRef, ASTContext &C, Expr *Base, bool isArrow, SourceLocation OpLoc, const CXXScopeSpec &SS, SourceLocation TemplateKWLoc, ValueDecl *Member, DeclAccessPair FoundDecl, const DeclarationNameInfo &MemberNameInfo, QualType Ty, ExprValueKind VK, ExprObjectKind OK, const TemplateArgumentListInfo *TemplateArgs=nullptr)
Build a MemberExpr AST node.
DeclContext * getFunctionLevelDeclContext()
Definition: Sema.cpp:1183
static void diagnoseInstanceReference(Sema &SemaRef, const CXXScopeSpec &SS, NamedDecl *Rep, const DeclarationNameInfo &nameInfo)
Diagnose a reference to a field with no object available.
QualType getDesugaredType(const ASTContext &Context) const
Return the specified type with any "sugar" removed from the type.
Definition: Type.h:934
VarDecl * getVarDecl() const
Definition: Decl.h:2859
void setLookupName(DeclarationName Name)
Sets the name to look up.
Definition: Lookup.h:248
QualType CXXThisTypeOverride
When non-NULL, the C++ &#39;this&#39; expression is allowed despite the current context not being a non-stati...
Definition: Sema.h:5180
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee...
Definition: Type.cpp:505
IMAKind
An instance of this object exists for each enum constant that is defined.
Definition: Decl.h:2785
static UnresolvedMemberExpr * Create(const ASTContext &Context, bool HasUnresolvedUsing, Expr *Base, QualType BaseType, bool IsArrow, SourceLocation OperatorLoc, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, const DeclarationNameInfo &MemberNameInfo, const TemplateArgumentListInfo *TemplateArgs, UnresolvedSetIterator Begin, UnresolvedSetIterator End)
Definition: ExprCXX.cpp:1441
bool isRecordType() const
Definition: Type.h:6374
Expr * getBase() const
Definition: Expr.h:2805
bool isEmpty() const
No scope specifier.
Definition: DeclSpec.h:188
QualType getQualifiedType(SplitQualType split) const
Un-split a SplitQualType.
Definition: ASTContext.h:1932
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
Emit a diagnostic.
Definition: Sema.h:1343
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:86
bool isExtVectorType() const
Definition: Type.h:6390
Defines the C++ template declaration subclasses.
The reference is definitely an implicit instance member access.
SourceLocation getBeginLoc() const
getBeginLoc - Retrieve the location of the first token.
Declaration of a variable template.
RedeclarationKind
Specifies whether (or how) name lookup is being performed for a redeclaration (vs.
Definition: Sema.h:3166
static bool IsInFnTryBlockHandler(const Scope *S)
Determine if the given scope is within a function-try-block handler.
LLVM_ATTRIBUTE_REINITIALIZES void clear()
Clears out any current state.
Definition: Lookup.h:554
const DeclAccessPair & getPair() const
Definition: UnresolvedSet.h:53
This file provides some common utility functions for processing Lambda related AST Constructs...
Represents a variable declaration or definition.
Definition: Decl.h:812
PartialDiagnostic PDiag(unsigned DiagID=0)
Build a partial diagnostic.
Definition: SemaInternal.h:24
DeclarationName getLookupName() const
Gets the name to look up.
Definition: Lookup.h:243
ObjCIsaExpr - Represent X->isa and X.isa when X is an ObjC &#39;id&#39; type.
Definition: ExprObjC.h:1437
DiagnosticsEngine & Diags
Definition: Sema.h:361
const T * getAs() const
Member-template getAs<specific type>&#39;.
Definition: Type.h:6761
DeclContext * computeDeclContext(QualType T)
Compute the DeclContext that is associated with the given type.
ObjCMethodDecl - Represents an instance or class method declaration.
Definition: DeclObjC.h:138
NamedDecl * getUnderlyingDecl()
Looks through UsingDecls and ObjCCompatibleAliasDecls for the underlying named decl.
Definition: Decl.h:431
bool isAmbiguous() const
Definition: Lookup.h:301
bool isInvalidDecl() const
Definition: DeclBase.h:544
QualType getObjCClassType() const
Represents the Objective-C Class type.
Definition: ASTContext.h:1870
void setBegin(SourceLocation b)
bool isStatic() const
Definition: DeclCXX.cpp:1882
protocol_range protocols() const
Definition: DeclObjC.h:2128
Defines the clang::Expr interface and subclasses for C++ expressions.
iterator begin(Source *source, bool LocalOnly=false)
The collection of all-type qualifiers we support.
Definition: Type.h:137
Qualifiers getQualifiers() const
Retrieve all qualifiers.
Represents a struct/union/class.
Definition: Decl.h:3592
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
Definition: Decl.h:297
bool Encloses(const DeclContext *DC) const
Determine whether this declaration context encloses the declaration context DC.
Definition: DeclBase.cpp:1150
One of these records is kept for each identifier that is lexed.
bool LookupTemplateName(LookupResult &R, Scope *S, CXXScopeSpec &SS, QualType ObjectType, bool EnteringContext, bool &MemberOfUnknownSpecialization, SourceLocation TemplateKWLoc=SourceLocation())
bool isStr(const char(&Str)[StrLen]) const
Return true if this is the identifier for the specified string.
Represents a class type in Objective C.
Definition: Type.h:5543
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:154
DeclarationName getCorrection() const
Gets the DeclarationName of the typo correction.
bool CheckQualifiedMemberReference(Expr *BaseExpr, QualType BaseType, const CXXScopeSpec &SS, const LookupResult &R)
static VarDecl * getVarTemplateSpecialization(Sema &S, VarTemplateDecl *VarTempl, const TemplateArgumentListInfo *TemplateArgs, const DeclarationNameInfo &MemberNameInfo, SourceLocation TemplateKWLoc)
ObjCMethodFamily
A family of Objective-C methods.
Base class for callback objects used by Sema::CorrectTypo to check the validity of a potential typo c...
Represents a member of a struct/union/class.
Definition: Decl.h:2578
The current expression is potentially evaluated at run time, which means that code may be generated t...
void removeConst()
Definition: Type.h:256
The reference may be to an unresolved using declaration and the context is not an instance method...
const DeclarationNameInfo & getLookupNameInfo() const
Gets the name info to look up.
Definition: Lookup.h:233
The iterator over UnresolvedSets.
Definition: UnresolvedSet.h:31
static bool ShouldTryAgainWithRedefinitionType(Sema &S, ExprResult &base)
Given that normal member access failed on the given expression, and given that the expression&#39;s type ...
int Category
Definition: Format.cpp:1631
bool isSpecificBuiltinType(unsigned K) const
Test for a particular builtin type.
Definition: Type.h:6520
bool Equals(const DeclContext *DC) const
Determine whether this declaration context is equivalent to the declaration context DC...
Definition: DeclBase.h:1875
Represents a C++ member access expression for which lookup produced a set of overloaded functions...
Definition: ExprCXX.h:3537
static int getPointAccessorIdx(char c)
Definition: Type.h:3299
bool isObjCSelType() const
Definition: Type.h:6439
ExtVectorElementExpr - This represents access to specific elements of a vector, and may occur on the ...
Definition: Expr.h:5320
ExprResult DefaultFunctionArrayConversion(Expr *E, bool Diagnose=true)
DefaultFunctionArrayConversion (C99 6.3.2.1p3, C99 6.3.2.1p4).
Definition: SemaExpr.cpp:451
An r-value expression (a pr-value in the C++11 taxonomy) produces a temporary value.
Definition: Specifiers.h:109
bool isDependentName() const
Determines whether the name itself is dependent, e.g., because it involves a C++ type that is itself ...
static Selector constructSetterSelector(IdentifierTable &Idents, SelectorTable &SelTable, const IdentifierInfo *Name)
Return the default setter selector for the given identifier.
Represents a C++ unqualified-id that has been parsed.
Definition: DeclSpec.h:933
bool isBitField() const
Determines whether this field is a bitfield.
Definition: Decl.h:2656
Selector getNullarySelector(IdentifierInfo *ID)
void resolveKind()
Resolves the result kind of the lookup, possibly hiding decls.
Definition: SemaLookup.cpp:472
Represents the results of name lookup.
Definition: Lookup.h:46
PtrTy get() const
Definition: Ownership.h:170
static DeclAccessPair make(NamedDecl *D, AccessSpecifier AS)
ObjCMethodDecl * getCurMethodDecl()
getCurMethodDecl - If inside of a method body, this returns a pointer to the method decl for the meth...
Definition: Sema.cpp:1208
A convenient class for passing around template argument information.
Definition: TemplateBase.h:554
static IMAKind ClassifyImplicitMemberAccess(Sema &SemaRef, const LookupResult &R)
The given lookup names class member(s) and is not being used for an address-of-member expression...
bool hasAddressSpace() const
Definition: Type.h:347
ExprValueKind getValueKind() const
getValueKind - The value kind that this expression produces.
Definition: Expr.h:407
ExprResult BuildAnonymousStructUnionMemberReference(const CXXScopeSpec &SS, SourceLocation nameLoc, IndirectFieldDecl *indirectField, DeclAccessPair FoundDecl=DeclAccessPair::make(nullptr, AS_none), Expr *baseObjectExpr=nullptr, SourceLocation opLoc=SourceLocation())
static bool isRecordType(QualType T)
TemplateSpecializationKind getTemplateSpecializationKind() const
If this variable is an instantiation of a variable template or a static data member of a class templa...
Definition: Decl.cpp:2433
The reference is a contextually-permitted abstract member reference.
CanQualType PseudoObjectTy
Definition: ASTContext.h:1046
bool isArrow() const
Definition: Expr.h:2912
QualType getObjCClassRedefinitionType() const
Retrieve the type that Class has been defined to, which may be different from the built-in Class if C...
Definition: ASTContext.h:1648
Expr * IgnoreParenCasts() LLVM_READONLY
Skip past any parentheses and casts which might surround this expression until reaching a fixed point...
Definition: Expr.cpp:2724
Scope - A scope is a transient data structure that is used while parsing the program.
Definition: Scope.h:40
CXXRecordDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Definition: DeclCXX.h:727
bool declaresSameEntity(const Decl *D1, const Decl *D2)
Determine whether two declarations declare the same entity.
Definition: DeclBase.h:1160
TypoExpr - Internal placeholder for expressions where typo correction still needs to be performed and...
Definition: Expr.h:5766
ObjCMethodDecl * lookupClassMethod(Selector Sel) const
Lookup a class method for a given selector.
Definition: DeclObjC.h:1851
ExprResult ActOnDependentMemberExpr(Expr *Base, QualType BaseType, bool IsArrow, SourceLocation OpLoc, const CXXScopeSpec &SS, SourceLocation TemplateKWLoc, NamedDecl *FirstQualifierInScope, const DeclarationNameInfo &NameInfo, const TemplateArgumentListInfo *TemplateArgs)
Represents a C++ nested-name-specifier or a global scope specifier.
Definition: DeclSpec.h:62
The current expression occurs within a discarded statement.
Represents an Objective-C protocol declaration.
Definition: DeclObjC.h:2063
Preprocessor & PP
Definition: Sema.h:358
const LangOptions & getLangOpts() const
Definition: Sema.h:1266
The reference may be an implicit instance member access.
An ordinary object is located at an address in memory.
Definition: Specifiers.h:125
bool isUnevaluatedContext() const
Determines whether we are currently in a context that is not evaluated as per C++ [expr] p5...
Definition: Sema.h:7629
Represents an ObjC class declaration.
Definition: DeclObjC.h:1171
ExprResult BuildMemberReferenceExpr(Expr *Base, QualType BaseType, SourceLocation OpLoc, bool IsArrow, CXXScopeSpec &SS, SourceLocation TemplateKWLoc, NamedDecl *FirstQualifierInScope, const DeclarationNameInfo &NameInfo, const TemplateArgumentListInfo *TemplateArgs, const Scope *S, ActOnMemberAccessExtraArgs *ExtraArgs=nullptr)
void addDecl(NamedDecl *D)
Add a declaration to these results with its natural access.
Definition: Lookup.h:426
Member name lookup, which finds the names of class/struct/union members.
Definition: Sema.h:3127
ObjCInterfaceDecl * getInterface() const
Gets the interface declaration for this object type, if the base type really is an interface...
Definition: Type.h:5778
The current context is "potentially evaluated" in C++11 terms, but the expression is evaluated at com...
NestedNameSpecifierLoc getWithLocInContext(ASTContext &Context) const
Retrieve a nested-name-specifier with location information, copied into the given AST context...
Definition: DeclSpec.cpp:142
unsigned getLength() const
Efficiently return the length of this identifier info.
Sema::RedeclarationKind redeclarationKind() const
Definition: Lookup.h:268
Expr * IgnoreImpCasts() LLVM_READONLY
Skip past any implicit casts which might surround this expression until reaching a fixed point...
Definition: Expr.cpp:2703
Represents the this expression in C++.
Definition: ExprCXX.h:975
llvm::SmallPtrSet< const CXXRecordDecl *, 4 > BaseSet
RAII class used to determine whether SFINAE has trapped any errors that occur during template argumen...
Definition: Sema.h:7638
unsigned getFlags() const
getFlags - Return the flags for this scope.
Definition: Scope.h:217
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:313
All possible referrents are instance members and the current context is not an instance method...
void recordUseOfWeak(const ExprT *E, bool IsRead=true)
Record that a weak object was accessed.
Definition: ScopeInfo.h:1000
SourceRange getRange() const
Definition: DeclSpec.h:67
QualType getUsageType(QualType objectType) const
Retrieve the type of this instance variable when viewed as a member of a specific object type...
Definition: DeclObjC.cpp:1813
std::string getAsString(const LangOptions &LO) const
An Objective-C property is a logical field of an Objective-C object which is read and written via Obj...
Definition: Specifiers.h:135
static bool LookupMemberExprInRecord(Sema &SemaRef, LookupResult &R, Expr *BaseExpr, const RecordType *RTy, SourceLocation OpLoc, bool IsArrow, CXXScopeSpec &SS, bool HasTemplateArgs, SourceLocation TemplateKWLoc, TypoExpr *&TE)
The current expression is potentially evaluated, but any declarations referenced inside that expressi...
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition: Decl.h:636
This represents one expression.
Definition: Expr.h:108
DeclResult CheckVarTemplateId(VarTemplateDecl *Template, SourceLocation TemplateLoc, SourceLocation TemplateNameLoc, const TemplateArgumentListInfo &TemplateArgs)
LookupNameKind
Describes the kind of name lookup to perform.
Definition: Sema.h:3115
ExprValueKind
The categorization of expression values, currently following the C++11 scheme.
Definition: Specifiers.h:106
static bool IsRGBA(char c)
Determine whether input char is from rgba component set.
int Id
Definition: ASTDiff.cpp:190
const T * castAs() const
Member-template castAs<specific type>.
Definition: Type.h:6824
std::string getAsString() const
Retrieve the human-readable string for this name.
Defines the clang::Preprocessor interface.
All possible referrents are instance members of an unrelated class.
DeclContext * getDeclContext()
Definition: DeclBase.h:429
static CXXDependentScopeMemberExpr * Create(const ASTContext &Ctx, Expr *Base, QualType BaseType, bool IsArrow, SourceLocation OperatorLoc, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, NamedDecl *FirstQualifierFoundInScope, DeclarationNameInfo MemberNameInfo, const TemplateArgumentListInfo *TemplateArgs)
Definition: ExprCXX.cpp:1349
Represents a C++ template name within the type system.
Definition: TemplateName.h:178
bool RequireCompleteType(SourceLocation Loc, QualType T, TypeDiagnoser &Diagnoser)
Ensure that the type T is a complete type.
Definition: SemaType.cpp:7659
UnqualifiedIdKind getKind() const
Determine what kind of name we have.
Definition: DeclSpec.h:1015
The current expression and its subexpressions occur within an unevaluated operand (C++11 [expr]p7)...
QualType getType() const
Definition: Expr.h:130
ObjCIvarDecl * lookupInstanceVariable(IdentifierInfo *IVarName, ObjCInterfaceDecl *&ClassDeclared)
Definition: DeclObjC.cpp:620
bool isSingleResult() const
Determines if this names a single result which is not an unresolved value using decl.
Definition: Lookup.h:308
DeclContext * getParent()
getParent - Returns the containing DeclContext.
Definition: DeclBase.h:1755
bool isInvalid() const
Definition: Ownership.h:166
SourceLocation getEnd() const
UnaryOperator - This represents the unary-expression&#39;s (except sizeof and alignof), the postinc/postdec operators from postfix-expression, and various extensions.
Definition: Expr.h:1929
static void DiagnoseQualifiedMemberReference(Sema &SemaRef, Expr *BaseExpr, QualType BaseType, const CXXScopeSpec &SS, NamedDecl *rep, const DeclarationNameInfo &nameInfo)
We know that the given qualified member reference points only to declarations which do not belong to ...
ExprResult BuildPossibleImplicitMemberExpr(const CXXScopeSpec &SS, SourceLocation TemplateKWLoc, LookupResult &R, const TemplateArgumentListInfo *TemplateArgs, const Scope *S)
Builds an expression which might be an implicit member expression.
A member reference to an MSPropertyDecl.
Definition: ExprCXX.h:758
bool isUsable() const
Definition: Ownership.h:167
This template specialization was implicitly instantiated from a template.
Definition: Specifiers.h:151
bool isObjCClass() const
Definition: Type.h:5612
bool isNull() const
Return true if this QualType doesn&#39;t point to a type yet.
Definition: Type.h:699
bool isProvablyNotDerivedFrom(const CXXRecordDecl *Base) const
Determine whether this class is provably not derived from the type Base.
ExprObjectKind getObjectKind() const
getObjectKind - The object kind that this expression produces.
Definition: Expr.h:414
bool isUnresolvableResult() const
Definition: Lookup.h:317
RecordDecl * getDecl() const
Definition: Type.h:4385
NestedNameSpecifier * getScopeRep() const
Retrieve the representation of the nested-name-specifier.
Definition: DeclSpec.h:75
chain_iterator chain_end() const
Definition: Decl.h:2850
QualType getObjCIdRedefinitionType() const
Retrieve the type that id has been defined to, which may be different from the built-in id if id has ...
Definition: ASTContext.h:1635
static bool isPointerToRecordType(QualType T)
ArrayRef< NamedDecl * >::const_iterator chain_iterator
Definition: Decl.h:2844
ActionResult - This structure is used while parsing/acting on expressions, stmts, etc...
Definition: Ownership.h:153
PseudoObjectExpr - An expression which accesses a pseudo-object l-value.
Definition: Expr.h:5503
static ExprResult BuildMSPropertyRefExpr(Sema &S, Expr *BaseExpr, bool IsArrow, const CXXScopeSpec &SS, MSPropertyDecl *PD, const DeclarationNameInfo &NameInfo)
bool isAccessorWithinNumElements(char c, bool isNumericAccessor) const
Definition: Type.h:3344
Encodes a location in the source.
QualType getObjCSelRedefinitionType() const
Retrieve the type that &#39;SEL&#39; has been defined to, which may be different from the built-in &#39;SEL&#39; if &#39;...
Definition: ASTContext.h:1661
DeclarationName getName() const
getName - Returns the embedded declaration name.
QualType getElementType() const
Definition: Type.h:3208
IdentifierTable & getIdentifierTable()
Definition: Preprocessor.h:825
bool isOverloadedResult() const
Determines if the results are overloaded.
Definition: Lookup.h:313
ExprObjectKind
A further classification of the kind of object referenced by an l-value or x-value.
Definition: Specifiers.h:123
Represents a static or instance method of a struct/union/class.
Definition: DeclCXX.h:2048
QualType getExtVectorType(QualType VectorType, unsigned NumElts) const
Return the unique reference to an extended vector type of the specified element type and size...
ExprResult DefaultLvalueConversion(Expr *E)
Definition: SemaExpr.cpp:565
The reference may be to an unresolved using declaration.
const char * getNameStart() const
Return the beginning of the actual null-terminated string for this identifier.
TokenKind
Provides a simple uniform namespace for tokens from all C languages.
Definition: TokenKinds.h:24
bool forallBases(ForallBasesCallback BaseMatches, bool AllowShortCircuit=true) const
Determines if the given callback holds for all the direct or indirect base classes of this type...
Represents one property declaration in an Objective-C interface.
Definition: DeclObjC.h:728
bool DiagnoseUseOfDecl(NamedDecl *D, ArrayRef< SourceLocation > Locs, const ObjCInterfaceDecl *UnknownObjCClass=nullptr, bool ObjCPropertyAccess=false, bool AvoidPartialAvailabilityChecks=false, ObjCInterfaceDecl *ClassReciever=nullptr)
Determine whether the use of this declaration is valid, and emit any corresponding diagnostics...
Definition: SemaExpr.cpp:211
static Decl * FindGetterSetterNameDecl(const ObjCObjectPointerType *QIdTy, IdentifierInfo *Member, const Selector &Sel, ASTContext &Context)
bool isSuperClassOf(const ObjCInterfaceDecl *I) const
isSuperClassOf - Return true if this class is the specified class or is a super class of the specifie...
Definition: DeclObjC.h:1809
bool isThisOutsideMemberFunctionBody(QualType BaseType)
Determine whether the given type is the type of *this that is used outside of the body of a member fu...
void removeObjCGCAttr()
Definition: Type.h:305
bool RequireCompleteDeclContext(CXXScopeSpec &SS, DeclContext *DC)
Require that the context specified by SS be complete.
bool isInvalid() const
An error occurred during parsing of the scope specifier.
Definition: DeclSpec.h:193
bool hasSameUnqualifiedType(QualType T1, QualType T2) const
Determine whether the given types are equivalent after cvr-qualifiers have been removed.
Definition: ASTContext.h:2306
static MemberExpr * Create(const ASTContext &C, Expr *base, bool isarrow, SourceLocation OperatorLoc, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, ValueDecl *memberdecl, DeclAccessPair founddecl, DeclarationNameInfo MemberNameInfo, const TemplateArgumentListInfo *targs, QualType ty, ExprValueKind VK, ExprObjectKind OK)
Definition: Expr.cpp:1538
Sema & getSema() const
Get the Sema object that this lookup result is searching with.
Definition: Lookup.h:612
A POD class for pairing a NamedDecl* with an access specifier.
void setTemplateSpecializationKind(TemplateSpecializationKind TSK, SourceLocation PointOfInstantiation=SourceLocation())
For a static data member that was instantiated from a static data member of a class template...
Definition: Decl.cpp:2494
void diagnoseTypo(const TypoCorrection &Correction, const PartialDiagnostic &TypoDiag, bool ErrorRecovery=true)
QualType getTypedefType(const TypedefNameDecl *Decl, QualType Canon=QualType()) const
Return the unique reference to the type for the specified typedef-name decl.
void MarkMemberReferenced(MemberExpr *E)
Perform reference-marking and odr-use handling for a MemberExpr.
Definition: SemaExpr.cpp:15849
bool isObjCId() const
Definition: Type.h:5608
Dataflow Directional Tag Classes.
bool isValid() const
Return true if this is a valid SourceLocation object.
ObjCMethodDecl * lookupPrivateMethod(const Selector &Sel, bool Instance=true) const
Lookup a method in the classes implementation hierarchy.
Definition: DeclObjC.cpp:739
ObjCPropertyDecl * FindPropertyDeclaration(const IdentifierInfo *PropertyId, ObjCPropertyQueryKind QueryKind) const
FindPropertyDeclaration - Finds declaration of the property given its name in &#39;PropertyId&#39; and return...
Definition: DeclObjC.cpp:235
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1265
const Scope * getParent() const
getParent - Return the scope that this is nested in.
Definition: Scope.h:225
ExprResult ImpCastExprToType(Expr *E, QualType Type, CastKind CK, ExprValueKind VK=VK_RValue, const CXXCastPath *BasePath=nullptr, CheckedConversionKind CCK=CCK_ImplicitConversion)
ImpCastExprToType - If Expr is not of type &#39;Type&#39;, insert an implicit cast.
Definition: Sema.cpp:474
bool isRecord() const
Definition: DeclBase.h:1830
The current expression occurs within an unevaluated operand that unconditionally permits abstract ref...
Represents a field injected from an anonymous union/struct into the parent scope. ...
Definition: Decl.h:2824
static FixItHint CreateRemoval(CharSourceRange RemoveRange)
Create a code modification hint that removes the given source range.
Definition: Diagnostic.h:117
AccessSpecifier getAccess() const
Definition: DeclBase.h:464
static ExprResult LookupMemberExpr(Sema &S, LookupResult &R, ExprResult &BaseExpr, bool &IsArrow, SourceLocation OpLoc, CXXScopeSpec &SS, Decl *ObjCImpDecl, bool HasTemplateArgs, SourceLocation TemplateKWLoc)
Look up the given member of the given non-type-dependent expression.
NamedDecl * getCorrectionDecl() const
Gets the pointer to the declaration of the typo correction.
The name of a declaration.
NamedDecl * getFoundDecl() const
Fetch the unique decl found by this lookup.
Definition: Lookup.h:517
const CXXRecordDecl * getParent() const
Returns the parent of this method declaration, which is the class in which this method is defined...
Definition: DeclCXX.h:2173
bool tryToRecoverWithCall(ExprResult &E, const PartialDiagnostic &PD, bool ForceComplain=false, bool(*IsPlausibleResult)(QualType)=nullptr)
Try to recover by turning the given expression into a call.
Definition: Sema.cpp:1988
const ObjCObjectType * getObjectType() const
Gets the type pointed to by this ObjC pointer.
Definition: Type.h:5840
ExprResult ActOnMemberAccessExpr(Scope *S, Expr *Base, SourceLocation OpLoc, tok::TokenKind OpKind, CXXScopeSpec &SS, SourceLocation TemplateKWLoc, UnqualifiedId &Member, Decl *ObjCImpDecl)
The main callback when the parser finds something like expression .
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspnd...
Expr * IgnoreParenImpCasts() LLVM_READONLY
Skip past any parentheses and implicit casts which might surround this expression until reaching a fi...
Definition: Expr.cpp:2719
ExprResult BuildImplicitMemberExpr(const CXXScopeSpec &SS, SourceLocation TemplateKWLoc, LookupResult &R, const TemplateArgumentListInfo *TemplateArgs, bool IsDefiniteInstance, const Scope *S)
Builds an implicit member access expression.
Represents a pointer to an Objective C object.
Definition: Type.h:5799
ObjCImplementationDecl - Represents a class definition - this is where method definitions are specifi...
Definition: DeclObjC.h:2551
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
Definition: Type.h:4375
This is the scope for a function-level C++ try or catch scope.
Definition: Scope.h:104
SourceRange getSourceRange() const LLVM_READONLY
getSourceRange - The range of the declaration name.
chain_iterator chain_begin() const
Definition: Decl.h:2849
FunctionDecl * getCurFunctionDecl()
getCurFunctionDecl - If inside of a function body, this returns a pointer to the function decl for th...
Definition: Sema.cpp:1203
bool isFunctionType() const
Definition: Type.h:6297
ExprResult HandleExprPropertyRefExpr(const ObjCObjectPointerType *OPT, Expr *BaseExpr, SourceLocation OpLoc, DeclarationName MemberName, SourceLocation MemberLoc, SourceLocation SuperLoc, QualType SuperType, bool Super)
HandleExprPropertyRefExpr - Handle foo.bar where foo is a pointer to an objective C interface...
ExtVectorType - Extended vector type.
Definition: Type.h:3292
Base for LValueReferenceType and RValueReferenceType.
Definition: Type.h:2678
CanQualType BoundMemberTy
Definition: ASTContext.h:1044
SmallVector< ExpressionEvaluationContextRecord, 8 > ExprEvalContexts
A stack of expression evaluation contexts.
Definition: Sema.h:1076
ExprResult BuildFieldReferenceExpr(Expr *BaseExpr, bool IsArrow, SourceLocation OpLoc, const CXXScopeSpec &SS, FieldDecl *Field, DeclAccessPair FoundDecl, const DeclarationNameInfo &MemberNameInfo)
qual_range quals() const
Definition: Type.h:5922
Sema::LookupNameKind getLookupKind() const
Gets the kind of lookup to perform.
Definition: Lookup.h:253
A bitfield object is a bitfield on a C or C++ record.
Definition: Specifiers.h:128
ObjCIvarRefExpr - A reference to an ObjC instance variable.
Definition: ExprObjC.h:506
bool LookupQualifiedName(LookupResult &R, DeclContext *LookupCtx, bool InUnqualifiedLookup=false)
Perform qualified name lookup into a given context.
CanQualType getCanonicalType(QualType T) const
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
Definition: ASTContext.h:2266
bool isSet() const
Deprecated.
Definition: DeclSpec.h:208
The reference may be to an instance member, but it is invalid if so, because the context is from an u...
ExprResult PerformMemberExprBaseConversion(Expr *Base, bool IsArrow)
Perform conversions on the LHS of a member access expression.
Reading or writing from this object requires a barrier call.
Definition: Type.h:168
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate.h) and friends (in DeclFriend.h).
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
Definition: Expr.h:2720
ActionResult< Expr * > ExprResult
Definition: Ownership.h:263
bool isMutable() const
Determines whether this field is mutable (C++ only).
Definition: Decl.h:2653
Represents a C++ struct/union/class.
Definition: DeclCXX.h:299
bool isValid() const
sema::FunctionScopeInfo * getCurFunction() const
Definition: Sema.h:1393
Qualifiers getQualifiers() const
Retrieve the set of qualifiers applied to this type.
Definition: Type.h:6104
ObjCIvarDecl - Represents an ObjC instance variable.
Definition: DeclObjC.h:1944
bool isRValue() const
Definition: Expr.h:252
static bool IsValidOpenCLComponentSwizzleLength(unsigned len)
TypoExpr * CorrectTypoDelayed(const DeclarationNameInfo &Typo, Sema::LookupNameKind LookupKind, Scope *S, CXXScopeSpec *SS, std::unique_ptr< CorrectionCandidateCallback > CCC, TypoDiagnosticGenerator TDG, TypoRecoveryCallback TRC, CorrectTypoKind Mode, DeclContext *MemberContext=nullptr, bool EnteringContext=false, const ObjCObjectPointerType *OPT=nullptr)
Try to "correct" a typo in the source code by finding visible declarations whose names are similar to...
static FixItHint CreateReplacement(CharSourceRange RemoveRange, StringRef Code)
Create a code modification hint that replaces the given source range with the given code string...
Definition: Diagnostic.h:128
iterator end() const
Definition: Lookup.h:336
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
Definition: Stmt.cpp:251
ExprResult ExprError()
Definition: Ownership.h:279
unsigned getNumElements() const
Definition: Type.h:3209
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
Definition: Type.h:2081
A reference to a declared variable, function, enum, etc.
Definition: Expr.h:1074
const Scope * getFnParent() const
getFnParent - Return the closest scope that is a function body.
Definition: Scope.h:229
bool isIgnored(unsigned DiagID, SourceLocation Loc) const
Determine whether the diagnostic is known to be ignored.
Definition: Diagnostic.h:818
bool isPointerType() const
Definition: Type.h:6301
void setBaseObjectType(QualType T)
Sets the base object type for this lookup.
Definition: Lookup.h:420
The reference is definitely not an instance member access.
void suppressDiagnostics()
Suppress the diagnostics that would normally fire because of this lookup.
Definition: Lookup.h:583
An instance of this class represents the declaration of a property member.
Definition: DeclCXX.h:3919
void diagnoseMissingTemplateArguments(TemplateName Name, SourceLocation Loc)
QualType getType() const
Definition: Decl.h:647
An l-value expression is a reference to an object with independent storage.
Definition: Specifiers.h:113
bool empty() const
Return true if no decls were found.
Definition: Lookup.h:339
static Decl * FindGetterSetterNameDeclFromProtocolList(const ObjCProtocolDecl *PDecl, IdentifierInfo *Member, const Selector &Sel, ASTContext &Context)
static int getNumericAccessorIdx(char c)
Definition: Type.h:3309
A trivial tuple used to represent a source range.
ASTContext & Context
Definition: Sema.h:359
TypoCorrection CorrectTypo(const DeclarationNameInfo &Typo, Sema::LookupNameKind LookupKind, Scope *S, CXXScopeSpec *SS, std::unique_ptr< CorrectionCandidateCallback > CCC, CorrectTypoKind Mode, DeclContext *MemberContext=nullptr, bool EnteringContext=false, const ObjCObjectPointerType *OPT=nullptr, bool RecordFailure=true)
Try to "correct" a typo in the source code by finding visible declarations whose names are similar to...
This represents a decl that may have a name.
Definition: Decl.h:248
ObjCMethodDecl * getInstanceMethod(Selector Sel, bool AllowHidden=false) const
Definition: DeclObjC.h:1086
AccessControl getAccessControl() const
Definition: DeclObjC.h:1983
iterator begin() const
Definition: Lookup.h:335
SourceLocation getNameLoc() const
Gets the location of the identifier.
Definition: Lookup.h:606
static QualType CheckExtVectorComponent(Sema &S, QualType baseType, ExprValueKind &VK, SourceLocation OpLoc, const IdentifierInfo *CompName, SourceLocation CompLoc)
Check an ext-vector component access expression.
NamedDecl * getRepresentativeDecl() const
Fetches a representative decl. Useful for lazy diagnostics.
Definition: Lookup.h:524
SourceLocation getBegin() const
void WillReplaceSpecifier(bool ForceReplacement)
ObjCCategoryImplDecl - An object of this class encapsulates a category @implementation declaration...
Definition: DeclObjC.h:2498
The current expression occurs within a braced-init-list within an unevaluated operand.
SourceLocation getLocation() const
Definition: DeclBase.h:420
static bool isProvablyNotDerivedFrom(Sema &SemaRef, CXXRecordDecl *Record, const BaseSet &Bases)
Determines if the given class is provably not derived from all of the prospective base classes...
bool isCXXInstanceMember() const
Determine whether the given declaration is an instance member of a C++ class.
Definition: Decl.cpp:1737
bool hasErrorOccurred() const
Determine whether any SFINAE errors have been trapped.
Definition: Sema.h:7669
Qualifiers::ObjCLifetime getObjCLifetime() const
Returns lifetime attribute of this type.
Definition: Type.h:1054
bool isTransparentContext() const
isTransparentContext - Determines whether this context is a "transparent" context, meaning that the members declared in this context are semantically declared in the nearest enclosing non-transparent (opaque) context but are lexically declared in this context.
Definition: DeclBase.cpp:1112