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