clang  6.0.0svn
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  // OpenCL mode requires swizzle length to be in accordance with accepted
388  // sizes. Clang however supports arbitrary lengths for other languages.
389  if (S.getLangOpts().OpenCL && !HalvingSwizzle) {
390  unsigned SwizzleLength = CompName->getLength();
391 
392  if (HexSwizzle)
393  SwizzleLength--;
394 
395  if (IsValidOpenCLComponentSwizzleLength(SwizzleLength) == false) {
396  S.Diag(OpLoc, diag::err_opencl_ext_vector_component_invalid_length)
397  << SwizzleLength << SourceRange(CompLoc);
398  return QualType();
399  }
400  }
401 
402  // The component accessor looks fine - now we need to compute the actual type.
403  // The vector type is implied by the component accessor. For example,
404  // vec4.b is a float, vec4.xy is a vec2, vec4.rgb is a vec3, etc.
405  // vec4.s0 is a float, vec4.s23 is a vec3, etc.
406  // vec4.hi, vec4.lo, vec4.e, and vec4.o all return vec2.
407  unsigned CompSize = HalvingSwizzle ? (vecType->getNumElements() + 1) / 2
408  : CompName->getLength();
409  if (HexSwizzle)
410  CompSize--;
411 
412  if (CompSize == 1)
413  return vecType->getElementType();
414 
415  if (HasRepeated) VK = VK_RValue;
416 
417  QualType VT = S.Context.getExtVectorType(vecType->getElementType(), CompSize);
418  // Now look up the TypeDefDecl from the vector type. Without this,
419  // diagostics look bad. We want extended vector types to appear built-in.
420  for (Sema::ExtVectorDeclsType::iterator
422  E = S.ExtVectorDecls.end();
423  I != E; ++I) {
424  if ((*I)->getUnderlyingType() == VT)
425  return S.Context.getTypedefType(*I);
426  }
427 
428  return VT; // should never get here (a typedef type should always be found).
429 }
430 
432  IdentifierInfo *Member,
433  const Selector &Sel,
434  ASTContext &Context) {
435  if (Member)
436  if (ObjCPropertyDecl *PD = PDecl->FindPropertyDeclaration(
438  return PD;
439  if (ObjCMethodDecl *OMD = PDecl->getInstanceMethod(Sel))
440  return OMD;
441 
442  for (const auto *I : PDecl->protocols()) {
443  if (Decl *D = FindGetterSetterNameDeclFromProtocolList(I, Member, Sel,
444  Context))
445  return D;
446  }
447  return nullptr;
448 }
449 
451  IdentifierInfo *Member,
452  const Selector &Sel,
453  ASTContext &Context) {
454  // Check protocols on qualified interfaces.
455  Decl *GDecl = nullptr;
456  for (const auto *I : QIdTy->quals()) {
457  if (Member)
458  if (ObjCPropertyDecl *PD = I->FindPropertyDeclaration(
460  GDecl = PD;
461  break;
462  }
463  // Also must look for a getter or setter name which uses property syntax.
464  if (ObjCMethodDecl *OMD = I->getInstanceMethod(Sel)) {
465  GDecl = OMD;
466  break;
467  }
468  }
469  if (!GDecl) {
470  for (const auto *I : QIdTy->quals()) {
471  // Search in the protocol-qualifier list of current protocol.
472  GDecl = FindGetterSetterNameDeclFromProtocolList(I, Member, Sel, Context);
473  if (GDecl)
474  return GDecl;
475  }
476  }
477  return GDecl;
478 }
479 
482  bool IsArrow, SourceLocation OpLoc,
483  const CXXScopeSpec &SS,
484  SourceLocation TemplateKWLoc,
485  NamedDecl *FirstQualifierInScope,
486  const DeclarationNameInfo &NameInfo,
487  const TemplateArgumentListInfo *TemplateArgs) {
488  // Even in dependent contexts, try to diagnose base expressions with
489  // obviously wrong types, e.g.:
490  //
491  // T* t;
492  // t.f;
493  //
494  // In Obj-C++, however, the above expression is valid, since it could be
495  // accessing the 'f' property if T is an Obj-C interface. The extra check
496  // allows this, while still reporting an error if T is a struct pointer.
497  if (!IsArrow) {
498  const PointerType *PT = BaseType->getAs<PointerType>();
499  if (PT && (!getLangOpts().ObjC1 ||
500  PT->getPointeeType()->isRecordType())) {
501  assert(BaseExpr && "cannot happen with implicit member accesses");
502  Diag(OpLoc, diag::err_typecheck_member_reference_struct_union)
503  << BaseType << BaseExpr->getSourceRange() << NameInfo.getSourceRange();
504  return ExprError();
505  }
506  }
507 
508  assert(BaseType->isDependentType() ||
509  NameInfo.getName().isDependentName() ||
510  isDependentScopeSpecifier(SS));
511 
512  // Get the type being accessed in BaseType. If this is an arrow, the BaseExpr
513  // must have pointer type, and the accessed type is the pointee.
515  Context, BaseExpr, BaseType, IsArrow, OpLoc,
516  SS.getWithLocInContext(Context), TemplateKWLoc, FirstQualifierInScope,
517  NameInfo, TemplateArgs);
518 }
519 
520 /// We know that the given qualified member reference points only to
521 /// declarations which do not belong to the static type of the base
522 /// expression. Diagnose the problem.
524  Expr *BaseExpr,
525  QualType BaseType,
526  const CXXScopeSpec &SS,
527  NamedDecl *rep,
528  const DeclarationNameInfo &nameInfo) {
529  // If this is an implicit member access, use a different set of
530  // diagnostics.
531  if (!BaseExpr)
532  return diagnoseInstanceReference(SemaRef, SS, rep, nameInfo);
533 
534  SemaRef.Diag(nameInfo.getLoc(), diag::err_qualified_member_of_unrelated)
535  << SS.getRange() << rep << BaseType;
536 }
537 
538 // Check whether the declarations we found through a nested-name
539 // specifier in a member expression are actually members of the base
540 // type. The restriction here is:
541 //
542 // C++ [expr.ref]p2:
543 // ... In these cases, the id-expression shall name a
544 // member of the class or of one of its base classes.
545 //
546 // So it's perfectly legitimate for the nested-name specifier to name
547 // an unrelated class, and for us to find an overload set including
548 // decls from classes which are not superclasses, as long as the decl
549 // we actually pick through overload resolution is from a superclass.
551  QualType BaseType,
552  const CXXScopeSpec &SS,
553  const LookupResult &R) {
554  CXXRecordDecl *BaseRecord =
555  cast_or_null<CXXRecordDecl>(computeDeclContext(BaseType));
556  if (!BaseRecord) {
557  // We can't check this yet because the base type is still
558  // dependent.
559  assert(BaseType->isDependentType());
560  return false;
561  }
562 
563  for (LookupResult::iterator I = R.begin(), E = R.end(); I != E; ++I) {
564  // If this is an implicit member reference and we find a
565  // non-instance member, it's not an error.
566  if (!BaseExpr && !(*I)->isCXXInstanceMember())
567  return false;
568 
569  // Note that we use the DC of the decl, not the underlying decl.
570  DeclContext *DC = (*I)->getDeclContext();
571  while (DC->isTransparentContext())
572  DC = DC->getParent();
573 
574  if (!DC->isRecord())
575  continue;
576 
577  CXXRecordDecl *MemberRecord = cast<CXXRecordDecl>(DC)->getCanonicalDecl();
578  if (BaseRecord->getCanonicalDecl() == MemberRecord ||
579  !BaseRecord->isProvablyNotDerivedFrom(MemberRecord))
580  return false;
581  }
582 
583  DiagnoseQualifiedMemberReference(*this, BaseExpr, BaseType, SS,
585  R.getLookupNameInfo());
586  return true;
587 }
588 
589 namespace {
590 
591 // Callback to only accept typo corrections that are either a ValueDecl or a
592 // FunctionTemplateDecl and are declared in the current record or, for a C++
593 // classes, one of its base classes.
594 class RecordMemberExprValidatorCCC : public CorrectionCandidateCallback {
595 public:
596  explicit RecordMemberExprValidatorCCC(const RecordType *RTy)
597  : Record(RTy->getDecl()) {
598  // Don't add bare keywords to the consumer since they will always fail
599  // validation by virtue of not being associated with any decls.
600  WantTypeSpecifiers = false;
601  WantExpressionKeywords = false;
602  WantCXXNamedCasts = false;
603  WantFunctionLikeCasts = false;
604  WantRemainingKeywords = false;
605  }
606 
607  bool ValidateCandidate(const TypoCorrection &candidate) override {
608  NamedDecl *ND = candidate.getCorrectionDecl();
609  // Don't accept candidates that cannot be member functions, constants,
610  // variables, or templates.
611  if (!ND || !(isa<ValueDecl>(ND) || isa<FunctionTemplateDecl>(ND)))
612  return false;
613 
614  // Accept candidates that occur in the current record.
615  if (Record->containsDecl(ND))
616  return true;
617 
618  if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(Record)) {
619  // Accept candidates that occur in any of the current class' base classes.
620  for (const auto &BS : RD->bases()) {
621  if (const RecordType *BSTy =
622  dyn_cast_or_null<RecordType>(BS.getType().getTypePtrOrNull())) {
623  if (BSTy->getDecl()->containsDecl(ND))
624  return true;
625  }
626  }
627  }
628 
629  return false;
630  }
631 
632 private:
633  const RecordDecl *const Record;
634 };
635 
636 }
637 
638 static bool LookupMemberExprInRecord(Sema &SemaRef, LookupResult &R,
639  Expr *BaseExpr,
640  const RecordType *RTy,
641  SourceLocation OpLoc, bool IsArrow,
642  CXXScopeSpec &SS, bool HasTemplateArgs,
643  TypoExpr *&TE) {
644  SourceRange BaseRange = BaseExpr ? BaseExpr->getSourceRange() : SourceRange();
645  RecordDecl *RDecl = RTy->getDecl();
646  if (!SemaRef.isThisOutsideMemberFunctionBody(QualType(RTy, 0)) &&
647  SemaRef.RequireCompleteType(OpLoc, QualType(RTy, 0),
648  diag::err_typecheck_incomplete_tag,
649  BaseRange))
650  return true;
651 
652  if (HasTemplateArgs) {
653  // LookupTemplateName doesn't expect these both to exist simultaneously.
654  QualType ObjectType = SS.isSet() ? QualType() : QualType(RTy, 0);
655 
656  bool MOUS;
657  SemaRef.LookupTemplateName(R, nullptr, SS, ObjectType, false, MOUS);
658  return false;
659  }
660 
661  DeclContext *DC = RDecl;
662  if (SS.isSet()) {
663  // If the member name was a qualified-id, look into the
664  // nested-name-specifier.
665  DC = SemaRef.computeDeclContext(SS, false);
666 
667  if (SemaRef.RequireCompleteDeclContext(SS, DC)) {
668  SemaRef.Diag(SS.getRange().getEnd(), diag::err_typecheck_incomplete_tag)
669  << SS.getRange() << DC;
670  return true;
671  }
672 
673  assert(DC && "Cannot handle non-computable dependent contexts in lookup");
674 
675  if (!isa<TypeDecl>(DC)) {
676  SemaRef.Diag(R.getNameLoc(), diag::err_qualified_member_nonclass)
677  << DC << SS.getRange();
678  return true;
679  }
680  }
681 
682  // The record definition is complete, now look up the member.
683  SemaRef.LookupQualifiedName(R, DC, SS);
684 
685  if (!R.empty())
686  return false;
687 
688  DeclarationName Typo = R.getLookupName();
689  SourceLocation TypoLoc = R.getNameLoc();
690 
691  struct QueryState {
692  Sema &SemaRef;
693  DeclarationNameInfo NameInfo;
694  Sema::LookupNameKind LookupKind;
696  };
697  QueryState Q = {R.getSema(), R.getLookupNameInfo(), R.getLookupKind(),
698  R.redeclarationKind()};
699  TE = SemaRef.CorrectTypoDelayed(
700  R.getLookupNameInfo(), R.getLookupKind(), nullptr, &SS,
701  llvm::make_unique<RecordMemberExprValidatorCCC>(RTy),
702  [=, &SemaRef](const TypoCorrection &TC) {
703  if (TC) {
704  assert(!TC.isKeyword() &&
705  "Got a keyword as a correction for a member!");
706  bool DroppedSpecifier =
707  TC.WillReplaceSpecifier() &&
708  Typo.getAsString() == TC.getAsString(SemaRef.getLangOpts());
709  SemaRef.diagnoseTypo(TC, SemaRef.PDiag(diag::err_no_member_suggest)
710  << Typo << DC << DroppedSpecifier
711  << SS.getRange());
712  } else {
713  SemaRef.Diag(TypoLoc, diag::err_no_member) << Typo << DC << BaseRange;
714  }
715  },
716  [=](Sema &SemaRef, TypoExpr *TE, TypoCorrection TC) mutable {
717  LookupResult R(Q.SemaRef, Q.NameInfo, Q.LookupKind, Q.Redecl);
718  R.clear(); // Ensure there's no decls lingering in the shared state.
721  for (NamedDecl *ND : TC)
722  R.addDecl(ND);
723  R.resolveKind();
724  return SemaRef.BuildMemberReferenceExpr(
725  BaseExpr, BaseExpr->getType(), OpLoc, IsArrow, SS, SourceLocation(),
726  nullptr, R, nullptr, nullptr);
727  },
729 
730  return false;
731 }
732 
734  ExprResult &BaseExpr, bool &IsArrow,
735  SourceLocation OpLoc, CXXScopeSpec &SS,
736  Decl *ObjCImpDecl, bool HasTemplateArgs);
737 
740  SourceLocation OpLoc, bool IsArrow,
741  CXXScopeSpec &SS,
742  SourceLocation TemplateKWLoc,
743  NamedDecl *FirstQualifierInScope,
744  const DeclarationNameInfo &NameInfo,
745  const TemplateArgumentListInfo *TemplateArgs,
746  const Scope *S,
747  ActOnMemberAccessExtraArgs *ExtraArgs) {
748  if (BaseType->isDependentType() ||
749  (SS.isSet() && isDependentScopeSpecifier(SS)))
750  return ActOnDependentMemberExpr(Base, BaseType,
751  IsArrow, OpLoc,
752  SS, TemplateKWLoc, FirstQualifierInScope,
753  NameInfo, TemplateArgs);
754 
755  LookupResult R(*this, NameInfo, LookupMemberName);
756 
757  // Implicit member accesses.
758  if (!Base) {
759  TypoExpr *TE = nullptr;
760  QualType RecordTy = BaseType;
761  if (IsArrow) RecordTy = RecordTy->getAs<PointerType>()->getPointeeType();
762  if (LookupMemberExprInRecord(*this, R, nullptr,
763  RecordTy->getAs<RecordType>(), OpLoc, IsArrow,
764  SS, TemplateArgs != nullptr, TE))
765  return ExprError();
766  if (TE)
767  return TE;
768 
769  // Explicit member accesses.
770  } else {
771  ExprResult BaseResult = Base;
772  ExprResult Result = LookupMemberExpr(
773  *this, R, BaseResult, IsArrow, OpLoc, SS,
774  ExtraArgs ? ExtraArgs->ObjCImpDecl : nullptr,
775  TemplateArgs != nullptr);
776 
777  if (BaseResult.isInvalid())
778  return ExprError();
779  Base = BaseResult.get();
780 
781  if (Result.isInvalid())
782  return ExprError();
783 
784  if (Result.get())
785  return Result;
786 
787  // LookupMemberExpr can modify Base, and thus change BaseType
788  BaseType = Base->getType();
789  }
790 
791  return BuildMemberReferenceExpr(Base, BaseType,
792  OpLoc, IsArrow, SS, TemplateKWLoc,
793  FirstQualifierInScope, R, TemplateArgs, S,
794  false, ExtraArgs);
795 }
796 
799  SourceLocation loc,
800  IndirectFieldDecl *indirectField,
801  DeclAccessPair foundDecl,
802  Expr *baseObjectExpr,
803  SourceLocation opLoc) {
804  // First, build the expression that refers to the base object.
805 
806  bool baseObjectIsPointer = false;
807  Qualifiers baseQuals;
808 
809  // Case 1: the base of the indirect field is not a field.
810  VarDecl *baseVariable = indirectField->getVarDecl();
811  CXXScopeSpec EmptySS;
812  if (baseVariable) {
813  assert(baseVariable->getType()->isRecordType());
814 
815  // In principle we could have a member access expression that
816  // accesses an anonymous struct/union that's a static member of
817  // the base object's class. However, under the current standard,
818  // static data members cannot be anonymous structs or unions.
819  // Supporting this is as easy as building a MemberExpr here.
820  assert(!baseObjectExpr && "anonymous struct/union is static data member?");
821 
822  DeclarationNameInfo baseNameInfo(DeclarationName(), loc);
823 
824  ExprResult result
825  = BuildDeclarationNameExpr(EmptySS, baseNameInfo, baseVariable);
826  if (result.isInvalid()) return ExprError();
827 
828  baseObjectExpr = result.get();
829  baseObjectIsPointer = false;
830  baseQuals = baseObjectExpr->getType().getQualifiers();
831 
832  // Case 2: the base of the indirect field is a field and the user
833  // wrote a member expression.
834  } else if (baseObjectExpr) {
835  // The caller provided the base object expression. Determine
836  // whether its a pointer and whether it adds any qualifiers to the
837  // anonymous struct/union fields we're looking into.
838  QualType objectType = baseObjectExpr->getType();
839 
840  if (const PointerType *ptr = objectType->getAs<PointerType>()) {
841  baseObjectIsPointer = true;
842  objectType = ptr->getPointeeType();
843  } else {
844  baseObjectIsPointer = false;
845  }
846  baseQuals = objectType.getQualifiers();
847 
848  // Case 3: the base of the indirect field is a field and we should
849  // build an implicit member access.
850  } else {
851  // We've found a member of an anonymous struct/union that is
852  // inside a non-anonymous struct/union, so in a well-formed
853  // program our base object expression is "this".
854  QualType ThisTy = getCurrentThisType();
855  if (ThisTy.isNull()) {
856  Diag(loc, diag::err_invalid_member_use_in_static_method)
857  << indirectField->getDeclName();
858  return ExprError();
859  }
860 
861  // Our base object expression is "this".
862  CheckCXXThisCapture(loc);
863  baseObjectExpr
864  = new (Context) CXXThisExpr(loc, ThisTy, /*isImplicit=*/ true);
865  baseObjectIsPointer = true;
866  baseQuals = ThisTy->castAs<PointerType>()->getPointeeType().getQualifiers();
867  }
868 
869  // Build the implicit member references to the field of the
870  // anonymous struct/union.
871  Expr *result = baseObjectExpr;
873  FI = indirectField->chain_begin(), FEnd = indirectField->chain_end();
874 
875  // Build the first member access in the chain with full information.
876  if (!baseVariable) {
877  FieldDecl *field = cast<FieldDecl>(*FI);
878 
879  // Make a nameInfo that properly uses the anonymous name.
880  DeclarationNameInfo memberNameInfo(field->getDeclName(), loc);
881 
882  result = BuildFieldReferenceExpr(result, baseObjectIsPointer,
883  SourceLocation(), EmptySS, field,
884  foundDecl, memberNameInfo).get();
885  if (!result)
886  return ExprError();
887 
888  // FIXME: check qualified member access
889  }
890 
891  // In all cases, we should now skip the first declaration in the chain.
892  ++FI;
893 
894  while (FI != FEnd) {
895  FieldDecl *field = cast<FieldDecl>(*FI++);
896 
897  // FIXME: these are somewhat meaningless
898  DeclarationNameInfo memberNameInfo(field->getDeclName(), loc);
899  DeclAccessPair fakeFoundDecl =
900  DeclAccessPair::make(field, field->getAccess());
901 
902  result =
903  BuildFieldReferenceExpr(result, /*isarrow*/ false, SourceLocation(),
904  (FI == FEnd ? SS : EmptySS), field,
905  fakeFoundDecl, memberNameInfo)
906  .get();
907  }
908 
909  return result;
910 }
911 
912 static ExprResult
913 BuildMSPropertyRefExpr(Sema &S, Expr *BaseExpr, bool IsArrow,
914  const CXXScopeSpec &SS,
915  MSPropertyDecl *PD,
916  const DeclarationNameInfo &NameInfo) {
917  // Property names are always simple identifiers and therefore never
918  // require any interesting additional storage.
919  return new (S.Context) MSPropertyRefExpr(BaseExpr, PD, IsArrow,
922  NameInfo.getLoc());
923 }
924 
925 /// \brief Build a MemberExpr AST node.
927  Sema &SemaRef, ASTContext &C, Expr *Base, bool isArrow,
928  SourceLocation OpLoc, const CXXScopeSpec &SS, SourceLocation TemplateKWLoc,
929  ValueDecl *Member, DeclAccessPair FoundDecl,
930  const DeclarationNameInfo &MemberNameInfo, QualType Ty, ExprValueKind VK,
931  ExprObjectKind OK, const TemplateArgumentListInfo *TemplateArgs = nullptr) {
932  assert((!isArrow || Base->isRValue()) && "-> base must be a pointer rvalue");
934  C, Base, isArrow, OpLoc, SS.getWithLocInContext(C), TemplateKWLoc, Member,
935  FoundDecl, MemberNameInfo, TemplateArgs, Ty, VK, OK);
936  SemaRef.MarkMemberReferenced(E);
937  return E;
938 }
939 
940 /// \brief Determine if the given scope is within a function-try-block handler.
941 static bool IsInFnTryBlockHandler(const Scope *S) {
942  // Walk the scope stack until finding a FnTryCatchScope, or leave the
943  // function scope. If a FnTryCatchScope is found, check whether the TryScope
944  // flag is set. If it is not, it's a function-try-block handler.
945  for (; S != S->getFnParent(); S = S->getParent()) {
946  if (S->getFlags() & Scope::FnTryCatchScope)
947  return (S->getFlags() & Scope::TryScope) != Scope::TryScope;
948  }
949  return false;
950 }
951 
952 static VarDecl *
954  const TemplateArgumentListInfo *TemplateArgs,
955  const DeclarationNameInfo &MemberNameInfo,
956  SourceLocation TemplateKWLoc) {
957 
958  if (!TemplateArgs) {
959  S.Diag(MemberNameInfo.getBeginLoc(), diag::err_template_decl_ref)
960  << /*Variable template*/ 1 << MemberNameInfo.getName()
961  << MemberNameInfo.getSourceRange();
962 
963  S.Diag(VarTempl->getLocation(), diag::note_template_decl_here);
964 
965  return nullptr;
966  }
967  DeclResult VDecl = S.CheckVarTemplateId(
968  VarTempl, TemplateKWLoc, MemberNameInfo.getLoc(), *TemplateArgs);
969  if (VDecl.isInvalid())
970  return nullptr;
971  VarDecl *Var = cast<VarDecl>(VDecl.get());
972  if (!Var->getTemplateSpecializationKind())
974  MemberNameInfo.getLoc());
975  return Var;
976 }
977 
980  SourceLocation OpLoc, bool IsArrow,
981  const CXXScopeSpec &SS,
982  SourceLocation TemplateKWLoc,
983  NamedDecl *FirstQualifierInScope,
984  LookupResult &R,
985  const TemplateArgumentListInfo *TemplateArgs,
986  const Scope *S,
987  bool SuppressQualifierCheck,
988  ActOnMemberAccessExtraArgs *ExtraArgs) {
989  QualType BaseType = BaseExprType;
990  if (IsArrow) {
991  assert(BaseType->isPointerType());
992  BaseType = BaseType->castAs<PointerType>()->getPointeeType();
993  }
994  R.setBaseObjectType(BaseType);
995 
996  // C++1z [expr.ref]p2:
997  // For the first option (dot) the first expression shall be a glvalue [...]
998  if (!IsArrow && BaseExpr && BaseExpr->isRValue()) {
999  ExprResult Converted = TemporaryMaterializationConversion(BaseExpr);
1000  if (Converted.isInvalid())
1001  return ExprError();
1002  BaseExpr = Converted.get();
1003  }
1004 
1005 
1006  const DeclarationNameInfo &MemberNameInfo = R.getLookupNameInfo();
1007  DeclarationName MemberName = MemberNameInfo.getName();
1008  SourceLocation MemberLoc = MemberNameInfo.getLoc();
1009 
1010  if (R.isAmbiguous())
1011  return ExprError();
1012 
1013  // [except.handle]p10: Referring to any non-static member or base class of an
1014  // object in the handler for a function-try-block of a constructor or
1015  // destructor for that object results in undefined behavior.
1016  const auto *FD = getCurFunctionDecl();
1017  if (S && BaseExpr && FD &&
1018  (isa<CXXDestructorDecl>(FD) || isa<CXXConstructorDecl>(FD)) &&
1019  isa<CXXThisExpr>(BaseExpr->IgnoreImpCasts()) &&
1021  Diag(MemberLoc, diag::warn_cdtor_function_try_handler_mem_expr)
1022  << isa<CXXDestructorDecl>(FD);
1023 
1024  if (R.empty()) {
1025  // Rederive where we looked up.
1026  DeclContext *DC = (SS.isSet()
1027  ? computeDeclContext(SS, false)
1028  : BaseType->getAs<RecordType>()->getDecl());
1029 
1030  if (ExtraArgs) {
1031  ExprResult RetryExpr;
1032  if (!IsArrow && BaseExpr) {
1033  SFINAETrap Trap(*this, true);
1034  ParsedType ObjectType;
1035  bool MayBePseudoDestructor = false;
1036  RetryExpr = ActOnStartCXXMemberReference(getCurScope(), BaseExpr,
1037  OpLoc, tok::arrow, ObjectType,
1038  MayBePseudoDestructor);
1039  if (RetryExpr.isUsable() && !Trap.hasErrorOccurred()) {
1040  CXXScopeSpec TempSS(SS);
1041  RetryExpr = ActOnMemberAccessExpr(
1042  ExtraArgs->S, RetryExpr.get(), OpLoc, tok::arrow, TempSS,
1043  TemplateKWLoc, ExtraArgs->Id, ExtraArgs->ObjCImpDecl);
1044  }
1045  if (Trap.hasErrorOccurred())
1046  RetryExpr = ExprError();
1047  }
1048  if (RetryExpr.isUsable()) {
1049  Diag(OpLoc, diag::err_no_member_overloaded_arrow)
1050  << MemberName << DC << FixItHint::CreateReplacement(OpLoc, "->");
1051  return RetryExpr;
1052  }
1053  }
1054 
1055  Diag(R.getNameLoc(), diag::err_no_member)
1056  << MemberName << DC
1057  << (BaseExpr ? BaseExpr->getSourceRange() : SourceRange());
1058  return ExprError();
1059  }
1060 
1061  // Diagnose lookups that find only declarations from a non-base
1062  // type. This is possible for either qualified lookups (which may
1063  // have been qualified with an unrelated type) or implicit member
1064  // expressions (which were found with unqualified lookup and thus
1065  // may have come from an enclosing scope). Note that it's okay for
1066  // lookup to find declarations from a non-base type as long as those
1067  // aren't the ones picked by overload resolution.
1068  if ((SS.isSet() || !BaseExpr ||
1069  (isa<CXXThisExpr>(BaseExpr) &&
1070  cast<CXXThisExpr>(BaseExpr)->isImplicit())) &&
1071  !SuppressQualifierCheck &&
1072  CheckQualifiedMemberReference(BaseExpr, BaseType, SS, R))
1073  return ExprError();
1074 
1075  // Construct an unresolved result if we in fact got an unresolved
1076  // result.
1077  if (R.isOverloadedResult() || R.isUnresolvableResult()) {
1078  // Suppress any lookup-related diagnostics; we'll do these when we
1079  // pick a member.
1080  R.suppressDiagnostics();
1081 
1082  UnresolvedMemberExpr *MemExpr
1084  BaseExpr, BaseExprType,
1085  IsArrow, OpLoc,
1086  SS.getWithLocInContext(Context),
1087  TemplateKWLoc, MemberNameInfo,
1088  TemplateArgs, R.begin(), R.end());
1089 
1090  return MemExpr;
1091  }
1092 
1093  assert(R.isSingleResult());
1094  DeclAccessPair FoundDecl = R.begin().getPair();
1095  NamedDecl *MemberDecl = R.getFoundDecl();
1096 
1097  // FIXME: diagnose the presence of template arguments now.
1098 
1099  // If the decl being referenced had an error, return an error for this
1100  // sub-expr without emitting another error, in order to avoid cascading
1101  // error cases.
1102  if (MemberDecl->isInvalidDecl())
1103  return ExprError();
1104 
1105  // Handle the implicit-member-access case.
1106  if (!BaseExpr) {
1107  // If this is not an instance member, convert to a non-member access.
1108  if (!MemberDecl->isCXXInstanceMember()) {
1109  // If this is a variable template, get the instantiated variable
1110  // declaration corresponding to the supplied template arguments
1111  // (while emitting diagnostics as necessary) that will be referenced
1112  // by this expression.
1113  assert((!TemplateArgs || isa<VarTemplateDecl>(MemberDecl)) &&
1114  "How did we get template arguments here sans a variable template");
1115  if (isa<VarTemplateDecl>(MemberDecl)) {
1116  MemberDecl = getVarTemplateSpecialization(
1117  *this, cast<VarTemplateDecl>(MemberDecl), TemplateArgs,
1118  R.getLookupNameInfo(), TemplateKWLoc);
1119  if (!MemberDecl)
1120  return ExprError();
1121  }
1122  return BuildDeclarationNameExpr(SS, R.getLookupNameInfo(), MemberDecl,
1123  FoundDecl, TemplateArgs);
1124  }
1125  SourceLocation Loc = R.getNameLoc();
1126  if (SS.getRange().isValid())
1127  Loc = SS.getRange().getBegin();
1128  CheckCXXThisCapture(Loc);
1129  BaseExpr = new (Context) CXXThisExpr(Loc, BaseExprType,/*isImplicit=*/true);
1130  }
1131 
1132  // Check the use of this member.
1133  if (DiagnoseUseOfDecl(MemberDecl, MemberLoc))
1134  return ExprError();
1135 
1136  if (FieldDecl *FD = dyn_cast<FieldDecl>(MemberDecl))
1137  return BuildFieldReferenceExpr(BaseExpr, IsArrow, OpLoc, SS, FD, FoundDecl,
1138  MemberNameInfo);
1139 
1140  if (MSPropertyDecl *PD = dyn_cast<MSPropertyDecl>(MemberDecl))
1141  return BuildMSPropertyRefExpr(*this, BaseExpr, IsArrow, SS, PD,
1142  MemberNameInfo);
1143 
1144  if (IndirectFieldDecl *FD = dyn_cast<IndirectFieldDecl>(MemberDecl))
1145  // We may have found a field within an anonymous union or struct
1146  // (C++ [class.union]).
1147  return BuildAnonymousStructUnionMemberReference(SS, MemberLoc, FD,
1148  FoundDecl, BaseExpr,
1149  OpLoc);
1150 
1151  if (VarDecl *Var = dyn_cast<VarDecl>(MemberDecl)) {
1152  return BuildMemberExpr(*this, Context, BaseExpr, IsArrow, OpLoc, SS,
1153  TemplateKWLoc, Var, FoundDecl, MemberNameInfo,
1154  Var->getType().getNonReferenceType(), VK_LValue,
1155  OK_Ordinary);
1156  }
1157 
1158  if (CXXMethodDecl *MemberFn = dyn_cast<CXXMethodDecl>(MemberDecl)) {
1159  ExprValueKind valueKind;
1160  QualType type;
1161  if (MemberFn->isInstance()) {
1162  valueKind = VK_RValue;
1163  type = Context.BoundMemberTy;
1164  } else {
1165  valueKind = VK_LValue;
1166  type = MemberFn->getType();
1167  }
1168 
1169  return BuildMemberExpr(*this, Context, BaseExpr, IsArrow, OpLoc, SS,
1170  TemplateKWLoc, MemberFn, FoundDecl, MemberNameInfo,
1171  type, valueKind, OK_Ordinary);
1172  }
1173  assert(!isa<FunctionDecl>(MemberDecl) && "member function not C++ method?");
1174 
1175  if (EnumConstantDecl *Enum = dyn_cast<EnumConstantDecl>(MemberDecl)) {
1176  return BuildMemberExpr(*this, Context, BaseExpr, IsArrow, OpLoc, SS,
1177  TemplateKWLoc, Enum, FoundDecl, MemberNameInfo,
1178  Enum->getType(), VK_RValue, OK_Ordinary);
1179  }
1180  if (VarTemplateDecl *VarTempl = dyn_cast<VarTemplateDecl>(MemberDecl)) {
1182  *this, VarTempl, TemplateArgs, MemberNameInfo, TemplateKWLoc))
1183  return BuildMemberExpr(*this, Context, BaseExpr, IsArrow, OpLoc, SS,
1184  TemplateKWLoc, Var, FoundDecl, MemberNameInfo,
1185  Var->getType().getNonReferenceType(), VK_LValue,
1186  OK_Ordinary);
1187  return ExprError();
1188  }
1189 
1190  // We found something that we didn't expect. Complain.
1191  if (isa<TypeDecl>(MemberDecl))
1192  Diag(MemberLoc, diag::err_typecheck_member_reference_type)
1193  << MemberName << BaseType << int(IsArrow);
1194  else
1195  Diag(MemberLoc, diag::err_typecheck_member_reference_unknown)
1196  << MemberName << BaseType << int(IsArrow);
1197 
1198  Diag(MemberDecl->getLocation(), diag::note_member_declared_here)
1199  << MemberName;
1200  R.suppressDiagnostics();
1201  return ExprError();
1202 }
1203 
1204 /// Given that normal member access failed on the given expression,
1205 /// and given that the expression's type involves builtin-id or
1206 /// builtin-Class, decide whether substituting in the redefinition
1207 /// types would be profitable. The redefinition type is whatever
1208 /// this translation unit tried to typedef to id/Class; we store
1209 /// it to the side and then re-use it in places like this.
1211  const ObjCObjectPointerType *opty
1212  = base.get()->getType()->getAs<ObjCObjectPointerType>();
1213  if (!opty) return false;
1214 
1215  const ObjCObjectType *ty = opty->getObjectType();
1216 
1217  QualType redef;
1218  if (ty->isObjCId()) {
1219  redef = S.Context.getObjCIdRedefinitionType();
1220  } else if (ty->isObjCClass()) {
1222  } else {
1223  return false;
1224  }
1225 
1226  // Do the substitution as long as the redefinition type isn't just a
1227  // possibly-qualified pointer to builtin-id or builtin-Class again.
1228  opty = redef->getAs<ObjCObjectPointerType>();
1229  if (opty && !opty->getObjectType()->getInterface())
1230  return false;
1231 
1232  base = S.ImpCastExprToType(base.get(), redef, CK_BitCast);
1233  return true;
1234 }
1235 
1236 static bool isRecordType(QualType T) {
1237  return T->isRecordType();
1238 }
1240  if (const PointerType *PT = T->getAs<PointerType>())
1241  return PT->getPointeeType()->isRecordType();
1242  return false;
1243 }
1244 
1245 /// Perform conversions on the LHS of a member access expression.
1246 ExprResult
1248  if (IsArrow && !Base->getType()->isFunctionType())
1249  return DefaultFunctionArrayLvalueConversion(Base);
1250 
1251  return CheckPlaceholderExpr(Base);
1252 }
1253 
1254 /// Look up the given member of the given non-type-dependent
1255 /// expression. This can return in one of two ways:
1256 /// * If it returns a sentinel null-but-valid result, the caller will
1257 /// assume that lookup was performed and the results written into
1258 /// the provided structure. It will take over from there.
1259 /// * Otherwise, the returned expression will be produced in place of
1260 /// an ordinary member expression.
1261 ///
1262 /// The ObjCImpDecl bit is a gross hack that will need to be properly
1263 /// fixed for ObjC++.
1265  ExprResult &BaseExpr, bool &IsArrow,
1266  SourceLocation OpLoc, CXXScopeSpec &SS,
1267  Decl *ObjCImpDecl, bool HasTemplateArgs) {
1268  assert(BaseExpr.get() && "no base expression");
1269 
1270  // Perform default conversions.
1271  BaseExpr = S.PerformMemberExprBaseConversion(BaseExpr.get(), IsArrow);
1272  if (BaseExpr.isInvalid())
1273  return ExprError();
1274 
1275  QualType BaseType = BaseExpr.get()->getType();
1276  assert(!BaseType->isDependentType());
1277 
1278  DeclarationName MemberName = R.getLookupName();
1279  SourceLocation MemberLoc = R.getNameLoc();
1280 
1281  // For later type-checking purposes, turn arrow accesses into dot
1282  // accesses. The only access type we support that doesn't follow
1283  // the C equivalence "a->b === (*a).b" is ObjC property accesses,
1284  // and those never use arrows, so this is unaffected.
1285  if (IsArrow) {
1286  if (const PointerType *Ptr = BaseType->getAs<PointerType>())
1287  BaseType = Ptr->getPointeeType();
1288  else if (const ObjCObjectPointerType *Ptr
1289  = BaseType->getAs<ObjCObjectPointerType>())
1290  BaseType = Ptr->getPointeeType();
1291  else if (BaseType->isRecordType()) {
1292  // Recover from arrow accesses to records, e.g.:
1293  // struct MyRecord foo;
1294  // foo->bar
1295  // This is actually well-formed in C++ if MyRecord has an
1296  // overloaded operator->, but that should have been dealt with
1297  // by now--or a diagnostic message already issued if a problem
1298  // was encountered while looking for the overloaded operator->.
1299  if (!S.getLangOpts().CPlusPlus) {
1300  S.Diag(OpLoc, diag::err_typecheck_member_reference_suggestion)
1301  << BaseType << int(IsArrow) << BaseExpr.get()->getSourceRange()
1302  << FixItHint::CreateReplacement(OpLoc, ".");
1303  }
1304  IsArrow = false;
1305  } else if (BaseType->isFunctionType()) {
1306  goto fail;
1307  } else {
1308  S.Diag(MemberLoc, diag::err_typecheck_member_reference_arrow)
1309  << BaseType << BaseExpr.get()->getSourceRange();
1310  return ExprError();
1311  }
1312  }
1313 
1314  // Handle field access to simple records.
1315  if (const RecordType *RTy = BaseType->getAs<RecordType>()) {
1316  TypoExpr *TE = nullptr;
1317  if (LookupMemberExprInRecord(S, R, BaseExpr.get(), RTy,
1318  OpLoc, IsArrow, SS, HasTemplateArgs, TE))
1319  return ExprError();
1320 
1321  // Returning valid-but-null is how we indicate to the caller that
1322  // the lookup result was filled in. If typo correction was attempted and
1323  // failed, the lookup result will have been cleared--that combined with the
1324  // valid-but-null ExprResult will trigger the appropriate diagnostics.
1325  return ExprResult(TE);
1326  }
1327 
1328  // Handle ivar access to Objective-C objects.
1329  if (const ObjCObjectType *OTy = BaseType->getAs<ObjCObjectType>()) {
1330  if (!SS.isEmpty() && !SS.isInvalid()) {
1331  S.Diag(SS.getRange().getBegin(), diag::err_qualified_objc_access)
1332  << 1 << SS.getScopeRep()
1334  SS.clear();
1335  }
1336 
1337  IdentifierInfo *Member = MemberName.getAsIdentifierInfo();
1338 
1339  // There are three cases for the base type:
1340  // - builtin id (qualified or unqualified)
1341  // - builtin Class (qualified or unqualified)
1342  // - an interface
1343  ObjCInterfaceDecl *IDecl = OTy->getInterface();
1344  if (!IDecl) {
1345  if (S.getLangOpts().ObjCAutoRefCount &&
1346  (OTy->isObjCId() || OTy->isObjCClass()))
1347  goto fail;
1348  // There's an implicit 'isa' ivar on all objects.
1349  // But we only actually find it this way on objects of type 'id',
1350  // apparently.
1351  if (OTy->isObjCId() && Member->isStr("isa"))
1352  return new (S.Context) ObjCIsaExpr(BaseExpr.get(), IsArrow, MemberLoc,
1353  OpLoc, S.Context.getObjCClassType());
1354  if (ShouldTryAgainWithRedefinitionType(S, BaseExpr))
1355  return LookupMemberExpr(S, R, BaseExpr, IsArrow, OpLoc, SS,
1356  ObjCImpDecl, HasTemplateArgs);
1357  goto fail;
1358  }
1359 
1360  if (S.RequireCompleteType(OpLoc, BaseType,
1361  diag::err_typecheck_incomplete_tag,
1362  BaseExpr.get()))
1363  return ExprError();
1364 
1365  ObjCInterfaceDecl *ClassDeclared = nullptr;
1366  ObjCIvarDecl *IV = IDecl->lookupInstanceVariable(Member, ClassDeclared);
1367 
1368  if (!IV) {
1369  // Attempt to correct for typos in ivar names.
1370  auto Validator = llvm::make_unique<DeclFilterCCC<ObjCIvarDecl>>();
1371  Validator->IsObjCIvarLookup = IsArrow;
1372  if (TypoCorrection Corrected = S.CorrectTypo(
1373  R.getLookupNameInfo(), Sema::LookupMemberName, nullptr, nullptr,
1374  std::move(Validator), Sema::CTK_ErrorRecovery, IDecl)) {
1375  IV = Corrected.getCorrectionDeclAs<ObjCIvarDecl>();
1376  S.diagnoseTypo(
1377  Corrected,
1378  S.PDiag(diag::err_typecheck_member_reference_ivar_suggest)
1379  << IDecl->getDeclName() << MemberName);
1380 
1381  // Figure out the class that declares the ivar.
1382  assert(!ClassDeclared);
1383 
1384  Decl *D = cast<Decl>(IV->getDeclContext());
1385  if (auto *Category = dyn_cast<ObjCCategoryDecl>(D))
1386  D = Category->getClassInterface();
1387 
1388  if (auto *Implementation = dyn_cast<ObjCImplementationDecl>(D))
1389  ClassDeclared = Implementation->getClassInterface();
1390  else if (auto *Interface = dyn_cast<ObjCInterfaceDecl>(D))
1391  ClassDeclared = Interface;
1392 
1393  assert(ClassDeclared && "cannot query interface");
1394  } else {
1395  if (IsArrow &&
1396  IDecl->FindPropertyDeclaration(
1398  S.Diag(MemberLoc, diag::err_property_found_suggest)
1399  << Member << BaseExpr.get()->getType()
1400  << FixItHint::CreateReplacement(OpLoc, ".");
1401  return ExprError();
1402  }
1403 
1404  S.Diag(MemberLoc, diag::err_typecheck_member_reference_ivar)
1405  << IDecl->getDeclName() << MemberName
1406  << BaseExpr.get()->getSourceRange();
1407  return ExprError();
1408  }
1409  }
1410 
1411  assert(ClassDeclared);
1412 
1413  // If the decl being referenced had an error, return an error for this
1414  // sub-expr without emitting another error, in order to avoid cascading
1415  // error cases.
1416  if (IV->isInvalidDecl())
1417  return ExprError();
1418 
1419  // Check whether we can reference this field.
1420  if (S.DiagnoseUseOfDecl(IV, MemberLoc))
1421  return ExprError();
1422  if (IV->getAccessControl() != ObjCIvarDecl::Public &&
1424  ObjCInterfaceDecl *ClassOfMethodDecl = nullptr;
1425  if (ObjCMethodDecl *MD = S.getCurMethodDecl())
1426  ClassOfMethodDecl = MD->getClassInterface();
1427  else if (ObjCImpDecl && S.getCurFunctionDecl()) {
1428  // Case of a c-function declared inside an objc implementation.
1429  // FIXME: For a c-style function nested inside an objc implementation
1430  // class, there is no implementation context available, so we pass
1431  // down the context as argument to this routine. Ideally, this context
1432  // need be passed down in the AST node and somehow calculated from the
1433  // AST for a function decl.
1434  if (ObjCImplementationDecl *IMPD =
1435  dyn_cast<ObjCImplementationDecl>(ObjCImpDecl))
1436  ClassOfMethodDecl = IMPD->getClassInterface();
1437  else if (ObjCCategoryImplDecl* CatImplClass =
1438  dyn_cast<ObjCCategoryImplDecl>(ObjCImpDecl))
1439  ClassOfMethodDecl = CatImplClass->getClassInterface();
1440  }
1441  if (!S.getLangOpts().DebuggerSupport) {
1442  if (IV->getAccessControl() == ObjCIvarDecl::Private) {
1443  if (!declaresSameEntity(ClassDeclared, IDecl) ||
1444  !declaresSameEntity(ClassOfMethodDecl, ClassDeclared))
1445  S.Diag(MemberLoc, diag::err_private_ivar_access)
1446  << IV->getDeclName();
1447  } else if (!IDecl->isSuperClassOf(ClassOfMethodDecl))
1448  // @protected
1449  S.Diag(MemberLoc, diag::err_protected_ivar_access)
1450  << IV->getDeclName();
1451  }
1452  }
1453  bool warn = true;
1454  if (S.getLangOpts().ObjCWeak) {
1455  Expr *BaseExp = BaseExpr.get()->IgnoreParenImpCasts();
1456  if (UnaryOperator *UO = dyn_cast<UnaryOperator>(BaseExp))
1457  if (UO->getOpcode() == UO_Deref)
1458  BaseExp = UO->getSubExpr()->IgnoreParenCasts();
1459 
1460  if (DeclRefExpr *DE = dyn_cast<DeclRefExpr>(BaseExp))
1461  if (DE->getType().getObjCLifetime() == Qualifiers::OCL_Weak) {
1462  S.Diag(DE->getLocation(), diag::err_arc_weak_ivar_access);
1463  warn = false;
1464  }
1465  }
1466  if (warn) {
1467  if (ObjCMethodDecl *MD = S.getCurMethodDecl()) {
1468  ObjCMethodFamily MF = MD->getMethodFamily();
1469  warn = (MF != OMF_init && MF != OMF_dealloc &&
1470  MF != OMF_finalize &&
1471  !S.IvarBacksCurrentMethodAccessor(IDecl, MD, IV));
1472  }
1473  if (warn)
1474  S.Diag(MemberLoc, diag::warn_direct_ivar_access) << IV->getDeclName();
1475  }
1476 
1477  ObjCIvarRefExpr *Result = new (S.Context) ObjCIvarRefExpr(
1478  IV, IV->getUsageType(BaseType), MemberLoc, OpLoc, BaseExpr.get(),
1479  IsArrow);
1480 
1481  if (IV->getType().getObjCLifetime() == Qualifiers::OCL_Weak) {
1482  if (!S.Diags.isIgnored(diag::warn_arc_repeated_use_of_weak, MemberLoc))
1483  S.recordUseOfEvaluatedWeak(Result);
1484  }
1485 
1486  return Result;
1487  }
1488 
1489  // Objective-C property access.
1490  const ObjCObjectPointerType *OPT;
1491  if (!IsArrow && (OPT = BaseType->getAs<ObjCObjectPointerType>())) {
1492  if (!SS.isEmpty() && !SS.isInvalid()) {
1493  S.Diag(SS.getRange().getBegin(), diag::err_qualified_objc_access)
1494  << 0 << SS.getScopeRep() << FixItHint::CreateRemoval(SS.getRange());
1495  SS.clear();
1496  }
1497 
1498  // This actually uses the base as an r-value.
1499  BaseExpr = S.DefaultLvalueConversion(BaseExpr.get());
1500  if (BaseExpr.isInvalid())
1501  return ExprError();
1502 
1503  assert(S.Context.hasSameUnqualifiedType(BaseType,
1504  BaseExpr.get()->getType()));
1505 
1506  IdentifierInfo *Member = MemberName.getAsIdentifierInfo();
1507 
1508  const ObjCObjectType *OT = OPT->getObjectType();
1509 
1510  // id, with and without qualifiers.
1511  if (OT->isObjCId()) {
1512  // Check protocols on qualified interfaces.
1513  Selector Sel = S.PP.getSelectorTable().getNullarySelector(Member);
1514  if (Decl *PMDecl =
1515  FindGetterSetterNameDecl(OPT, Member, Sel, S.Context)) {
1516  if (ObjCPropertyDecl *PD = dyn_cast<ObjCPropertyDecl>(PMDecl)) {
1517  // Check the use of this declaration
1518  if (S.DiagnoseUseOfDecl(PD, MemberLoc))
1519  return ExprError();
1520 
1521  return new (S.Context)
1523  OK_ObjCProperty, MemberLoc, BaseExpr.get());
1524  }
1525 
1526  if (ObjCMethodDecl *OMD = dyn_cast<ObjCMethodDecl>(PMDecl)) {
1527  // Check the use of this method.
1528  if (S.DiagnoseUseOfDecl(OMD, MemberLoc))
1529  return ExprError();
1530  Selector SetterSel =
1532  S.PP.getSelectorTable(),
1533  Member);
1534  ObjCMethodDecl *SMD = nullptr;
1535  if (Decl *SDecl = FindGetterSetterNameDecl(OPT,
1536  /*Property id*/ nullptr,
1537  SetterSel, S.Context))
1538  SMD = dyn_cast<ObjCMethodDecl>(SDecl);
1539 
1540  return new (S.Context)
1542  OK_ObjCProperty, MemberLoc, BaseExpr.get());
1543  }
1544  }
1545  // Use of id.member can only be for a property reference. Do not
1546  // use the 'id' redefinition in this case.
1547  if (IsArrow && ShouldTryAgainWithRedefinitionType(S, BaseExpr))
1548  return LookupMemberExpr(S, R, BaseExpr, IsArrow, OpLoc, SS,
1549  ObjCImpDecl, HasTemplateArgs);
1550 
1551  return ExprError(S.Diag(MemberLoc, diag::err_property_not_found)
1552  << MemberName << BaseType);
1553  }
1554 
1555  // 'Class', unqualified only.
1556  if (OT->isObjCClass()) {
1557  // Only works in a method declaration (??!).
1558  ObjCMethodDecl *MD = S.getCurMethodDecl();
1559  if (!MD) {
1560  if (ShouldTryAgainWithRedefinitionType(S, BaseExpr))
1561  return LookupMemberExpr(S, R, BaseExpr, IsArrow, OpLoc, SS,
1562  ObjCImpDecl, HasTemplateArgs);
1563 
1564  goto fail;
1565  }
1566 
1567  // Also must look for a getter name which uses property syntax.
1568  Selector Sel = S.PP.getSelectorTable().getNullarySelector(Member);
1569  ObjCInterfaceDecl *IFace = MD->getClassInterface();
1570  ObjCMethodDecl *Getter;
1571  if ((Getter = IFace->lookupClassMethod(Sel))) {
1572  // Check the use of this method.
1573  if (S.DiagnoseUseOfDecl(Getter, MemberLoc))
1574  return ExprError();
1575  } else
1576  Getter = IFace->lookupPrivateMethod(Sel, false);
1577  // If we found a getter then this may be a valid dot-reference, we
1578  // will look for the matching setter, in case it is needed.
1579  Selector SetterSel =
1581  S.PP.getSelectorTable(),
1582  Member);
1583  ObjCMethodDecl *Setter = IFace->lookupClassMethod(SetterSel);
1584  if (!Setter) {
1585  // If this reference is in an @implementation, also check for 'private'
1586  // methods.
1587  Setter = IFace->lookupPrivateMethod(SetterSel, false);
1588  }
1589 
1590  if (Setter && S.DiagnoseUseOfDecl(Setter, MemberLoc))
1591  return ExprError();
1592 
1593  if (Getter || Setter) {
1594  return new (S.Context) ObjCPropertyRefExpr(
1595  Getter, Setter, S.Context.PseudoObjectTy, VK_LValue,
1596  OK_ObjCProperty, MemberLoc, BaseExpr.get());
1597  }
1598 
1599  if (ShouldTryAgainWithRedefinitionType(S, BaseExpr))
1600  return LookupMemberExpr(S, R, BaseExpr, IsArrow, OpLoc, SS,
1601  ObjCImpDecl, HasTemplateArgs);
1602 
1603  return ExprError(S.Diag(MemberLoc, diag::err_property_not_found)
1604  << MemberName << BaseType);
1605  }
1606 
1607  // Normal property access.
1608  return S.HandleExprPropertyRefExpr(OPT, BaseExpr.get(), OpLoc, MemberName,
1609  MemberLoc, SourceLocation(), QualType(),
1610  false);
1611  }
1612 
1613  // Handle 'field access' to vectors, such as 'V.xx'.
1614  if (BaseType->isExtVectorType()) {
1615  // FIXME: this expr should store IsArrow.
1616  IdentifierInfo *Member = MemberName.getAsIdentifierInfo();
1617  ExprValueKind VK;
1618  if (IsArrow)
1619  VK = VK_LValue;
1620  else {
1621  if (PseudoObjectExpr *POE = dyn_cast<PseudoObjectExpr>(BaseExpr.get()))
1622  VK = POE->getSyntacticForm()->getValueKind();
1623  else
1624  VK = BaseExpr.get()->getValueKind();
1625  }
1626  QualType ret = CheckExtVectorComponent(S, BaseType, VK, OpLoc,
1627  Member, MemberLoc);
1628  if (ret.isNull())
1629  return ExprError();
1630 
1631  return new (S.Context)
1632  ExtVectorElementExpr(ret, VK, BaseExpr.get(), *Member, MemberLoc);
1633  }
1634 
1635  // Adjust builtin-sel to the appropriate redefinition type if that's
1636  // not just a pointer to builtin-sel again.
1637  if (IsArrow && BaseType->isSpecificBuiltinType(BuiltinType::ObjCSel) &&
1639  BaseExpr = S.ImpCastExprToType(
1640  BaseExpr.get(), S.Context.getObjCSelRedefinitionType(), CK_BitCast);
1641  return LookupMemberExpr(S, R, BaseExpr, IsArrow, OpLoc, SS,
1642  ObjCImpDecl, HasTemplateArgs);
1643  }
1644 
1645  // Failure cases.
1646  fail:
1647 
1648  // Recover from dot accesses to pointers, e.g.:
1649  // type *foo;
1650  // foo.bar
1651  // This is actually well-formed in two cases:
1652  // - 'type' is an Objective C type
1653  // - 'bar' is a pseudo-destructor name which happens to refer to
1654  // the appropriate pointer type
1655  if (const PointerType *Ptr = BaseType->getAs<PointerType>()) {
1656  if (!IsArrow && Ptr->getPointeeType()->isRecordType() &&
1657  MemberName.getNameKind() != DeclarationName::CXXDestructorName) {
1658  S.Diag(OpLoc, diag::err_typecheck_member_reference_suggestion)
1659  << BaseType << int(IsArrow) << BaseExpr.get()->getSourceRange()
1660  << FixItHint::CreateReplacement(OpLoc, "->");
1661 
1662  // Recurse as an -> access.
1663  IsArrow = true;
1664  return LookupMemberExpr(S, R, BaseExpr, IsArrow, OpLoc, SS,
1665  ObjCImpDecl, HasTemplateArgs);
1666  }
1667  }
1668 
1669  // If the user is trying to apply -> or . to a function name, it's probably
1670  // because they forgot parentheses to call that function.
1671  if (S.tryToRecoverWithCall(
1672  BaseExpr, S.PDiag(diag::err_member_reference_needs_call),
1673  /*complain*/ false,
1674  IsArrow ? &isPointerToRecordType : &isRecordType)) {
1675  if (BaseExpr.isInvalid())
1676  return ExprError();
1677  BaseExpr = S.DefaultFunctionArrayConversion(BaseExpr.get());
1678  return LookupMemberExpr(S, R, BaseExpr, IsArrow, OpLoc, SS,
1679  ObjCImpDecl, HasTemplateArgs);
1680  }
1681 
1682  S.Diag(OpLoc, diag::err_typecheck_member_reference_struct_union)
1683  << BaseType << BaseExpr.get()->getSourceRange() << MemberLoc;
1684 
1685  return ExprError();
1686 }
1687 
1688 /// The main callback when the parser finds something like
1689 /// expression . [nested-name-specifier] identifier
1690 /// expression -> [nested-name-specifier] identifier
1691 /// where 'identifier' encompasses a fairly broad spectrum of
1692 /// possibilities, including destructor and operator references.
1693 ///
1694 /// \param OpKind either tok::arrow or tok::period
1695 /// \param ObjCImpDecl the current Objective-C \@implementation
1696 /// decl; this is an ugly hack around the fact that Objective-C
1697 /// \@implementations aren't properly put in the context chain
1699  SourceLocation OpLoc,
1700  tok::TokenKind OpKind,
1701  CXXScopeSpec &SS,
1702  SourceLocation TemplateKWLoc,
1703  UnqualifiedId &Id,
1704  Decl *ObjCImpDecl) {
1705  if (SS.isSet() && SS.isInvalid())
1706  return ExprError();
1707 
1708  // Warn about the explicit constructor calls Microsoft extension.
1709  if (getLangOpts().MicrosoftExt &&
1711  Diag(Id.getSourceRange().getBegin(),
1712  diag::ext_ms_explicit_constructor_call);
1713 
1714  TemplateArgumentListInfo TemplateArgsBuffer;
1715 
1716  // Decompose the name into its component parts.
1717  DeclarationNameInfo NameInfo;
1718  const TemplateArgumentListInfo *TemplateArgs;
1719  DecomposeUnqualifiedId(Id, TemplateArgsBuffer,
1720  NameInfo, TemplateArgs);
1721 
1722  DeclarationName Name = NameInfo.getName();
1723  bool IsArrow = (OpKind == tok::arrow);
1724 
1725  NamedDecl *FirstQualifierInScope
1726  = (!SS.isSet() ? nullptr : FindFirstQualifierInScope(S, SS.getScopeRep()));
1727 
1728  // This is a postfix expression, so get rid of ParenListExprs.
1729  ExprResult Result = MaybeConvertParenListExprToParenExpr(S, Base);
1730  if (Result.isInvalid()) return ExprError();
1731  Base = Result.get();
1732 
1733  if (Base->getType()->isDependentType() || Name.isDependentName() ||
1734  isDependentScopeSpecifier(SS)) {
1735  return ActOnDependentMemberExpr(Base, Base->getType(), IsArrow, OpLoc, SS,
1736  TemplateKWLoc, FirstQualifierInScope,
1737  NameInfo, TemplateArgs);
1738  }
1739 
1740  ActOnMemberAccessExtraArgs ExtraArgs = {S, Id, ObjCImpDecl};
1741  return BuildMemberReferenceExpr(Base, Base->getType(), OpLoc, IsArrow, SS,
1742  TemplateKWLoc, FirstQualifierInScope,
1743  NameInfo, TemplateArgs, S, &ExtraArgs);
1744 }
1745 
1746 ExprResult
1747 Sema::BuildFieldReferenceExpr(Expr *BaseExpr, bool IsArrow,
1748  SourceLocation OpLoc, const CXXScopeSpec &SS,
1749  FieldDecl *Field, DeclAccessPair FoundDecl,
1750  const DeclarationNameInfo &MemberNameInfo) {
1751  // x.a is an l-value if 'a' has a reference type. Otherwise:
1752  // x.a is an l-value/x-value/pr-value if the base is (and note
1753  // that *x is always an l-value), except that if the base isn't
1754  // an ordinary object then we must have an rvalue.
1755  ExprValueKind VK = VK_LValue;
1757  if (!IsArrow) {
1758  if (BaseExpr->getObjectKind() == OK_Ordinary)
1759  VK = BaseExpr->getValueKind();
1760  else
1761  VK = VK_RValue;
1762  }
1763  if (VK != VK_RValue && Field->isBitField())
1764  OK = OK_BitField;
1765 
1766  // Figure out the type of the member; see C99 6.5.2.3p3, C++ [expr.ref]
1767  QualType MemberType = Field->getType();
1768  if (const ReferenceType *Ref = MemberType->getAs<ReferenceType>()) {
1769  MemberType = Ref->getPointeeType();
1770  VK = VK_LValue;
1771  } else {
1772  QualType BaseType = BaseExpr->getType();
1773  if (IsArrow) BaseType = BaseType->getAs<PointerType>()->getPointeeType();
1774 
1775  Qualifiers BaseQuals = BaseType.getQualifiers();
1776 
1777  // GC attributes are never picked up by members.
1778  BaseQuals.removeObjCGCAttr();
1779 
1780  // CVR attributes from the base are picked up by members,
1781  // except that 'mutable' members don't pick up 'const'.
1782  if (Field->isMutable()) BaseQuals.removeConst();
1783 
1784  Qualifiers MemberQuals =
1785  Context.getCanonicalType(MemberType).getQualifiers();
1786 
1787  assert(!MemberQuals.hasAddressSpace());
1788 
1789  Qualifiers Combined = BaseQuals + MemberQuals;
1790  if (Combined != MemberQuals)
1791  MemberType = Context.getQualifiedType(MemberType, Combined);
1792  }
1793 
1794  UnusedPrivateFields.remove(Field);
1795 
1796  ExprResult Base = PerformObjectMemberConversion(BaseExpr, SS.getScopeRep(),
1797  FoundDecl, Field);
1798  if (Base.isInvalid())
1799  return ExprError();
1800 
1801  // Build a reference to a private copy for non-static data members in
1802  // non-static member functions, privatized by OpenMP constructs.
1803  if (getLangOpts().OpenMP && IsArrow &&
1804  !CurContext->isDependentContext() &&
1805  isa<CXXThisExpr>(Base.get()->IgnoreParenImpCasts())) {
1806  if (auto *PrivateCopy = IsOpenMPCapturedDecl(Field)) {
1807  return getOpenMPCapturedExpr(PrivateCopy, VK, OK,
1808  MemberNameInfo.getLoc());
1809  }
1810  }
1811 
1812  return BuildMemberExpr(*this, Context, Base.get(), IsArrow, OpLoc, SS,
1813  /*TemplateKWLoc=*/SourceLocation(), Field, FoundDecl,
1814  MemberNameInfo, MemberType, VK, OK);
1815 }
1816 
1817 /// Builds an implicit member access expression. The current context
1818 /// is known to be an instance method, and the given unqualified lookup
1819 /// set is known to contain only instance members, at least one of which
1820 /// is from an appropriate type.
1821 ExprResult
1823  SourceLocation TemplateKWLoc,
1824  LookupResult &R,
1825  const TemplateArgumentListInfo *TemplateArgs,
1826  bool IsKnownInstance, const Scope *S) {
1827  assert(!R.empty() && !R.isAmbiguous());
1828 
1829  SourceLocation loc = R.getNameLoc();
1830 
1831  // If this is known to be an instance access, go ahead and build an
1832  // implicit 'this' expression now.
1833  // 'this' expression now.
1834  QualType ThisTy = getCurrentThisType();
1835  assert(!ThisTy.isNull() && "didn't correctly pre-flight capture of 'this'");
1836 
1837  Expr *baseExpr = nullptr; // null signifies implicit access
1838  if (IsKnownInstance) {
1839  SourceLocation Loc = R.getNameLoc();
1840  if (SS.getRange().isValid())
1841  Loc = SS.getRange().getBegin();
1842  CheckCXXThisCapture(Loc);
1843  baseExpr = new (Context) CXXThisExpr(loc, ThisTy, /*isImplicit=*/true);
1844  }
1845 
1846  return BuildMemberReferenceExpr(baseExpr, ThisTy,
1847  /*OpLoc*/ SourceLocation(),
1848  /*IsArrow*/ true,
1849  SS, TemplateKWLoc,
1850  /*FirstQualifierInScope*/ nullptr,
1851  R, TemplateArgs, S);
1852 }
ObjCPropertyRefExpr - A dot-syntax expression to access an ObjC property.
Definition: ExprObjC.h:539
SourceLocation getLoc() const
getLoc - Returns the main location of the declaration name.
This is the scope of a C++ try statement.
Definition: Scope.h:100
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:546
ExternalSemaSource * getExternalSource() const
Definition: Sema.h:1203
Smart pointer class that efficiently represents Objective-C method names.
SelectorTable & getSelectorTable()
Definition: Preprocessor.h:738
ArrayRef< NamedDecl * >::const_iterator chain_iterator
Definition: Decl.h:2641
PointerType - C99 6.7.5.1 - Pointer Declarators.
Definition: Type.h:2222
QualType getPointeeType() const
Definition: Type.h:2236
A (possibly-)qualified type.
Definition: Type.h:614
Simple class containing the result of Sema::CorrectTypo.
ObjCInterfaceDecl * getClassInterface()
Definition: DeclObjC.cpp:1089
bool IvarBacksCurrentMethodAccessor(ObjCInterfaceDecl *IFace, ObjCMethodDecl *Method, ObjCIvarDecl *IV)
IvarBacksCurrentMethodAccessor - This routine returns &#39;true&#39; if &#39;IV&#39; is an ivar synthesized for &#39;Meth...
The reference may be to an instance member, but it might be invalid if so, because the context is not...
SourceRange getSourceRange() const LLVM_READONLY
Return the source range that covers this unqualified-id.
Definition: DeclSpec.h:1120
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:1133
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:1144
VarDecl * getVarDecl() const
Definition: Decl.h:2656
void setLookupName(DeclarationName Name)
Sets the name to look up.
Definition: Lookup.h:260
QualType CXXThisTypeOverride
When non-NULL, the C++ &#39;this&#39; expression is allowed despite the current context not being a non-stati...
Definition: Sema.h:5037
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee...
Definition: Type.cpp:435
IMAKind
EnumConstantDecl - An instance of this object exists for each enum constant that is defined...
Definition: Decl.h:2584
ActionResult< Expr * > ExprResult
Definition: Ownership.h:251
bool isRecordType() const
Definition: Type.h:5823
bool isEmpty() const
No scope specifier.
Definition: DeclSpec.h:189
QualType getQualifiedType(SplitQualType split) const
Un-split a SplitQualType.
Definition: ASTContext.h:1841
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
Emit a diagnostic.
Definition: Sema.h:1270
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:81
bool isExtVectorType() const
Definition: Type.h:5835
Defines the C++ template declaration subclasses.
The reference is definitely an implicit instance member access.
SourceLocation getBeginLoc() const
getBeginLoc - Retrieve the location of the first token.
Declaration of a variable template.
RedeclarationKind
Specifies whether (or how) name lookup is being performed for a redeclaration (vs.
Definition: Sema.h:3040
static bool IsInFnTryBlockHandler(const Scope *S)
Determine if the given scope is within a function-try-block handler.
const DeclAccessPair & getPair() const
Definition: UnresolvedSet.h:49
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:771
PartialDiagnostic PDiag(unsigned DiagID=0)
Build a partial diagnostic.
Definition: SemaInternal.h:25
DeclarationName getLookupName() const
Gets the name to look up.
Definition: Lookup.h:255
ObjCIsaExpr - Represent X->isa and X.isa when X is an ObjC &#39;id&#39; type.
Definition: ExprObjC.h:1383
DiagnosticsEngine & Diags
Definition: Sema.h:318
const T * getAs() const
Member-template getAs<specific type>&#39;.
Definition: Type.h:6099
DeclContext * computeDeclContext(QualType T)
Compute the DeclContext that is associated with the given type.
ObjCMethodDecl - Represents an instance or class method declaration.
Definition: DeclObjC.h:113
NamedDecl * getUnderlyingDecl()
Looks through UsingDecls and ObjCCompatibleAliasDecls for the underlying named decl.
Definition: Decl.h:390
bool isAmbiguous() const
Definition: Lookup.h:304
bool isInvalidDecl() const
Definition: DeclBase.h:532
QualType getObjCClassType() const
Represents the Objective-C Class type.
Definition: ASTContext.h:1783
void setBegin(SourceLocation b)
bool isStatic() const
Definition: DeclCXX.cpp:1612
protocol_range protocols() const
Definition: DeclObjC.h:2042
Defines the clang::Expr interface and subclasses for C++ expressions.
iterator begin(Source *source, bool LocalOnly=false)
The collection of all-type qualifiers we support.
Definition: Type.h:116
Qualifiers getQualifiers() const
Retrieve all qualifiers.
Expr * IgnoreImpCasts() LLVM_READONLY
IgnoreImpCasts - Skip past any implicit casts which might surround this expression.
Definition: Expr.h:2866
RecordDecl - Represents a struct/union/class.
Definition: Decl.h:3384
DeclarationName getDeclName() const
getDeclName - Get the actual, stored name of the declaration, which may be a special name...
Definition: Decl.h:258
bool Encloses(const DeclContext *DC) const
Determine whether this declaration context encloses the declaration context DC.
Definition: DeclBase.cpp:1079
One of these records is kept for each identifier that is lexed.
bool isStr(const char(&Str)[StrLen]) const
Return true if this is the identifier for the specified string.
Represents a class type in Objective C.
Definition: Type.h:5023
IdKind getKind() const
Determine what kind of name we have.
Definition: DeclSpec.h:1002
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:128
DeclarationName getCorrection() const
Gets the DeclarationName of the typo correction.
bool CheckQualifiedMemberReference(Expr *BaseExpr, QualType BaseType, const CXXScopeSpec &SS, const LookupResult &R)
static VarDecl * getVarTemplateSpecialization(Sema &S, VarTemplateDecl *VarTempl, const TemplateArgumentListInfo *TemplateArgs, const DeclarationNameInfo &MemberNameInfo, SourceLocation TemplateKWLoc)
ObjCMethodFamily
A family of Objective-C methods.
Base class for callback objects used by Sema::CorrectTypo to check the validity of a potential typo c...
FieldDecl - An instance of this class is created by Sema::ActOnField to represent a member of a struc...
Definition: Decl.h:2382
The current expression is potentially evaluated at run time, which means that code may be generated t...
void removeConst()
Definition: Type.h:237
The reference may be to an unresolved using declaration and the context is not an instance method...
const DeclarationNameInfo & getLookupNameInfo() const
Gets the name info to look up.
Definition: Lookup.h:245
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&#39;s type ...
int Category
Definition: Format.cpp:1319
bool isSpecificBuiltinType(unsigned K) const
Test for a particular builtin type.
Definition: Type.h:5930
bool Equals(const DeclContext *DC) const
Determine whether this declaration context is equivalent to the declaration context DC...
Definition: DeclBase.h:1423
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:3355
static int getPointAccessorIdx(char c)
Definition: Type.h:2904
bool isObjCSelType() const
Definition: Type.h:5875
ExtVectorElementExpr - This represents access to specific elements of a vector, and may occur on the ...
Definition: Expr.h:4791
ExprResult DefaultFunctionArrayConversion(Expr *E, bool Diagnose=true)
DefaultFunctionArrayConversion (C99 6.3.2.1p3, C99 6.3.2.1p4).
Definition: SemaExpr.cpp:417
An r-value expression (a pr-value in the C++11 taxonomy) produces a temporary value.
Definition: Specifiers.h:107
bool isDependentName() const
Determines whether the name itself is dependent, e.g., because it involves a C++ type that is itself ...
static Selector constructSetterSelector(IdentifierTable &Idents, SelectorTable &SelTable, const IdentifierInfo *Name)
Return the default setter selector for the given identifier.
Represents a C++ unqualified-id that has been parsed.
Definition: DeclSpec.h:900
bool isBitField() const
Determines whether this field is a bitfield.
Definition: Decl.h:2457
Selector getNullarySelector(IdentifierInfo *ID)
void resolveKind()
Resolves the result kind of the lookup, possibly hiding decls.
Definition: SemaLookup.cpp:471
Represents the results of name lookup.
Definition: Lookup.h:32
PtrTy get() const
Definition: Ownership.h:162
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:1158
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...
bool hasAddressSpace() const
Definition: Type.h:330
ExprValueKind getValueKind() const
getValueKind - The value kind that this expression produces.
Definition: Expr.h:405
ExprResult BuildAnonymousStructUnionMemberReference(const CXXScopeSpec &SS, SourceLocation nameLoc, IndirectFieldDecl *indirectField, DeclAccessPair FoundDecl=DeclAccessPair::make(nullptr, AS_none), Expr *baseObjectExpr=nullptr, SourceLocation opLoc=SourceLocation())
static bool isRecordType(QualType T)
TemplateSpecializationKind getTemplateSpecializationKind() const
If this variable is an instantiation of a variable template or a static data member of a class templa...
Definition: Decl.cpp:2348
The reference is a contextually-permitted abstract member reference.
CanQualType PseudoObjectTy
Definition: ASTContext.h:984
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:1561
Expr * IgnoreParenCasts() LLVM_READONLY
IgnoreParenCasts - Ignore parentheses and casts.
Definition: Expr.cpp:2462
Scope - A scope is a transient data structure that is used while parsing the program.
Definition: Scope.h:39
CXXRecordDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Definition: DeclCXX.h:670
bool declaresSameEntity(const Decl *D1, const Decl *D2)
Determine whether two declarations declare the same entity.
Definition: DeclBase.h:1127
TypoExpr - Internal placeholder for expressions where typo correction still needs to be performed and...
Definition: Expr.h:5233
ObjCMethodDecl * lookupClassMethod(Selector Sel) const
Lookup a class method for a given selector.
Definition: DeclObjC.h:1771
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
Preprocessor & PP
Definition: Sema.h:315
const LangOptions & getLangOpts() const
Definition: Sema.h:1193
The reference may be an implicit instance member access.
An ordinary object is located at an address in memory.
Definition: Specifiers.h:123
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)
void addDecl(NamedDecl *D)
Add a declaration to these results with its natural access.
Definition: Lookup.h:429
Member name lookup, which finds the names of class/struct/union members.
Definition: Sema.h:3003
ObjCInterfaceDecl * getInterface() const
Gets the interface declaration for this object type, if the base type really is an interface...
Definition: Type.h:5253
The current context is "potentially evaluated" in C++11 terms, but the expression is evaluated at com...
NestedNameSpecifierLoc getWithLocInContext(ASTContext &Context) const
Retrieve a nested-name-specifier with location information, copied into the given AST context...
Definition: DeclSpec.cpp:143
unsigned getLength() const
Efficiently return the length of this identifier info.
Sema::RedeclarationKind redeclarationKind() const
Definition: Lookup.h:280
Represents the this expression in C++.
Definition: ExprCXX.h:888
llvm::SmallPtrSet< const CXXRecordDecl *, 4 > BaseSet
RAII class used to determine whether SFINAE has trapped any errors that occur during template argumen...
Definition: Sema.h:7427
unsigned getFlags() const
getFlags - Return the flags for this scope.
Definition: Scope.h:213
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:274
All possible referrents are instance members and the current context is not an instance method...
SourceRange getRange() const
Definition: DeclSpec.h:68
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
std::string getAsString(const LangOptions &LO) const
An Objective-C property is a logical field of an Objective-C object which is read and written via Obj...
Definition: Specifiers.h:133
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:593
Expr - This represents one expression.
Definition: Expr.h:106
DeclResult CheckVarTemplateId(VarTemplateDecl *Template, SourceLocation TemplateLoc, SourceLocation TemplateNameLoc, const TemplateArgumentListInfo &TemplateArgs)
LookupNameKind
Describes the kind of name lookup to perform.
Definition: Sema.h:2991
ExprValueKind
The categorization of expression values, currently following the C++11 scheme.
Definition: Specifiers.h:104
static bool IsRGBA(char c)
Determine whether input char is from rgba component set.
int Id
Definition: ASTDiff.cpp:191
const FunctionProtoType * T
const T * castAs() const
Member-template castAs<specific type>.
Definition: Type.h:6162
std::string getAsString() const
getNameAsString - Retrieve the human-readable string for this name.
Defines the clang::Preprocessor interface.
All possible referrents are instance members of an unrelated class.
DeclContext * getDeclContext()
Definition: DeclBase.h:416
bool RequireCompleteType(SourceLocation Loc, QualType T, TypeDiagnoser &Diagnoser)
Ensure that the type T is a complete type.
Definition: SemaType.cpp:7350
The current expression and its subexpressions occur within an unevaluated operand (C++11 [expr]p7)...
QualType getType() const
Definition: Expr.h:128
ObjCIvarDecl * lookupInstanceVariable(IdentifierInfo *IVarName, ObjCInterfaceDecl *&ClassDeclared)
Definition: DeclObjC.cpp:600
bool isSingleResult() const
Determines if this names a single result which is not an unresolved value using decl.
Definition: Lookup.h:311
DeclContext * getParent()
getParent - Returns the containing DeclContext.
Definition: DeclBase.h:1303
bool isInvalid() const
Definition: Ownership.h:158
SourceLocation getEnd() const
UnaryOperator - This represents the unary-expression&#39;s (except sizeof and alignof), the postinc/postdec operators from postfix-expression, and various extensions.
Definition: Expr.h:1717
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
bool isUsable() const
Definition: Ownership.h:159
This template specialization was implicitly instantiated from a template.
Definition: Specifiers.h:149
bool isObjCClass() const
Definition: Type.h:5089
bool isNull() const
Return true if this QualType doesn&#39;t point to a type yet.
Definition: Type.h:681
bool isProvablyNotDerivedFrom(const CXXRecordDecl *Base) const
Determine whether this class is provably not derived from the type Base.
ExprObjectKind getObjectKind() const
getObjectKind - The object kind that this expression produces.
Definition: Expr.h:412
bool isUnresolvableResult() const
Definition: Lookup.h:320
RecordDecl * getDecl() const
Definition: Type.h:3848
NestedNameSpecifier * getScopeRep() const
Retrieve the representation of the nested-name-specifier.
Definition: DeclSpec.h:76
chain_iterator chain_end() const
Definition: Decl.h:2647
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:1548
static bool isPointerToRecordType(QualType T)
ActionResult - This structure is used while parsing/acting on expressions, stmts, etc...
Definition: Ownership.h:144
PseudoObjectExpr - An expression which accesses a pseudo-object l-value.
Definition: Expr.h:4970
static ExprResult BuildMSPropertyRefExpr(Sema &S, Expr *BaseExpr, bool IsArrow, const CXXScopeSpec &SS, MSPropertyDecl *PD, const DeclarationNameInfo &NameInfo)
bool isAccessorWithinNumElements(char c, bool isNumericAccessor) const
Definition: Type.h:2948
Encodes a location in the source.
QualType getObjCSelRedefinitionType() const
Retrieve the type that &#39;SEL&#39; has been defined to, which may be different from the built-in &#39;SEL&#39; if &#39;...
Definition: ASTContext.h:1574
DeclarationName getName() const
getName - Returns the embedded declaration name.
QualType getElementType() const
Definition: Type.h:2862
IdentifierTable & getIdentifierTable()
Definition: Preprocessor.h:736
bool isOverloadedResult() const
Determines if the results are overloaded.
Definition: Lookup.h:316
ExprObjectKind
A further classification of the kind of object referenced by an l-value or x-value.
Definition: Specifiers.h:121
Represents a static or instance method of a struct/union/class.
Definition: DeclCXX.h:1918
QualType getExtVectorType(QualType VectorType, unsigned NumElts) const
Return the unique reference to an extended vector type of the specified element type and size...
ExprResult DefaultLvalueConversion(Expr *E)
Definition: SemaExpr.cpp:530
The reference may be to an unresolved using declaration.
const char * getNameStart() const
Return the beginning of the actual null-terminated string for this identifier.
TokenKind
Provides a simple uniform namespace for tokens from all C languages.
Definition: TokenKinds.h:25
bool forallBases(ForallBasesCallback BaseMatches, bool AllowShortCircuit=true) const
Determines if the given callback holds for all the direct or indirect base classes of this type...
Represents one property declaration in an Objective-C interface.
Definition: DeclObjC.h:704
static Decl * FindGetterSetterNameDecl(const ObjCObjectPointerType *QIdTy, IdentifierInfo *Member, const Selector &Sel, ASTContext &Context)
bool isSuperClassOf(const ObjCInterfaceDecl *I) const
isSuperClassOf - Return true if this class is the specified class or is a super class of the specifie...
Definition: DeclObjC.h:1729
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:288
bool RequireCompleteDeclContext(CXXScopeSpec &SS, DeclContext *DC)
Require that the context specified by SS be complete.
bool isInvalid() const
An error occurred during parsing of the scope specifier.
Definition: DeclSpec.h:194
bool hasSameUnqualifiedType(QualType T1, QualType T2) const
Determine whether the given types are equivalent after cvr-qualifiers have been removed.
Definition: ASTContext.h:2165
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
Sema & getSema() const
Get the Sema object that this lookup result is searching with.
Definition: Lookup.h:615
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:2386
void diagnoseTypo(const TypoCorrection &Correction, const PartialDiagnostic &TypoDiag, bool ErrorRecovery=true)
QualType getTypedefType(const TypedefNameDecl *Decl, QualType Canon=QualType()) const
Return the unique reference to the type for the specified typedef-name decl.
void MarkMemberReferenced(MemberExpr *E)
Perform reference-marking and odr-use handling for a MemberExpr.
Definition: SemaExpr.cpp:14993
bool isObjCId() const
Definition: Type.h:5086
Dataflow Directional Tag Classes.
bool isValid() const
Return true if this is a valid SourceLocation object.
ObjCMethodDecl * lookupPrivateMethod(const Selector &Sel, bool Instance=true) const
Lookup a method in the classes implementation hierarchy.
Definition: DeclObjC.cpp:720
ObjCPropertyDecl * FindPropertyDeclaration(const IdentifierInfo *PropertyId, ObjCPropertyQueryKind QueryKind) const
FindPropertyDeclaration - Finds declaration of the property given its name in &#39;PropertyId&#39; and return...
Definition: DeclObjC.cpp:213
void recordUseOfEvaluatedWeak(const ExprT *E, bool IsRead=true)
Definition: Sema.h:1337
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1224
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.
const Scope * getParent() const
getParent - Return the scope that this is nested in.
Definition: Scope.h:221
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
Definition: ASTMatchers.h:2154
ExprResult ImpCastExprToType(Expr *E, QualType Type, CastKind CK, ExprValueKind VK=VK_RValue, const CXXCastPath *BasePath=nullptr, CheckedConversionKind CCK=CCK_ImplicitConversion)
ImpCastExprToType - If Expr is not of type &#39;Type&#39;, insert an implicit cast.
Definition: Sema.cpp:454
bool isRecord() const
Definition: DeclBase.h:1377
The current expression occurs within an unevaluated operand that unconditionally permits abstract ref...
IndirectFieldDecl - An instance of this class is created to represent a field injected from an anonym...
Definition: Decl.h:2624
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:204
static FixItHint CreateRemoval(CharSourceRange RemoveRange)
Create a code modification hint that removes the given source range.
Definition: Diagnostic.h:116
AccessSpecifier getAccess() const
Definition: DeclBase.h:451
NamedDecl * getCorrectionDecl() const
Gets the pointer to the declaration of the typo correction.
DeclarationName - The name of a declaration.
NamedDecl * getFoundDecl() const
Fetch the unique decl found by this lookup.
Definition: Lookup.h:520
const CXXRecordDecl * getParent() const
Returns the parent of this method declaration, which is the class in which this method is defined...
Definition: DeclCXX.h:2033
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:1675
const ObjCObjectType * getObjectType() const
Gets the type pointed to by this ObjC pointer.
Definition: Type.h:5314
ExprResult ActOnMemberAccessExpr(Scope *S, Expr *Base, SourceLocation OpLoc, tok::TokenKind OpKind, CXXScopeSpec &SS, SourceLocation TemplateKWLoc, UnqualifiedId &Member, Decl *ObjCImpDecl)
The main callback when the parser finds something like expression .
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspnd...
Expr * IgnoreParenImpCasts() LLVM_READONLY
IgnoreParenImpCasts - Ignore parentheses and implicit casts.
Definition: Expr.cpp:2549
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:5274
ObjCImplementationDecl - Represents a class definition - this is where method definitions are specifi...
Definition: DeclObjC.h:2448
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
Definition: Type.h:3839
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.
chain_iterator chain_begin() const
Definition: Decl.h:2646
FunctionDecl * getCurFunctionDecl()
getCurFunctionDecl - If inside of a function body, this returns a pointer to the function decl for th...
Definition: Sema.cpp:1153
bool isFunctionType() const
Definition: Type.h:5763
ExprResult HandleExprPropertyRefExpr(const ObjCObjectPointerType *OPT, Expr *BaseExpr, SourceLocation OpLoc, DeclarationName MemberName, SourceLocation MemberLoc, SourceLocation SuperLoc, QualType SuperType, bool Super)
HandleExprPropertyRefExpr - Handle foo.bar where foo is a pointer to an objective C interface...
ExtVectorType - Extended vector type.
Definition: Type.h:2899
Base for LValueReferenceType and RValueReferenceType.
Definition: Type.h:2358
CanQualType BoundMemberTy
Definition: ASTContext.h:982
SmallVector< ExpressionEvaluationContextRecord, 8 > ExprEvalContexts
A stack of expression evaluation contexts.
Definition: Sema.h:1006
ExprResult BuildFieldReferenceExpr(Expr *BaseExpr, bool IsArrow, SourceLocation OpLoc, const CXXScopeSpec &SS, FieldDecl *Field, DeclAccessPair FoundDecl, const DeclarationNameInfo &MemberNameInfo)
qual_range quals() const
Definition: Type.h:5396
Sema::LookupNameKind getLookupKind() const
Gets the kind of lookup to perform.
Definition: Lookup.h:265
A bitfield object is a bitfield on a C or C++ record.
Definition: Specifiers.h:126
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.
CanQualType getCanonicalType(QualType T) const
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
Definition: ASTContext.h:2124
bool isSet() const
Deprecated.
Definition: DeclSpec.h:209
The reference may be to an instance member, but it is invalid if so, because the context is from an u...
ExprResult PerformMemberExprBaseConversion(Expr *Base, bool IsArrow)
Perform conversions on the LHS of a member access expression.
Reading or writing from this object requires a barrier call.
Definition: Type.h:147
static UnresolvedMemberExpr * Create(const ASTContext &C, bool HasUnresolvedUsing, Expr *Base, QualType BaseType, bool IsArrow, SourceLocation OperatorLoc, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, const DeclarationNameInfo &MemberNameInfo, const TemplateArgumentListInfo *TemplateArgs, UnresolvedSetIterator Begin, UnresolvedSetIterator End)
Definition: ExprCXX.cpp:1247
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate.h) and friends (in DeclFriend.h).
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
Definition: Expr.h:2387
bool isMutable() const
isMutable - Determines whether this field is mutable (C++ only).
Definition: Decl.h:2454
Represents a C++ struct/union/class.
Definition: DeclCXX.h:266
bool isValid() const
Qualifiers getQualifiers() const
Retrieve the set of qualifiers applied to this type.
Definition: Type.h:5570
ObjCIvarDecl - Represents an ObjC instance variable.
Definition: DeclObjC.h:1866
bool isRValue() const
Definition: Expr.h:250
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
iterator end() const
Definition: Lookup.h:339
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
Definition: Stmt.cpp:245
ExprResult ExprError()
Definition: Ownership.h:267
unsigned getNumElements() const
Definition: Type.h:2863
void LookupTemplateName(LookupResult &R, Scope *S, CXXScopeSpec &SS, QualType ObjectType, bool EnteringContext, bool &MemberOfUnknownSpecialization)
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
Definition: Type.h:1795
A reference to a declared variable, function, enum, etc.
Definition: Expr.h:956
const Scope * getFnParent() const
getFnParent - Return the closest scope that is a function body.
Definition: Scope.h:226
bool isIgnored(unsigned DiagID, SourceLocation Loc) const
Determine whether the diagnostic is known to be ignored.
Definition: Diagnostic.h:732
bool isPointerType() const
Definition: Type.h:5766
void setBaseObjectType(QualType T)
Sets the base object type for this lookup.
Definition: Lookup.h:423
The reference is definitely not an instance member access.
void suppressDiagnostics()
Suppress the diagnostics that would normally fire because of this lookup.
Definition: Lookup.h:586
An instance of this class represents the declaration of a property member.
Definition: DeclCXX.h:3762
QualType getType() const
Definition: Decl.h:602
An l-value expression is a reference to an object with independent storage.
Definition: Specifiers.h:111
bool empty() const
Return true if no decls were found.
Definition: Lookup.h:342
static Decl * FindGetterSetterNameDeclFromProtocolList(const ObjCProtocolDecl *PDecl, IdentifierInfo *Member, const Selector &Sel, ASTContext &Context)
static int getNumericAccessorIdx(char c)
Definition: Type.h:2913
A trivial tuple used to represent a source range.
ASTContext & Context
Definition: Sema.h:316
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
ObjCMethodDecl * getInstanceMethod(Selector Sel, bool AllowHidden=false) const
Definition: DeclObjC.h:1025
AccessControl getAccessControl() const
Definition: DeclObjC.h:1905
iterator begin() const
Definition: Lookup.h:338
SourceLocation getNameLoc() const
Gets the location of the identifier.
Definition: Lookup.h:609
static QualType CheckExtVectorComponent(Sema &S, QualType baseType, ExprValueKind &VK, SourceLocation OpLoc, const IdentifierInfo *CompName, SourceLocation CompLoc)
Check an ext-vector component access expression.
NamedDecl * getRepresentativeDecl() const
Fetches a representative decl. Useful for lazy diagnostics.
Definition: Lookup.h:527
SourceLocation getBegin() const
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:557
The current expression occurs within a braced-init-list within an unevaluated operand.
SourceLocation getLocation() const
Definition: DeclBase.h:407
static bool isProvablyNotDerivedFrom(Sema &SemaRef, CXXRecordDecl *Record, const BaseSet &Bases)
Determines if the given class is provably not derived from all of the prospective base classes...
bool isCXXInstanceMember() const
Determine whether the given declaration is an instance member of a C++ class.
Definition: Decl.cpp:1659
bool hasErrorOccurred() const
Determine whether any SFINAE errors have been trapped.
Definition: Sema.h:7453
Qualifiers::ObjCLifetime getObjCLifetime() const
Returns lifetime attribute of this type.
Definition: Type.h:1026
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:1040