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