Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 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/SemaInternal.h" |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 14 | #include "clang/AST/DeclCXX.h" |
| 15 | #include "clang/AST/DeclObjC.h" |
| 16 | #include "clang/AST/DeclTemplate.h" |
| 17 | #include "clang/AST/ExprCXX.h" |
| 18 | #include "clang/AST/ExprObjC.h" |
| 19 | #include "clang/Lex/Preprocessor.h" |
Chandler Carruth | 55fc873 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 20 | #include "clang/Sema/Lookup.h" |
| 21 | #include "clang/Sema/Scope.h" |
| 22 | #include "clang/Sema/ScopeInfo.h" |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 23 | |
| 24 | using namespace clang; |
| 25 | using namespace sema; |
| 26 | |
Richard Smith | f62c690 | 2012-11-22 00:24:47 +0000 | [diff] [blame] | 27 | typedef llvm::SmallPtrSet<const CXXRecordDecl*, 4> BaseSet; |
| 28 | static bool BaseIsNotInSet(const CXXRecordDecl *Base, void *BasesPtr) { |
| 29 | const BaseSet &Bases = *reinterpret_cast<const BaseSet*>(BasesPtr); |
| 30 | return !Bases.count(Base->getCanonicalDecl()); |
| 31 | } |
| 32 | |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 33 | /// Determines if the given class is provably not derived from all of |
| 34 | /// the prospective base classes. |
Richard Smith | f62c690 | 2012-11-22 00:24:47 +0000 | [diff] [blame] | 35 | static bool isProvablyNotDerivedFrom(Sema &SemaRef, CXXRecordDecl *Record, |
| 36 | const BaseSet &Bases) { |
| 37 | void *BasesPtr = const_cast<void*>(reinterpret_cast<const void*>(&Bases)); |
| 38 | return BaseIsNotInSet(Record, BasesPtr) && |
| 39 | Record->forallBases(BaseIsNotInSet, BasesPtr); |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | enum IMAKind { |
| 43 | /// The reference is definitely not an instance member access. |
| 44 | IMA_Static, |
| 45 | |
| 46 | /// The reference may be an implicit instance member access. |
| 47 | IMA_Mixed, |
| 48 | |
Eli Friedman | 9bc291d | 2012-01-18 03:53:45 +0000 | [diff] [blame] | 49 | /// The reference may be to an instance member, but it might be invalid if |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 50 | /// so, because the context is not an instance method. |
| 51 | IMA_Mixed_StaticContext, |
| 52 | |
| 53 | /// The reference may be to an instance member, but it is invalid if |
| 54 | /// so, because the context is from an unrelated class. |
| 55 | IMA_Mixed_Unrelated, |
| 56 | |
| 57 | /// The reference is definitely an implicit instance member access. |
| 58 | IMA_Instance, |
| 59 | |
| 60 | /// The reference may be to an unresolved using declaration. |
| 61 | IMA_Unresolved, |
| 62 | |
John McCall | aeeacf7 | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 63 | /// The reference is a contextually-permitted abstract member reference. |
| 64 | IMA_Abstract, |
| 65 | |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 66 | /// The reference may be to an unresolved using declaration and the |
| 67 | /// context is not an instance method. |
| 68 | IMA_Unresolved_StaticContext, |
| 69 | |
Eli Friedman | ef331b7 | 2012-01-20 01:26:23 +0000 | [diff] [blame] | 70 | // The reference refers to a field which is not a member of the containing |
| 71 | // class, which is allowed because we're in C++11 mode and the context is |
| 72 | // unevaluated. |
| 73 | IMA_Field_Uneval_Context, |
Eli Friedman | 9bc291d | 2012-01-18 03:53:45 +0000 | [diff] [blame] | 74 | |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 75 | /// All possible referrents are instance members and the current |
| 76 | /// context is not an instance method. |
| 77 | IMA_Error_StaticContext, |
| 78 | |
| 79 | /// All possible referrents are instance members of an unrelated |
| 80 | /// class. |
| 81 | IMA_Error_Unrelated |
| 82 | }; |
| 83 | |
| 84 | /// The given lookup names class member(s) and is not being used for |
| 85 | /// an address-of-member expression. Classify the type of access |
| 86 | /// according to whether it's possible that this reference names an |
Eli Friedman | 9bc291d | 2012-01-18 03:53:45 +0000 | [diff] [blame] | 87 | /// instance member. This is best-effort in dependent contexts; it is okay to |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 88 | /// conservatively answer "yes", in which case some errors will simply |
| 89 | /// not be caught until template-instantiation. |
| 90 | static IMAKind ClassifyImplicitMemberAccess(Sema &SemaRef, |
| 91 | Scope *CurScope, |
| 92 | const LookupResult &R) { |
| 93 | assert(!R.empty() && (*R.begin())->isCXXClassMember()); |
| 94 | |
| 95 | DeclContext *DC = SemaRef.getFunctionLevelDeclContext(); |
| 96 | |
Douglas Gregor | cefc3af | 2012-04-16 07:05:22 +0000 | [diff] [blame] | 97 | bool isStaticContext = SemaRef.CXXThisTypeOverride.isNull() && |
| 98 | (!isa<CXXMethodDecl>(DC) || cast<CXXMethodDecl>(DC)->isStatic()); |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 99 | |
| 100 | if (R.isUnresolvableResult()) |
| 101 | return isStaticContext ? IMA_Unresolved_StaticContext : IMA_Unresolved; |
| 102 | |
| 103 | // Collect all the declaring classes of instance members we find. |
| 104 | bool hasNonInstance = false; |
Eli Friedman | 9bc291d | 2012-01-18 03:53:45 +0000 | [diff] [blame] | 105 | bool isField = false; |
Richard Smith | f62c690 | 2012-11-22 00:24:47 +0000 | [diff] [blame] | 106 | BaseSet Classes; |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 107 | for (LookupResult::iterator I = R.begin(), E = R.end(); I != E; ++I) { |
| 108 | NamedDecl *D = *I; |
| 109 | |
| 110 | if (D->isCXXInstanceMember()) { |
John McCall | 76da55d | 2013-04-16 07:28:30 +0000 | [diff] [blame] | 111 | if (dyn_cast<FieldDecl>(D) || dyn_cast<MSPropertyDecl>(D) |
| 112 | || dyn_cast<IndirectFieldDecl>(D)) |
Eli Friedman | 9bc291d | 2012-01-18 03:53:45 +0000 | [diff] [blame] | 113 | isField = true; |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 114 | |
| 115 | CXXRecordDecl *R = cast<CXXRecordDecl>(D->getDeclContext()); |
| 116 | Classes.insert(R->getCanonicalDecl()); |
| 117 | } |
| 118 | else |
| 119 | hasNonInstance = true; |
| 120 | } |
| 121 | |
| 122 | // If we didn't find any instance members, it can't be an implicit |
| 123 | // member reference. |
| 124 | if (Classes.empty()) |
| 125 | return IMA_Static; |
John McCall | aeeacf7 | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 126 | |
| 127 | // C++11 [expr.prim.general]p12: |
| 128 | // An id-expression that denotes a non-static data member or non-static |
| 129 | // member function of a class can only be used: |
| 130 | // (...) |
| 131 | // - if that id-expression denotes a non-static data member and it |
| 132 | // appears in an unevaluated operand. |
| 133 | // |
| 134 | // This rule is specific to C++11. However, we also permit this form |
| 135 | // in unevaluated inline assembly operands, like the operand to a SIZE. |
| 136 | IMAKind AbstractInstanceResult = IMA_Static; // happens to be 'false' |
| 137 | assert(!AbstractInstanceResult); |
| 138 | switch (SemaRef.ExprEvalContexts.back().Context) { |
| 139 | case Sema::Unevaluated: |
| 140 | if (isField && SemaRef.getLangOpts().CPlusPlus11) |
| 141 | AbstractInstanceResult = IMA_Field_Uneval_Context; |
| 142 | break; |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 143 | |
John McCall | aeeacf7 | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 144 | case Sema::UnevaluatedAbstract: |
| 145 | AbstractInstanceResult = IMA_Abstract; |
| 146 | break; |
| 147 | |
| 148 | case Sema::ConstantEvaluated: |
| 149 | case Sema::PotentiallyEvaluated: |
| 150 | case Sema::PotentiallyEvaluatedIfUsed: |
| 151 | break; |
Richard Smith | 2c8aee4 | 2012-02-25 10:04:07 +0000 | [diff] [blame] | 152 | } |
| 153 | |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 154 | // If the current context is not an instance method, it can't be |
| 155 | // an implicit member reference. |
| 156 | if (isStaticContext) { |
| 157 | if (hasNonInstance) |
Richard Smith | 2c8aee4 | 2012-02-25 10:04:07 +0000 | [diff] [blame] | 158 | return IMA_Mixed_StaticContext; |
| 159 | |
John McCall | aeeacf7 | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 160 | return AbstractInstanceResult ? AbstractInstanceResult |
| 161 | : IMA_Error_StaticContext; |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | CXXRecordDecl *contextClass; |
| 165 | if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC)) |
| 166 | contextClass = MD->getParent()->getCanonicalDecl(); |
| 167 | else |
| 168 | contextClass = cast<CXXRecordDecl>(DC); |
| 169 | |
| 170 | // [class.mfct.non-static]p3: |
| 171 | // ...is used in the body of a non-static member function of class X, |
| 172 | // if name lookup (3.4.1) resolves the name in the id-expression to a |
| 173 | // non-static non-type member of some class C [...] |
| 174 | // ...if C is not X or a base class of X, the class member access expression |
| 175 | // is ill-formed. |
| 176 | if (R.getNamingClass() && |
DeLesley Hutchins | d08d599 | 2012-02-25 00:11:55 +0000 | [diff] [blame] | 177 | contextClass->getCanonicalDecl() != |
Richard Smith | f62c690 | 2012-11-22 00:24:47 +0000 | [diff] [blame] | 178 | R.getNamingClass()->getCanonicalDecl()) { |
| 179 | // If the naming class is not the current context, this was a qualified |
| 180 | // member name lookup, and it's sufficient to check that we have the naming |
| 181 | // class as a base class. |
| 182 | Classes.clear(); |
Richard Smith | 746619a | 2012-11-22 00:40:54 +0000 | [diff] [blame] | 183 | Classes.insert(R.getNamingClass()->getCanonicalDecl()); |
Richard Smith | f62c690 | 2012-11-22 00:24:47 +0000 | [diff] [blame] | 184 | } |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 185 | |
| 186 | // If we can prove that the current context is unrelated to all the |
| 187 | // declaring classes, it can't be an implicit member reference (in |
| 188 | // which case it's an error if any of those members are selected). |
Richard Smith | f62c690 | 2012-11-22 00:24:47 +0000 | [diff] [blame] | 189 | if (isProvablyNotDerivedFrom(SemaRef, contextClass, Classes)) |
Richard Smith | d390de9 | 2012-02-25 10:20:59 +0000 | [diff] [blame] | 190 | return hasNonInstance ? IMA_Mixed_Unrelated : |
John McCall | aeeacf7 | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 191 | AbstractInstanceResult ? AbstractInstanceResult : |
| 192 | IMA_Error_Unrelated; |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 193 | |
| 194 | return (hasNonInstance ? IMA_Mixed : IMA_Instance); |
| 195 | } |
| 196 | |
| 197 | /// Diagnose a reference to a field with no object available. |
Richard Smith | a85cf39 | 2012-04-05 01:13:04 +0000 | [diff] [blame] | 198 | static void diagnoseInstanceReference(Sema &SemaRef, |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 199 | const CXXScopeSpec &SS, |
Richard Smith | a85cf39 | 2012-04-05 01:13:04 +0000 | [diff] [blame] | 200 | NamedDecl *Rep, |
Eli Friedman | ef331b7 | 2012-01-20 01:26:23 +0000 | [diff] [blame] | 201 | const DeclarationNameInfo &nameInfo) { |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 202 | SourceLocation Loc = nameInfo.getLoc(); |
| 203 | SourceRange Range(Loc); |
| 204 | if (SS.isSet()) Range.setBegin(SS.getRange().getBegin()); |
Eli Friedman | 9bc291d | 2012-01-18 03:53:45 +0000 | [diff] [blame] | 205 | |
Richard Smith | a85cf39 | 2012-04-05 01:13:04 +0000 | [diff] [blame] | 206 | DeclContext *FunctionLevelDC = SemaRef.getFunctionLevelDeclContext(); |
| 207 | CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(FunctionLevelDC); |
| 208 | CXXRecordDecl *ContextClass = Method ? Method->getParent() : 0; |
| 209 | CXXRecordDecl *RepClass = dyn_cast<CXXRecordDecl>(Rep->getDeclContext()); |
| 210 | |
| 211 | bool InStaticMethod = Method && Method->isStatic(); |
| 212 | bool IsField = isa<FieldDecl>(Rep) || isa<IndirectFieldDecl>(Rep); |
| 213 | |
| 214 | if (IsField && InStaticMethod) |
| 215 | // "invalid use of member 'x' in static member function" |
| 216 | SemaRef.Diag(Loc, diag::err_invalid_member_use_in_static_method) |
| 217 | << Range << nameInfo.getName(); |
| 218 | else if (ContextClass && RepClass && SS.isEmpty() && !InStaticMethod && |
| 219 | !RepClass->Equals(ContextClass) && RepClass->Encloses(ContextClass)) |
| 220 | // Unqualified lookup in a non-static member function found a member of an |
| 221 | // enclosing class. |
| 222 | SemaRef.Diag(Loc, diag::err_nested_non_static_member_use) |
| 223 | << IsField << RepClass << nameInfo.getName() << ContextClass << Range; |
| 224 | else if (IsField) |
Eli Friedman | ef331b7 | 2012-01-20 01:26:23 +0000 | [diff] [blame] | 225 | SemaRef.Diag(Loc, diag::err_invalid_non_static_member_use) |
Richard Smith | a85cf39 | 2012-04-05 01:13:04 +0000 | [diff] [blame] | 226 | << nameInfo.getName() << Range; |
| 227 | else |
| 228 | SemaRef.Diag(Loc, diag::err_member_call_without_object) |
| 229 | << Range; |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | /// Builds an expression which might be an implicit member expression. |
| 233 | ExprResult |
| 234 | Sema::BuildPossibleImplicitMemberExpr(const CXXScopeSpec &SS, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 235 | SourceLocation TemplateKWLoc, |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 236 | LookupResult &R, |
| 237 | const TemplateArgumentListInfo *TemplateArgs) { |
| 238 | switch (ClassifyImplicitMemberAccess(*this, CurScope, R)) { |
| 239 | case IMA_Instance: |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 240 | return BuildImplicitMemberExpr(SS, TemplateKWLoc, R, TemplateArgs, true); |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 241 | |
| 242 | case IMA_Mixed: |
| 243 | case IMA_Mixed_Unrelated: |
| 244 | case IMA_Unresolved: |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 245 | return BuildImplicitMemberExpr(SS, TemplateKWLoc, R, TemplateArgs, false); |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 246 | |
Richard Smith | d390de9 | 2012-02-25 10:20:59 +0000 | [diff] [blame] | 247 | case IMA_Field_Uneval_Context: |
| 248 | Diag(R.getNameLoc(), diag::warn_cxx98_compat_non_static_member_use) |
| 249 | << R.getLookupNameInfo().getName(); |
| 250 | // Fall through. |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 251 | case IMA_Static: |
John McCall | aeeacf7 | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 252 | case IMA_Abstract: |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 253 | case IMA_Mixed_StaticContext: |
| 254 | case IMA_Unresolved_StaticContext: |
Abramo Bagnara | 9d9922a | 2012-02-06 14:31:00 +0000 | [diff] [blame] | 255 | if (TemplateArgs || TemplateKWLoc.isValid()) |
| 256 | return BuildTemplateIdExpr(SS, TemplateKWLoc, R, false, TemplateArgs); |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 257 | return BuildDeclarationNameExpr(SS, R, false); |
| 258 | |
| 259 | case IMA_Error_StaticContext: |
| 260 | case IMA_Error_Unrelated: |
Richard Smith | a85cf39 | 2012-04-05 01:13:04 +0000 | [diff] [blame] | 261 | diagnoseInstanceReference(*this, SS, R.getRepresentativeDecl(), |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 262 | R.getLookupNameInfo()); |
| 263 | return ExprError(); |
| 264 | } |
| 265 | |
| 266 | llvm_unreachable("unexpected instance member access kind"); |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 267 | } |
| 268 | |
| 269 | /// Check an ext-vector component access expression. |
| 270 | /// |
| 271 | /// VK should be set in advance to the value kind of the base |
| 272 | /// expression. |
| 273 | static QualType |
| 274 | CheckExtVectorComponent(Sema &S, QualType baseType, ExprValueKind &VK, |
| 275 | SourceLocation OpLoc, const IdentifierInfo *CompName, |
| 276 | SourceLocation CompLoc) { |
| 277 | // FIXME: Share logic with ExtVectorElementExpr::containsDuplicateElements, |
| 278 | // see FIXME there. |
| 279 | // |
| 280 | // FIXME: This logic can be greatly simplified by splitting it along |
| 281 | // halving/not halving and reworking the component checking. |
| 282 | const ExtVectorType *vecType = baseType->getAs<ExtVectorType>(); |
| 283 | |
| 284 | // The vector accessor can't exceed the number of elements. |
| 285 | const char *compStr = CompName->getNameStart(); |
| 286 | |
| 287 | // This flag determines whether or not the component is one of the four |
| 288 | // special names that indicate a subset of exactly half the elements are |
| 289 | // to be selected. |
| 290 | bool HalvingSwizzle = false; |
| 291 | |
| 292 | // This flag determines whether or not CompName has an 's' char prefix, |
| 293 | // indicating that it is a string of hex values to be used as vector indices. |
| 294 | bool HexSwizzle = *compStr == 's' || *compStr == 'S'; |
| 295 | |
| 296 | bool HasRepeated = false; |
| 297 | bool HasIndex[16] = {}; |
| 298 | |
| 299 | int Idx; |
| 300 | |
| 301 | // Check that we've found one of the special components, or that the component |
| 302 | // names must come from the same set. |
| 303 | if (!strcmp(compStr, "hi") || !strcmp(compStr, "lo") || |
| 304 | !strcmp(compStr, "even") || !strcmp(compStr, "odd")) { |
| 305 | HalvingSwizzle = true; |
| 306 | } else if (!HexSwizzle && |
| 307 | (Idx = vecType->getPointAccessorIdx(*compStr)) != -1) { |
| 308 | do { |
| 309 | if (HasIndex[Idx]) HasRepeated = true; |
| 310 | HasIndex[Idx] = true; |
| 311 | compStr++; |
| 312 | } while (*compStr && (Idx = vecType->getPointAccessorIdx(*compStr)) != -1); |
| 313 | } else { |
| 314 | if (HexSwizzle) compStr++; |
| 315 | while ((Idx = vecType->getNumericAccessorIdx(*compStr)) != -1) { |
| 316 | if (HasIndex[Idx]) HasRepeated = true; |
| 317 | HasIndex[Idx] = true; |
| 318 | compStr++; |
| 319 | } |
| 320 | } |
| 321 | |
| 322 | if (!HalvingSwizzle && *compStr) { |
| 323 | // We didn't get to the end of the string. This means the component names |
| 324 | // didn't come from the same set *or* we encountered an illegal name. |
| 325 | S.Diag(OpLoc, diag::err_ext_vector_component_name_illegal) |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 326 | << StringRef(compStr, 1) << SourceRange(CompLoc); |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 327 | return QualType(); |
| 328 | } |
| 329 | |
| 330 | // Ensure no component accessor exceeds the width of the vector type it |
| 331 | // operates on. |
| 332 | if (!HalvingSwizzle) { |
| 333 | compStr = CompName->getNameStart(); |
| 334 | |
| 335 | if (HexSwizzle) |
| 336 | compStr++; |
| 337 | |
| 338 | while (*compStr) { |
| 339 | if (!vecType->isAccessorWithinNumElements(*compStr++)) { |
| 340 | S.Diag(OpLoc, diag::err_ext_vector_component_exceeds_length) |
| 341 | << baseType << SourceRange(CompLoc); |
| 342 | return QualType(); |
| 343 | } |
| 344 | } |
| 345 | } |
| 346 | |
| 347 | // The component accessor looks fine - now we need to compute the actual type. |
| 348 | // The vector type is implied by the component accessor. For example, |
| 349 | // vec4.b is a float, vec4.xy is a vec2, vec4.rgb is a vec3, etc. |
| 350 | // vec4.s0 is a float, vec4.s23 is a vec3, etc. |
| 351 | // vec4.hi, vec4.lo, vec4.e, and vec4.o all return vec2. |
| 352 | unsigned CompSize = HalvingSwizzle ? (vecType->getNumElements() + 1) / 2 |
| 353 | : CompName->getLength(); |
| 354 | if (HexSwizzle) |
| 355 | CompSize--; |
| 356 | |
| 357 | if (CompSize == 1) |
| 358 | return vecType->getElementType(); |
| 359 | |
| 360 | if (HasRepeated) VK = VK_RValue; |
| 361 | |
| 362 | QualType VT = S.Context.getExtVectorType(vecType->getElementType(), CompSize); |
| 363 | // Now look up the TypeDefDecl from the vector type. Without this, |
| 364 | // diagostics look bad. We want extended vector types to appear built-in. |
Douglas Gregor | d58a0a5 | 2011-07-28 00:39:29 +0000 | [diff] [blame] | 365 | for (Sema::ExtVectorDeclsType::iterator |
Axel Naumann | 0ec56b7 | 2012-10-18 19:05:02 +0000 | [diff] [blame] | 366 | I = S.ExtVectorDecls.begin(S.getExternalSource()), |
Douglas Gregor | d58a0a5 | 2011-07-28 00:39:29 +0000 | [diff] [blame] | 367 | E = S.ExtVectorDecls.end(); |
| 368 | I != E; ++I) { |
| 369 | if ((*I)->getUnderlyingType() == VT) |
| 370 | return S.Context.getTypedefType(*I); |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 371 | } |
Douglas Gregor | d58a0a5 | 2011-07-28 00:39:29 +0000 | [diff] [blame] | 372 | |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 373 | return VT; // should never get here (a typedef type should always be found). |
| 374 | } |
| 375 | |
| 376 | static Decl *FindGetterSetterNameDeclFromProtocolList(const ObjCProtocolDecl*PDecl, |
| 377 | IdentifierInfo *Member, |
| 378 | const Selector &Sel, |
| 379 | ASTContext &Context) { |
| 380 | if (Member) |
| 381 | if (ObjCPropertyDecl *PD = PDecl->FindPropertyDeclaration(Member)) |
| 382 | return PD; |
| 383 | if (ObjCMethodDecl *OMD = PDecl->getInstanceMethod(Sel)) |
| 384 | return OMD; |
| 385 | |
| 386 | for (ObjCProtocolDecl::protocol_iterator I = PDecl->protocol_begin(), |
| 387 | E = PDecl->protocol_end(); I != E; ++I) { |
| 388 | if (Decl *D = FindGetterSetterNameDeclFromProtocolList(*I, Member, Sel, |
| 389 | Context)) |
| 390 | return D; |
| 391 | } |
| 392 | return 0; |
| 393 | } |
| 394 | |
| 395 | static Decl *FindGetterSetterNameDecl(const ObjCObjectPointerType *QIdTy, |
| 396 | IdentifierInfo *Member, |
| 397 | const Selector &Sel, |
| 398 | ASTContext &Context) { |
| 399 | // Check protocols on qualified interfaces. |
| 400 | Decl *GDecl = 0; |
| 401 | for (ObjCObjectPointerType::qual_iterator I = QIdTy->qual_begin(), |
| 402 | E = QIdTy->qual_end(); I != E; ++I) { |
| 403 | if (Member) |
| 404 | if (ObjCPropertyDecl *PD = (*I)->FindPropertyDeclaration(Member)) { |
| 405 | GDecl = PD; |
| 406 | break; |
| 407 | } |
| 408 | // Also must look for a getter or setter name which uses property syntax. |
| 409 | if (ObjCMethodDecl *OMD = (*I)->getInstanceMethod(Sel)) { |
| 410 | GDecl = OMD; |
| 411 | break; |
| 412 | } |
| 413 | } |
| 414 | if (!GDecl) { |
| 415 | for (ObjCObjectPointerType::qual_iterator I = QIdTy->qual_begin(), |
| 416 | E = QIdTy->qual_end(); I != E; ++I) { |
| 417 | // Search in the protocol-qualifier list of current protocol. |
| 418 | GDecl = FindGetterSetterNameDeclFromProtocolList(*I, Member, Sel, |
| 419 | Context); |
| 420 | if (GDecl) |
| 421 | return GDecl; |
| 422 | } |
| 423 | } |
| 424 | return GDecl; |
| 425 | } |
| 426 | |
| 427 | ExprResult |
| 428 | Sema::ActOnDependentMemberExpr(Expr *BaseExpr, QualType BaseType, |
| 429 | bool IsArrow, SourceLocation OpLoc, |
| 430 | const CXXScopeSpec &SS, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 431 | SourceLocation TemplateKWLoc, |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 432 | NamedDecl *FirstQualifierInScope, |
| 433 | const DeclarationNameInfo &NameInfo, |
| 434 | const TemplateArgumentListInfo *TemplateArgs) { |
| 435 | // Even in dependent contexts, try to diagnose base expressions with |
| 436 | // obviously wrong types, e.g.: |
| 437 | // |
| 438 | // T* t; |
| 439 | // t.f; |
| 440 | // |
| 441 | // In Obj-C++, however, the above expression is valid, since it could be |
| 442 | // accessing the 'f' property if T is an Obj-C interface. The extra check |
| 443 | // allows this, while still reporting an error if T is a struct pointer. |
| 444 | if (!IsArrow) { |
| 445 | const PointerType *PT = BaseType->getAs<PointerType>(); |
David Blaikie | 4e4d084 | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 446 | if (PT && (!getLangOpts().ObjC1 || |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 447 | PT->getPointeeType()->isRecordType())) { |
| 448 | assert(BaseExpr && "cannot happen with implicit member accesses"); |
Matt Beaumont-Gay | 7d90fe5 | 2012-04-21 01:12:48 +0000 | [diff] [blame] | 449 | Diag(OpLoc, diag::err_typecheck_member_reference_struct_union) |
Matt Beaumont-Gay | 73664a4 | 2012-04-21 02:13:04 +0000 | [diff] [blame] | 450 | << BaseType << BaseExpr->getSourceRange() << NameInfo.getSourceRange(); |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 451 | return ExprError(); |
| 452 | } |
| 453 | } |
| 454 | |
| 455 | assert(BaseType->isDependentType() || |
| 456 | NameInfo.getName().isDependentName() || |
| 457 | isDependentScopeSpecifier(SS)); |
| 458 | |
| 459 | // Get the type being accessed in BaseType. If this is an arrow, the BaseExpr |
| 460 | // must have pointer type, and the accessed type is the pointee. |
| 461 | return Owned(CXXDependentScopeMemberExpr::Create(Context, BaseExpr, BaseType, |
| 462 | IsArrow, OpLoc, |
| 463 | SS.getWithLocInContext(Context), |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 464 | TemplateKWLoc, |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 465 | FirstQualifierInScope, |
| 466 | NameInfo, TemplateArgs)); |
| 467 | } |
| 468 | |
| 469 | /// We know that the given qualified member reference points only to |
| 470 | /// declarations which do not belong to the static type of the base |
| 471 | /// expression. Diagnose the problem. |
| 472 | static void DiagnoseQualifiedMemberReference(Sema &SemaRef, |
| 473 | Expr *BaseExpr, |
| 474 | QualType BaseType, |
| 475 | const CXXScopeSpec &SS, |
| 476 | NamedDecl *rep, |
| 477 | const DeclarationNameInfo &nameInfo) { |
| 478 | // If this is an implicit member access, use a different set of |
| 479 | // diagnostics. |
| 480 | if (!BaseExpr) |
Richard Smith | a85cf39 | 2012-04-05 01:13:04 +0000 | [diff] [blame] | 481 | return diagnoseInstanceReference(SemaRef, SS, rep, nameInfo); |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 482 | |
| 483 | SemaRef.Diag(nameInfo.getLoc(), diag::err_qualified_member_of_unrelated) |
| 484 | << SS.getRange() << rep << BaseType; |
| 485 | } |
| 486 | |
| 487 | // Check whether the declarations we found through a nested-name |
| 488 | // specifier in a member expression are actually members of the base |
| 489 | // type. The restriction here is: |
| 490 | // |
| 491 | // C++ [expr.ref]p2: |
| 492 | // ... In these cases, the id-expression shall name a |
| 493 | // member of the class or of one of its base classes. |
| 494 | // |
| 495 | // So it's perfectly legitimate for the nested-name specifier to name |
| 496 | // an unrelated class, and for us to find an overload set including |
| 497 | // decls from classes which are not superclasses, as long as the decl |
| 498 | // we actually pick through overload resolution is from a superclass. |
| 499 | bool Sema::CheckQualifiedMemberReference(Expr *BaseExpr, |
| 500 | QualType BaseType, |
| 501 | const CXXScopeSpec &SS, |
| 502 | const LookupResult &R) { |
Richard Smith | f62c690 | 2012-11-22 00:24:47 +0000 | [diff] [blame] | 503 | CXXRecordDecl *BaseRecord = |
| 504 | cast_or_null<CXXRecordDecl>(computeDeclContext(BaseType)); |
| 505 | if (!BaseRecord) { |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 506 | // We can't check this yet because the base type is still |
| 507 | // dependent. |
| 508 | assert(BaseType->isDependentType()); |
| 509 | return false; |
| 510 | } |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 511 | |
| 512 | for (LookupResult::iterator I = R.begin(), E = R.end(); I != E; ++I) { |
| 513 | // If this is an implicit member reference and we find a |
| 514 | // non-instance member, it's not an error. |
| 515 | if (!BaseExpr && !(*I)->isCXXInstanceMember()) |
| 516 | return false; |
| 517 | |
| 518 | // Note that we use the DC of the decl, not the underlying decl. |
| 519 | DeclContext *DC = (*I)->getDeclContext(); |
| 520 | while (DC->isTransparentContext()) |
| 521 | DC = DC->getParent(); |
| 522 | |
| 523 | if (!DC->isRecord()) |
| 524 | continue; |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 525 | |
Richard Smith | f62c690 | 2012-11-22 00:24:47 +0000 | [diff] [blame] | 526 | CXXRecordDecl *MemberRecord = cast<CXXRecordDecl>(DC)->getCanonicalDecl(); |
| 527 | if (BaseRecord->getCanonicalDecl() == MemberRecord || |
| 528 | !BaseRecord->isProvablyNotDerivedFrom(MemberRecord)) |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 529 | return false; |
| 530 | } |
| 531 | |
| 532 | DiagnoseQualifiedMemberReference(*this, BaseExpr, BaseType, SS, |
| 533 | R.getRepresentativeDecl(), |
| 534 | R.getLookupNameInfo()); |
| 535 | return true; |
| 536 | } |
| 537 | |
Kaelyn Uhrain | e4c7f90 | 2012-01-13 21:28:55 +0000 | [diff] [blame] | 538 | namespace { |
| 539 | |
| 540 | // Callback to only accept typo corrections that are either a ValueDecl or a |
| 541 | // FunctionTemplateDecl. |
| 542 | class RecordMemberExprValidatorCCC : public CorrectionCandidateCallback { |
| 543 | public: |
| 544 | virtual bool ValidateCandidate(const TypoCorrection &candidate) { |
| 545 | NamedDecl *ND = candidate.getCorrectionDecl(); |
| 546 | return ND && (isa<ValueDecl>(ND) || isa<FunctionTemplateDecl>(ND)); |
| 547 | } |
| 548 | }; |
| 549 | |
| 550 | } |
| 551 | |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 552 | static bool |
Douglas Gregor | cefc3af | 2012-04-16 07:05:22 +0000 | [diff] [blame] | 553 | LookupMemberExprInRecord(Sema &SemaRef, LookupResult &R, |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 554 | SourceRange BaseRange, const RecordType *RTy, |
| 555 | SourceLocation OpLoc, CXXScopeSpec &SS, |
| 556 | bool HasTemplateArgs) { |
| 557 | RecordDecl *RDecl = RTy->getDecl(); |
Douglas Gregor | cefc3af | 2012-04-16 07:05:22 +0000 | [diff] [blame] | 558 | if (!SemaRef.isThisOutsideMemberFunctionBody(QualType(RTy, 0)) && |
| 559 | SemaRef.RequireCompleteType(OpLoc, QualType(RTy, 0), |
Douglas Gregor | d10099e | 2012-05-04 16:32:21 +0000 | [diff] [blame] | 560 | diag::err_typecheck_incomplete_tag, |
| 561 | BaseRange)) |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 562 | return true; |
| 563 | |
| 564 | if (HasTemplateArgs) { |
| 565 | // LookupTemplateName doesn't expect these both to exist simultaneously. |
| 566 | QualType ObjectType = SS.isSet() ? QualType() : QualType(RTy, 0); |
| 567 | |
| 568 | bool MOUS; |
| 569 | SemaRef.LookupTemplateName(R, 0, SS, ObjectType, false, MOUS); |
| 570 | return false; |
| 571 | } |
| 572 | |
| 573 | DeclContext *DC = RDecl; |
| 574 | if (SS.isSet()) { |
| 575 | // If the member name was a qualified-id, look into the |
| 576 | // nested-name-specifier. |
| 577 | DC = SemaRef.computeDeclContext(SS, false); |
| 578 | |
| 579 | if (SemaRef.RequireCompleteDeclContext(SS, DC)) { |
| 580 | SemaRef.Diag(SS.getRange().getEnd(), diag::err_typecheck_incomplete_tag) |
| 581 | << SS.getRange() << DC; |
| 582 | return true; |
| 583 | } |
| 584 | |
| 585 | assert(DC && "Cannot handle non-computable dependent contexts in lookup"); |
| 586 | |
| 587 | if (!isa<TypeDecl>(DC)) { |
| 588 | SemaRef.Diag(R.getNameLoc(), diag::err_qualified_member_nonclass) |
| 589 | << DC << SS.getRange(); |
| 590 | return true; |
| 591 | } |
| 592 | } |
| 593 | |
| 594 | // The record definition is complete, now look up the member. |
| 595 | SemaRef.LookupQualifiedName(R, DC); |
| 596 | |
| 597 | if (!R.empty()) |
| 598 | return false; |
| 599 | |
| 600 | // We didn't find anything with the given name, so try to correct |
| 601 | // for typos. |
| 602 | DeclarationName Name = R.getLookupName(); |
Kaelyn Uhrain | e4c7f90 | 2012-01-13 21:28:55 +0000 | [diff] [blame] | 603 | RecordMemberExprValidatorCCC Validator; |
Douglas Gregor | d8bba9c | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 604 | TypoCorrection Corrected = SemaRef.CorrectTypo(R.getLookupNameInfo(), |
| 605 | R.getLookupKind(), NULL, |
Kaelyn Uhrain | 16e46dd | 2012-01-31 23:49:25 +0000 | [diff] [blame] | 606 | &SS, Validator, DC); |
Douglas Gregor | d8bba9c | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 607 | R.clear(); |
Nick Lewycky | d9de51f | 2013-05-07 22:14:37 +0000 | [diff] [blame] | 608 | if (Corrected.isResolved() && !Corrected.isKeyword()) { |
Douglas Gregor | d8bba9c | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 609 | std::string CorrectedStr( |
David Blaikie | 4e4d084 | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 610 | Corrected.getAsString(SemaRef.getLangOpts())); |
Douglas Gregor | d8bba9c | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 611 | std::string CorrectedQuotedStr( |
David Blaikie | 4e4d084 | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 612 | Corrected.getQuoted(SemaRef.getLangOpts())); |
Nick Lewycky | d9de51f | 2013-05-07 22:14:37 +0000 | [diff] [blame] | 613 | |
Douglas Gregor | d8bba9c | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 614 | R.setLookupName(Corrected.getCorrection()); |
Nick Lewycky | d9de51f | 2013-05-07 22:14:37 +0000 | [diff] [blame] | 615 | for (TypoCorrection::decl_iterator DI = Corrected.begin(), |
| 616 | DIEnd = Corrected.end(); |
| 617 | DI != DIEnd; ++DI) { |
| 618 | R.addDecl(*DI); |
| 619 | } |
| 620 | R.resolveKind(); |
| 621 | |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 622 | SemaRef.Diag(R.getNameLoc(), diag::err_no_member_suggest) |
Douglas Gregor | d8bba9c | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 623 | << Name << DC << CorrectedQuotedStr << SS.getRange() |
David Blaikie | 6952c01 | 2012-10-12 20:00:44 +0000 | [diff] [blame] | 624 | << FixItHint::CreateReplacement(Corrected.getCorrectionRange(), |
| 625 | CorrectedStr); |
Nick Lewycky | d9de51f | 2013-05-07 22:14:37 +0000 | [diff] [blame] | 626 | |
| 627 | // If we're typo-correcting to an overloaded name, we don't yet have enough |
| 628 | // information to do overload resolution, so we don't know which previous |
| 629 | // declaration to point to. |
| 630 | if (!Corrected.isOverloaded()) { |
| 631 | NamedDecl *ND = Corrected.getCorrectionDecl(); |
| 632 | SemaRef.Diag(ND->getLocation(), diag::note_previous_decl) |
| 633 | << ND->getDeclName(); |
| 634 | } |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 635 | } |
| 636 | |
| 637 | return false; |
| 638 | } |
| 639 | |
| 640 | ExprResult |
| 641 | Sema::BuildMemberReferenceExpr(Expr *Base, QualType BaseType, |
| 642 | SourceLocation OpLoc, bool IsArrow, |
| 643 | CXXScopeSpec &SS, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 644 | SourceLocation TemplateKWLoc, |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 645 | NamedDecl *FirstQualifierInScope, |
| 646 | const DeclarationNameInfo &NameInfo, |
| 647 | const TemplateArgumentListInfo *TemplateArgs) { |
| 648 | if (BaseType->isDependentType() || |
| 649 | (SS.isSet() && isDependentScopeSpecifier(SS))) |
| 650 | return ActOnDependentMemberExpr(Base, BaseType, |
| 651 | IsArrow, OpLoc, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 652 | SS, TemplateKWLoc, FirstQualifierInScope, |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 653 | NameInfo, TemplateArgs); |
| 654 | |
| 655 | LookupResult R(*this, NameInfo, LookupMemberName); |
| 656 | |
| 657 | // Implicit member accesses. |
| 658 | if (!Base) { |
| 659 | QualType RecordTy = BaseType; |
| 660 | if (IsArrow) RecordTy = RecordTy->getAs<PointerType>()->getPointeeType(); |
| 661 | if (LookupMemberExprInRecord(*this, R, SourceRange(), |
| 662 | RecordTy->getAs<RecordType>(), |
| 663 | OpLoc, SS, TemplateArgs != 0)) |
| 664 | return ExprError(); |
| 665 | |
| 666 | // Explicit member accesses. |
| 667 | } else { |
| 668 | ExprResult BaseResult = Owned(Base); |
| 669 | ExprResult Result = |
| 670 | LookupMemberExpr(R, BaseResult, IsArrow, OpLoc, |
| 671 | SS, /*ObjCImpDecl*/ 0, TemplateArgs != 0); |
| 672 | |
| 673 | if (BaseResult.isInvalid()) |
| 674 | return ExprError(); |
| 675 | Base = BaseResult.take(); |
| 676 | |
| 677 | if (Result.isInvalid()) { |
| 678 | Owned(Base); |
| 679 | return ExprError(); |
| 680 | } |
| 681 | |
| 682 | if (Result.get()) |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 683 | return Result; |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 684 | |
| 685 | // LookupMemberExpr can modify Base, and thus change BaseType |
| 686 | BaseType = Base->getType(); |
| 687 | } |
| 688 | |
| 689 | return BuildMemberReferenceExpr(Base, BaseType, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 690 | OpLoc, IsArrow, SS, TemplateKWLoc, |
| 691 | FirstQualifierInScope, R, TemplateArgs); |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 692 | } |
| 693 | |
| 694 | static ExprResult |
| 695 | BuildFieldReferenceExpr(Sema &S, Expr *BaseExpr, bool IsArrow, |
| 696 | const CXXScopeSpec &SS, FieldDecl *Field, |
| 697 | DeclAccessPair FoundDecl, |
| 698 | const DeclarationNameInfo &MemberNameInfo); |
| 699 | |
| 700 | ExprResult |
| 701 | Sema::BuildAnonymousStructUnionMemberReference(const CXXScopeSpec &SS, |
| 702 | SourceLocation loc, |
| 703 | IndirectFieldDecl *indirectField, |
| 704 | Expr *baseObjectExpr, |
| 705 | SourceLocation opLoc) { |
| 706 | // First, build the expression that refers to the base object. |
| 707 | |
| 708 | bool baseObjectIsPointer = false; |
| 709 | Qualifiers baseQuals; |
| 710 | |
| 711 | // Case 1: the base of the indirect field is not a field. |
| 712 | VarDecl *baseVariable = indirectField->getVarDecl(); |
| 713 | CXXScopeSpec EmptySS; |
| 714 | if (baseVariable) { |
| 715 | assert(baseVariable->getType()->isRecordType()); |
| 716 | |
| 717 | // In principle we could have a member access expression that |
| 718 | // accesses an anonymous struct/union that's a static member of |
| 719 | // the base object's class. However, under the current standard, |
| 720 | // static data members cannot be anonymous structs or unions. |
| 721 | // Supporting this is as easy as building a MemberExpr here. |
| 722 | assert(!baseObjectExpr && "anonymous struct/union is static data member?"); |
| 723 | |
| 724 | DeclarationNameInfo baseNameInfo(DeclarationName(), loc); |
| 725 | |
| 726 | ExprResult result |
| 727 | = BuildDeclarationNameExpr(EmptySS, baseNameInfo, baseVariable); |
| 728 | if (result.isInvalid()) return ExprError(); |
| 729 | |
| 730 | baseObjectExpr = result.take(); |
| 731 | baseObjectIsPointer = false; |
| 732 | baseQuals = baseObjectExpr->getType().getQualifiers(); |
| 733 | |
| 734 | // Case 2: the base of the indirect field is a field and the user |
| 735 | // wrote a member expression. |
| 736 | } else if (baseObjectExpr) { |
| 737 | // The caller provided the base object expression. Determine |
| 738 | // whether its a pointer and whether it adds any qualifiers to the |
| 739 | // anonymous struct/union fields we're looking into. |
| 740 | QualType objectType = baseObjectExpr->getType(); |
| 741 | |
| 742 | if (const PointerType *ptr = objectType->getAs<PointerType>()) { |
| 743 | baseObjectIsPointer = true; |
| 744 | objectType = ptr->getPointeeType(); |
| 745 | } else { |
| 746 | baseObjectIsPointer = false; |
| 747 | } |
| 748 | baseQuals = objectType.getQualifiers(); |
| 749 | |
| 750 | // Case 3: the base of the indirect field is a field and we should |
| 751 | // build an implicit member access. |
| 752 | } else { |
| 753 | // We've found a member of an anonymous struct/union that is |
| 754 | // inside a non-anonymous struct/union, so in a well-formed |
| 755 | // program our base object expression is "this". |
Douglas Gregor | 341350e | 2011-10-18 16:47:30 +0000 | [diff] [blame] | 756 | QualType ThisTy = getCurrentThisType(); |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 757 | if (ThisTy.isNull()) { |
| 758 | Diag(loc, diag::err_invalid_member_use_in_static_method) |
| 759 | << indirectField->getDeclName(); |
| 760 | return ExprError(); |
| 761 | } |
| 762 | |
| 763 | // Our base object expression is "this". |
Eli Friedman | 72899c3 | 2012-01-07 04:59:52 +0000 | [diff] [blame] | 764 | CheckCXXThisCapture(loc); |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 765 | baseObjectExpr |
| 766 | = new (Context) CXXThisExpr(loc, ThisTy, /*isImplicit=*/ true); |
| 767 | baseObjectIsPointer = true; |
| 768 | baseQuals = ThisTy->castAs<PointerType>()->getPointeeType().getQualifiers(); |
| 769 | } |
| 770 | |
| 771 | // Build the implicit member references to the field of the |
| 772 | // anonymous struct/union. |
| 773 | Expr *result = baseObjectExpr; |
| 774 | IndirectFieldDecl::chain_iterator |
| 775 | FI = indirectField->chain_begin(), FEnd = indirectField->chain_end(); |
| 776 | |
| 777 | // Build the first member access in the chain with full information. |
| 778 | if (!baseVariable) { |
| 779 | FieldDecl *field = cast<FieldDecl>(*FI); |
| 780 | |
| 781 | // FIXME: use the real found-decl info! |
| 782 | DeclAccessPair foundDecl = DeclAccessPair::make(field, field->getAccess()); |
| 783 | |
| 784 | // Make a nameInfo that properly uses the anonymous name. |
| 785 | DeclarationNameInfo memberNameInfo(field->getDeclName(), loc); |
| 786 | |
| 787 | result = BuildFieldReferenceExpr(*this, result, baseObjectIsPointer, |
| 788 | EmptySS, field, foundDecl, |
| 789 | memberNameInfo).take(); |
| 790 | baseObjectIsPointer = false; |
| 791 | |
| 792 | // FIXME: check qualified member access |
| 793 | } |
| 794 | |
| 795 | // In all cases, we should now skip the first declaration in the chain. |
| 796 | ++FI; |
| 797 | |
| 798 | while (FI != FEnd) { |
| 799 | FieldDecl *field = cast<FieldDecl>(*FI++); |
| 800 | |
| 801 | // FIXME: these are somewhat meaningless |
| 802 | DeclarationNameInfo memberNameInfo(field->getDeclName(), loc); |
| 803 | DeclAccessPair foundDecl = DeclAccessPair::make(field, field->getAccess()); |
| 804 | |
| 805 | result = BuildFieldReferenceExpr(*this, result, /*isarrow*/ false, |
| 806 | (FI == FEnd? SS : EmptySS), field, |
| 807 | foundDecl, memberNameInfo).take(); |
| 808 | } |
| 809 | |
| 810 | return Owned(result); |
| 811 | } |
| 812 | |
John McCall | 76da55d | 2013-04-16 07:28:30 +0000 | [diff] [blame] | 813 | static ExprResult |
| 814 | BuildMSPropertyRefExpr(Sema &S, Expr *BaseExpr, bool IsArrow, |
| 815 | const CXXScopeSpec &SS, |
| 816 | MSPropertyDecl *PD, |
| 817 | const DeclarationNameInfo &NameInfo) { |
| 818 | // Property names are always simple identifiers and therefore never |
| 819 | // require any interesting additional storage. |
| 820 | return new (S.Context) MSPropertyRefExpr(BaseExpr, PD, IsArrow, |
| 821 | S.Context.PseudoObjectTy, VK_LValue, |
| 822 | SS.getWithLocInContext(S.Context), |
| 823 | NameInfo.getLoc()); |
| 824 | } |
| 825 | |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 826 | /// \brief Build a MemberExpr AST node. |
Eli Friedman | 5f2987c | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 827 | static MemberExpr *BuildMemberExpr(Sema &SemaRef, |
| 828 | ASTContext &C, Expr *Base, bool isArrow, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 829 | const CXXScopeSpec &SS, |
| 830 | SourceLocation TemplateKWLoc, |
| 831 | ValueDecl *Member, |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 832 | DeclAccessPair FoundDecl, |
| 833 | const DeclarationNameInfo &MemberNameInfo, |
| 834 | QualType Ty, |
| 835 | ExprValueKind VK, ExprObjectKind OK, |
| 836 | const TemplateArgumentListInfo *TemplateArgs = 0) { |
Richard Smith | 4f87062 | 2011-10-27 22:11:44 +0000 | [diff] [blame] | 837 | assert((!isArrow || Base->isRValue()) && "-> base must be a pointer rvalue"); |
Eli Friedman | 5f2987c | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 838 | MemberExpr *E = |
| 839 | MemberExpr::Create(C, Base, isArrow, SS.getWithLocInContext(C), |
| 840 | TemplateKWLoc, Member, FoundDecl, MemberNameInfo, |
| 841 | TemplateArgs, Ty, VK, OK); |
| 842 | SemaRef.MarkMemberReferenced(E); |
| 843 | return E; |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 844 | } |
| 845 | |
| 846 | ExprResult |
| 847 | Sema::BuildMemberReferenceExpr(Expr *BaseExpr, QualType BaseExprType, |
| 848 | SourceLocation OpLoc, bool IsArrow, |
| 849 | const CXXScopeSpec &SS, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 850 | SourceLocation TemplateKWLoc, |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 851 | NamedDecl *FirstQualifierInScope, |
| 852 | LookupResult &R, |
Kaelyn Uhrain | 2b90f76 | 2012-04-25 19:49:54 +0000 | [diff] [blame] | 853 | const TemplateArgumentListInfo *TemplateArgs, |
| 854 | bool SuppressQualifierCheck, |
| 855 | ActOnMemberAccessExtraArgs *ExtraArgs) { |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 856 | QualType BaseType = BaseExprType; |
| 857 | if (IsArrow) { |
| 858 | assert(BaseType->isPointerType()); |
John McCall | 3c3b7f9 | 2011-10-25 17:37:35 +0000 | [diff] [blame] | 859 | BaseType = BaseType->castAs<PointerType>()->getPointeeType(); |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 860 | } |
| 861 | R.setBaseObjectType(BaseType); |
| 862 | |
| 863 | const DeclarationNameInfo &MemberNameInfo = R.getLookupNameInfo(); |
| 864 | DeclarationName MemberName = MemberNameInfo.getName(); |
| 865 | SourceLocation MemberLoc = MemberNameInfo.getLoc(); |
| 866 | |
| 867 | if (R.isAmbiguous()) |
| 868 | return ExprError(); |
| 869 | |
| 870 | if (R.empty()) { |
| 871 | // Rederive where we looked up. |
| 872 | DeclContext *DC = (SS.isSet() |
| 873 | ? computeDeclContext(SS, false) |
| 874 | : BaseType->getAs<RecordType>()->getDecl()); |
| 875 | |
Kaelyn Uhrain | 2b90f76 | 2012-04-25 19:49:54 +0000 | [diff] [blame] | 876 | if (ExtraArgs) { |
| 877 | ExprResult RetryExpr; |
| 878 | if (!IsArrow && BaseExpr) { |
Kaelyn Uhrain | 111263c | 2012-05-01 01:17:53 +0000 | [diff] [blame] | 879 | SFINAETrap Trap(*this, true); |
Kaelyn Uhrain | 2b90f76 | 2012-04-25 19:49:54 +0000 | [diff] [blame] | 880 | ParsedType ObjectType; |
| 881 | bool MayBePseudoDestructor = false; |
| 882 | RetryExpr = ActOnStartCXXMemberReference(getCurScope(), BaseExpr, |
| 883 | OpLoc, tok::arrow, ObjectType, |
| 884 | MayBePseudoDestructor); |
| 885 | if (RetryExpr.isUsable() && !Trap.hasErrorOccurred()) { |
| 886 | CXXScopeSpec TempSS(SS); |
| 887 | RetryExpr = ActOnMemberAccessExpr( |
| 888 | ExtraArgs->S, RetryExpr.get(), OpLoc, tok::arrow, TempSS, |
| 889 | TemplateKWLoc, ExtraArgs->Id, ExtraArgs->ObjCImpDecl, |
| 890 | ExtraArgs->HasTrailingLParen); |
| 891 | } |
| 892 | if (Trap.hasErrorOccurred()) |
| 893 | RetryExpr = ExprError(); |
| 894 | } |
| 895 | if (RetryExpr.isUsable()) { |
| 896 | Diag(OpLoc, diag::err_no_member_overloaded_arrow) |
| 897 | << MemberName << DC << FixItHint::CreateReplacement(OpLoc, "->"); |
| 898 | return RetryExpr; |
| 899 | } |
| 900 | } |
| 901 | |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 902 | Diag(R.getNameLoc(), diag::err_no_member) |
| 903 | << MemberName << DC |
| 904 | << (BaseExpr ? BaseExpr->getSourceRange() : SourceRange()); |
| 905 | return ExprError(); |
| 906 | } |
| 907 | |
| 908 | // Diagnose lookups that find only declarations from a non-base |
| 909 | // type. This is possible for either qualified lookups (which may |
| 910 | // have been qualified with an unrelated type) or implicit member |
| 911 | // expressions (which were found with unqualified lookup and thus |
| 912 | // may have come from an enclosing scope). Note that it's okay for |
| 913 | // lookup to find declarations from a non-base type as long as those |
| 914 | // aren't the ones picked by overload resolution. |
| 915 | if ((SS.isSet() || !BaseExpr || |
| 916 | (isa<CXXThisExpr>(BaseExpr) && |
| 917 | cast<CXXThisExpr>(BaseExpr)->isImplicit())) && |
| 918 | !SuppressQualifierCheck && |
| 919 | CheckQualifiedMemberReference(BaseExpr, BaseType, SS, R)) |
| 920 | return ExprError(); |
Fariborz Jahanian | d125050 | 2011-10-17 21:00:22 +0000 | [diff] [blame] | 921 | |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 922 | // Construct an unresolved result if we in fact got an unresolved |
| 923 | // result. |
| 924 | if (R.isOverloadedResult() || R.isUnresolvableResult()) { |
| 925 | // Suppress any lookup-related diagnostics; we'll do these when we |
| 926 | // pick a member. |
| 927 | R.suppressDiagnostics(); |
| 928 | |
| 929 | UnresolvedMemberExpr *MemExpr |
| 930 | = UnresolvedMemberExpr::Create(Context, R.isUnresolvableResult(), |
| 931 | BaseExpr, BaseExprType, |
| 932 | IsArrow, OpLoc, |
| 933 | SS.getWithLocInContext(Context), |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 934 | TemplateKWLoc, MemberNameInfo, |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 935 | TemplateArgs, R.begin(), R.end()); |
| 936 | |
| 937 | return Owned(MemExpr); |
| 938 | } |
| 939 | |
| 940 | assert(R.isSingleResult()); |
| 941 | DeclAccessPair FoundDecl = R.begin().getPair(); |
| 942 | NamedDecl *MemberDecl = R.getFoundDecl(); |
| 943 | |
| 944 | // FIXME: diagnose the presence of template arguments now. |
| 945 | |
| 946 | // If the decl being referenced had an error, return an error for this |
| 947 | // sub-expr without emitting another error, in order to avoid cascading |
| 948 | // error cases. |
| 949 | if (MemberDecl->isInvalidDecl()) |
| 950 | return ExprError(); |
| 951 | |
| 952 | // Handle the implicit-member-access case. |
| 953 | if (!BaseExpr) { |
| 954 | // If this is not an instance member, convert to a non-member access. |
| 955 | if (!MemberDecl->isCXXInstanceMember()) |
| 956 | return BuildDeclarationNameExpr(SS, R.getLookupNameInfo(), MemberDecl); |
| 957 | |
| 958 | SourceLocation Loc = R.getNameLoc(); |
| 959 | if (SS.getRange().isValid()) |
| 960 | Loc = SS.getRange().getBegin(); |
Eli Friedman | 72899c3 | 2012-01-07 04:59:52 +0000 | [diff] [blame] | 961 | CheckCXXThisCapture(Loc); |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 962 | BaseExpr = new (Context) CXXThisExpr(Loc, BaseExprType,/*isImplicit=*/true); |
| 963 | } |
| 964 | |
| 965 | bool ShouldCheckUse = true; |
| 966 | if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(MemberDecl)) { |
| 967 | // Don't diagnose the use of a virtual member function unless it's |
| 968 | // explicitly qualified. |
| 969 | if (MD->isVirtual() && !SS.isSet()) |
| 970 | ShouldCheckUse = false; |
| 971 | } |
| 972 | |
| 973 | // Check the use of this member. |
| 974 | if (ShouldCheckUse && DiagnoseUseOfDecl(MemberDecl, MemberLoc)) { |
| 975 | Owned(BaseExpr); |
| 976 | return ExprError(); |
| 977 | } |
| 978 | |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 979 | if (FieldDecl *FD = dyn_cast<FieldDecl>(MemberDecl)) |
| 980 | return BuildFieldReferenceExpr(*this, BaseExpr, IsArrow, |
| 981 | SS, FD, FoundDecl, MemberNameInfo); |
| 982 | |
John McCall | 76da55d | 2013-04-16 07:28:30 +0000 | [diff] [blame] | 983 | if (MSPropertyDecl *PD = dyn_cast<MSPropertyDecl>(MemberDecl)) |
| 984 | return BuildMSPropertyRefExpr(*this, BaseExpr, IsArrow, SS, PD, |
| 985 | MemberNameInfo); |
| 986 | |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 987 | if (IndirectFieldDecl *FD = dyn_cast<IndirectFieldDecl>(MemberDecl)) |
| 988 | // We may have found a field within an anonymous union or struct |
| 989 | // (C++ [class.union]). |
| 990 | return BuildAnonymousStructUnionMemberReference(SS, MemberLoc, FD, |
| 991 | BaseExpr, OpLoc); |
| 992 | |
| 993 | if (VarDecl *Var = dyn_cast<VarDecl>(MemberDecl)) { |
Eli Friedman | 5f2987c | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 994 | return Owned(BuildMemberExpr(*this, Context, BaseExpr, IsArrow, SS, |
| 995 | TemplateKWLoc, Var, FoundDecl, MemberNameInfo, |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 996 | Var->getType().getNonReferenceType(), |
| 997 | VK_LValue, OK_Ordinary)); |
| 998 | } |
| 999 | |
| 1000 | if (CXXMethodDecl *MemberFn = dyn_cast<CXXMethodDecl>(MemberDecl)) { |
| 1001 | ExprValueKind valueKind; |
| 1002 | QualType type; |
| 1003 | if (MemberFn->isInstance()) { |
| 1004 | valueKind = VK_RValue; |
| 1005 | type = Context.BoundMemberTy; |
| 1006 | } else { |
| 1007 | valueKind = VK_LValue; |
| 1008 | type = MemberFn->getType(); |
| 1009 | } |
| 1010 | |
Eli Friedman | 5f2987c | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 1011 | return Owned(BuildMemberExpr(*this, Context, BaseExpr, IsArrow, SS, |
| 1012 | TemplateKWLoc, MemberFn, FoundDecl, |
| 1013 | MemberNameInfo, type, valueKind, |
| 1014 | OK_Ordinary)); |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 1015 | } |
| 1016 | assert(!isa<FunctionDecl>(MemberDecl) && "member function not C++ method?"); |
| 1017 | |
| 1018 | if (EnumConstantDecl *Enum = dyn_cast<EnumConstantDecl>(MemberDecl)) { |
Eli Friedman | 5f2987c | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 1019 | return Owned(BuildMemberExpr(*this, Context, BaseExpr, IsArrow, SS, |
| 1020 | TemplateKWLoc, Enum, FoundDecl, MemberNameInfo, |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 1021 | Enum->getType(), VK_RValue, OK_Ordinary)); |
| 1022 | } |
| 1023 | |
| 1024 | Owned(BaseExpr); |
| 1025 | |
| 1026 | // We found something that we didn't expect. Complain. |
| 1027 | if (isa<TypeDecl>(MemberDecl)) |
| 1028 | Diag(MemberLoc, diag::err_typecheck_member_reference_type) |
| 1029 | << MemberName << BaseType << int(IsArrow); |
| 1030 | else |
| 1031 | Diag(MemberLoc, diag::err_typecheck_member_reference_unknown) |
| 1032 | << MemberName << BaseType << int(IsArrow); |
| 1033 | |
| 1034 | Diag(MemberDecl->getLocation(), diag::note_member_declared_here) |
| 1035 | << MemberName; |
| 1036 | R.suppressDiagnostics(); |
| 1037 | return ExprError(); |
| 1038 | } |
| 1039 | |
| 1040 | /// Given that normal member access failed on the given expression, |
| 1041 | /// and given that the expression's type involves builtin-id or |
| 1042 | /// builtin-Class, decide whether substituting in the redefinition |
| 1043 | /// types would be profitable. The redefinition type is whatever |
| 1044 | /// this translation unit tried to typedef to id/Class; we store |
| 1045 | /// it to the side and then re-use it in places like this. |
| 1046 | static bool ShouldTryAgainWithRedefinitionType(Sema &S, ExprResult &base) { |
| 1047 | const ObjCObjectPointerType *opty |
| 1048 | = base.get()->getType()->getAs<ObjCObjectPointerType>(); |
| 1049 | if (!opty) return false; |
| 1050 | |
| 1051 | const ObjCObjectType *ty = opty->getObjectType(); |
| 1052 | |
| 1053 | QualType redef; |
| 1054 | if (ty->isObjCId()) { |
Douglas Gregor | 01a4cf1 | 2011-08-11 20:58:55 +0000 | [diff] [blame] | 1055 | redef = S.Context.getObjCIdRedefinitionType(); |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 1056 | } else if (ty->isObjCClass()) { |
Douglas Gregor | 01a4cf1 | 2011-08-11 20:58:55 +0000 | [diff] [blame] | 1057 | redef = S.Context.getObjCClassRedefinitionType(); |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 1058 | } else { |
| 1059 | return false; |
| 1060 | } |
| 1061 | |
| 1062 | // Do the substitution as long as the redefinition type isn't just a |
| 1063 | // possibly-qualified pointer to builtin-id or builtin-Class again. |
| 1064 | opty = redef->getAs<ObjCObjectPointerType>(); |
Richard Trieu | 47fcbba | 2012-10-12 17:48:40 +0000 | [diff] [blame] | 1065 | if (opty && !opty->getObjectType()->getInterface()) |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 1066 | return false; |
| 1067 | |
| 1068 | base = S.ImpCastExprToType(base.take(), redef, CK_BitCast); |
| 1069 | return true; |
| 1070 | } |
| 1071 | |
John McCall | 6dbba4f | 2011-10-11 23:14:30 +0000 | [diff] [blame] | 1072 | static bool isRecordType(QualType T) { |
| 1073 | return T->isRecordType(); |
| 1074 | } |
| 1075 | static bool isPointerToRecordType(QualType T) { |
| 1076 | if (const PointerType *PT = T->getAs<PointerType>()) |
| 1077 | return PT->getPointeeType()->isRecordType(); |
| 1078 | return false; |
| 1079 | } |
| 1080 | |
Richard Smith | 9138b4e | 2011-10-26 19:06:56 +0000 | [diff] [blame] | 1081 | /// Perform conversions on the LHS of a member access expression. |
| 1082 | ExprResult |
| 1083 | Sema::PerformMemberExprBaseConversion(Expr *Base, bool IsArrow) { |
Eli Friedman | 059d578 | 2012-01-13 02:20:01 +0000 | [diff] [blame] | 1084 | if (IsArrow && !Base->getType()->isFunctionType()) |
| 1085 | return DefaultFunctionArrayLvalueConversion(Base); |
Richard Smith | 9138b4e | 2011-10-26 19:06:56 +0000 | [diff] [blame] | 1086 | |
Eli Friedman | 059d578 | 2012-01-13 02:20:01 +0000 | [diff] [blame] | 1087 | return CheckPlaceholderExpr(Base); |
Richard Smith | 9138b4e | 2011-10-26 19:06:56 +0000 | [diff] [blame] | 1088 | } |
| 1089 | |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 1090 | /// Look up the given member of the given non-type-dependent |
| 1091 | /// expression. This can return in one of two ways: |
| 1092 | /// * If it returns a sentinel null-but-valid result, the caller will |
| 1093 | /// assume that lookup was performed and the results written into |
| 1094 | /// the provided structure. It will take over from there. |
| 1095 | /// * Otherwise, the returned expression will be produced in place of |
| 1096 | /// an ordinary member expression. |
| 1097 | /// |
| 1098 | /// The ObjCImpDecl bit is a gross hack that will need to be properly |
| 1099 | /// fixed for ObjC++. |
| 1100 | ExprResult |
| 1101 | Sema::LookupMemberExpr(LookupResult &R, ExprResult &BaseExpr, |
| 1102 | bool &IsArrow, SourceLocation OpLoc, |
| 1103 | CXXScopeSpec &SS, |
| 1104 | Decl *ObjCImpDecl, bool HasTemplateArgs) { |
| 1105 | assert(BaseExpr.get() && "no base expression"); |
| 1106 | |
| 1107 | // Perform default conversions. |
Richard Smith | 9138b4e | 2011-10-26 19:06:56 +0000 | [diff] [blame] | 1108 | BaseExpr = PerformMemberExprBaseConversion(BaseExpr.take(), IsArrow); |
John McCall | 6dbba4f | 2011-10-11 23:14:30 +0000 | [diff] [blame] | 1109 | if (BaseExpr.isInvalid()) |
| 1110 | return ExprError(); |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 1111 | |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 1112 | QualType BaseType = BaseExpr.get()->getType(); |
| 1113 | assert(!BaseType->isDependentType()); |
| 1114 | |
| 1115 | DeclarationName MemberName = R.getLookupName(); |
| 1116 | SourceLocation MemberLoc = R.getNameLoc(); |
| 1117 | |
| 1118 | // For later type-checking purposes, turn arrow accesses into dot |
| 1119 | // accesses. The only access type we support that doesn't follow |
| 1120 | // the C equivalence "a->b === (*a).b" is ObjC property accesses, |
| 1121 | // and those never use arrows, so this is unaffected. |
| 1122 | if (IsArrow) { |
| 1123 | if (const PointerType *Ptr = BaseType->getAs<PointerType>()) |
| 1124 | BaseType = Ptr->getPointeeType(); |
| 1125 | else if (const ObjCObjectPointerType *Ptr |
| 1126 | = BaseType->getAs<ObjCObjectPointerType>()) |
| 1127 | BaseType = Ptr->getPointeeType(); |
| 1128 | else if (BaseType->isRecordType()) { |
| 1129 | // Recover from arrow accesses to records, e.g.: |
| 1130 | // struct MyRecord foo; |
| 1131 | // foo->bar |
| 1132 | // This is actually well-formed in C++ if MyRecord has an |
| 1133 | // overloaded operator->, but that should have been dealt with |
| 1134 | // by now. |
| 1135 | Diag(OpLoc, diag::err_typecheck_member_reference_suggestion) |
| 1136 | << BaseType << int(IsArrow) << BaseExpr.get()->getSourceRange() |
| 1137 | << FixItHint::CreateReplacement(OpLoc, "."); |
| 1138 | IsArrow = false; |
Eli Friedman | 059d578 | 2012-01-13 02:20:01 +0000 | [diff] [blame] | 1139 | } else if (BaseType->isFunctionType()) { |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 1140 | goto fail; |
| 1141 | } else { |
| 1142 | Diag(MemberLoc, diag::err_typecheck_member_reference_arrow) |
| 1143 | << BaseType << BaseExpr.get()->getSourceRange(); |
| 1144 | return ExprError(); |
| 1145 | } |
| 1146 | } |
| 1147 | |
| 1148 | // Handle field access to simple records. |
| 1149 | if (const RecordType *RTy = BaseType->getAs<RecordType>()) { |
| 1150 | if (LookupMemberExprInRecord(*this, R, BaseExpr.get()->getSourceRange(), |
| 1151 | RTy, OpLoc, SS, HasTemplateArgs)) |
| 1152 | return ExprError(); |
| 1153 | |
| 1154 | // Returning valid-but-null is how we indicate to the caller that |
| 1155 | // the lookup result was filled in. |
| 1156 | return Owned((Expr*) 0); |
| 1157 | } |
| 1158 | |
| 1159 | // Handle ivar access to Objective-C objects. |
| 1160 | if (const ObjCObjectType *OTy = BaseType->getAs<ObjCObjectType>()) { |
Douglas Gregor | 5a706dc | 2011-10-10 16:09:49 +0000 | [diff] [blame] | 1161 | if (!SS.isEmpty() && !SS.isInvalid()) { |
Douglas Gregor | b5ae92f | 2011-10-09 23:22:49 +0000 | [diff] [blame] | 1162 | Diag(SS.getRange().getBegin(), diag::err_qualified_objc_access) |
| 1163 | << 1 << SS.getScopeRep() |
| 1164 | << FixItHint::CreateRemoval(SS.getRange()); |
| 1165 | SS.clear(); |
| 1166 | } |
| 1167 | |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 1168 | IdentifierInfo *Member = MemberName.getAsIdentifierInfo(); |
| 1169 | |
| 1170 | // There are three cases for the base type: |
| 1171 | // - builtin id (qualified or unqualified) |
| 1172 | // - builtin Class (qualified or unqualified) |
| 1173 | // - an interface |
| 1174 | ObjCInterfaceDecl *IDecl = OTy->getInterface(); |
| 1175 | if (!IDecl) { |
David Blaikie | 4e4d084 | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 1176 | if (getLangOpts().ObjCAutoRefCount && |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 1177 | (OTy->isObjCId() || OTy->isObjCClass())) |
| 1178 | goto fail; |
| 1179 | // There's an implicit 'isa' ivar on all objects. |
| 1180 | // But we only actually find it this way on objects of type 'id', |
Eric Christopher | 2502ec8 | 2012-08-16 23:50:37 +0000 | [diff] [blame] | 1181 | // apparently. |
Fariborz Jahanian | 7e35274 | 2013-03-27 21:19:25 +0000 | [diff] [blame] | 1182 | if (OTy->isObjCId() && Member->isStr("isa")) |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 1183 | return Owned(new (Context) ObjCIsaExpr(BaseExpr.take(), IsArrow, MemberLoc, |
Fariborz Jahanian | ec8deba | 2013-03-28 19:50:55 +0000 | [diff] [blame] | 1184 | OpLoc, |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 1185 | Context.getObjCClassType())); |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 1186 | if (ShouldTryAgainWithRedefinitionType(*this, BaseExpr)) |
| 1187 | return LookupMemberExpr(R, BaseExpr, IsArrow, OpLoc, SS, |
| 1188 | ObjCImpDecl, HasTemplateArgs); |
| 1189 | goto fail; |
| 1190 | } |
Fariborz Jahanian | 0910059 | 2012-06-21 21:35:15 +0000 | [diff] [blame] | 1191 | |
Douglas Gregor | d10099e | 2012-05-04 16:32:21 +0000 | [diff] [blame] | 1192 | if (RequireCompleteType(OpLoc, BaseType, diag::err_typecheck_incomplete_tag, |
| 1193 | BaseExpr.get())) |
Douglas Gregor | d07cc36 | 2012-01-02 17:18:37 +0000 | [diff] [blame] | 1194 | return ExprError(); |
| 1195 | |
Ted Kremenek | 2c085ed | 2012-03-17 00:53:39 +0000 | [diff] [blame] | 1196 | ObjCInterfaceDecl *ClassDeclared = 0; |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 1197 | ObjCIvarDecl *IV = IDecl->lookupInstanceVariable(Member, ClassDeclared); |
| 1198 | |
| 1199 | if (!IV) { |
| 1200 | // Attempt to correct for typos in ivar names. |
Kaelyn Uhrain | e4c7f90 | 2012-01-13 21:28:55 +0000 | [diff] [blame] | 1201 | DeclFilterCCC<ObjCIvarDecl> Validator; |
| 1202 | Validator.IsObjCIvarLookup = IsArrow; |
| 1203 | if (TypoCorrection Corrected = CorrectTypo(R.getLookupNameInfo(), |
| 1204 | LookupMemberName, NULL, NULL, |
Kaelyn Uhrain | 16e46dd | 2012-01-31 23:49:25 +0000 | [diff] [blame] | 1205 | Validator, IDecl)) { |
Kaelyn Uhrain | e4c7f90 | 2012-01-13 21:28:55 +0000 | [diff] [blame] | 1206 | IV = Corrected.getCorrectionDeclAs<ObjCIvarDecl>(); |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 1207 | Diag(R.getNameLoc(), |
| 1208 | diag::err_typecheck_member_reference_ivar_suggest) |
| 1209 | << IDecl->getDeclName() << MemberName << IV->getDeclName() |
| 1210 | << FixItHint::CreateReplacement(R.getNameLoc(), |
| 1211 | IV->getNameAsString()); |
| 1212 | Diag(IV->getLocation(), diag::note_previous_decl) |
| 1213 | << IV->getDeclName(); |
Ted Kremenek | 2c085ed | 2012-03-17 00:53:39 +0000 | [diff] [blame] | 1214 | |
| 1215 | // Figure out the class that declares the ivar. |
| 1216 | assert(!ClassDeclared); |
| 1217 | Decl *D = cast<Decl>(IV->getDeclContext()); |
| 1218 | if (ObjCCategoryDecl *CAT = dyn_cast<ObjCCategoryDecl>(D)) |
| 1219 | D = CAT->getClassInterface(); |
| 1220 | ClassDeclared = cast<ObjCInterfaceDecl>(D); |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 1221 | } else { |
Fariborz Jahanian | 6326e05 | 2011-06-28 00:00:52 +0000 | [diff] [blame] | 1222 | if (IsArrow && IDecl->FindPropertyDeclaration(Member)) { |
| 1223 | Diag(MemberLoc, |
| 1224 | diag::err_property_found_suggest) |
| 1225 | << Member << BaseExpr.get()->getType() |
| 1226 | << FixItHint::CreateReplacement(OpLoc, "."); |
| 1227 | return ExprError(); |
| 1228 | } |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 1229 | |
| 1230 | Diag(MemberLoc, diag::err_typecheck_member_reference_ivar) |
| 1231 | << IDecl->getDeclName() << MemberName |
| 1232 | << BaseExpr.get()->getSourceRange(); |
| 1233 | return ExprError(); |
| 1234 | } |
| 1235 | } |
Ted Kremenek | 2c085ed | 2012-03-17 00:53:39 +0000 | [diff] [blame] | 1236 | |
| 1237 | assert(ClassDeclared); |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 1238 | |
| 1239 | // If the decl being referenced had an error, return an error for this |
| 1240 | // sub-expr without emitting another error, in order to avoid cascading |
| 1241 | // error cases. |
| 1242 | if (IV->isInvalidDecl()) |
| 1243 | return ExprError(); |
| 1244 | |
| 1245 | // Check whether we can reference this field. |
| 1246 | if (DiagnoseUseOfDecl(IV, MemberLoc)) |
| 1247 | return ExprError(); |
| 1248 | if (IV->getAccessControl() != ObjCIvarDecl::Public && |
| 1249 | IV->getAccessControl() != ObjCIvarDecl::Package) { |
| 1250 | ObjCInterfaceDecl *ClassOfMethodDecl = 0; |
| 1251 | if (ObjCMethodDecl *MD = getCurMethodDecl()) |
| 1252 | ClassOfMethodDecl = MD->getClassInterface(); |
| 1253 | else if (ObjCImpDecl && getCurFunctionDecl()) { |
| 1254 | // Case of a c-function declared inside an objc implementation. |
| 1255 | // FIXME: For a c-style function nested inside an objc implementation |
| 1256 | // class, there is no implementation context available, so we pass |
| 1257 | // down the context as argument to this routine. Ideally, this context |
| 1258 | // need be passed down in the AST node and somehow calculated from the |
| 1259 | // AST for a function decl. |
| 1260 | if (ObjCImplementationDecl *IMPD = |
| 1261 | dyn_cast<ObjCImplementationDecl>(ObjCImpDecl)) |
| 1262 | ClassOfMethodDecl = IMPD->getClassInterface(); |
| 1263 | else if (ObjCCategoryImplDecl* CatImplClass = |
| 1264 | dyn_cast<ObjCCategoryImplDecl>(ObjCImpDecl)) |
| 1265 | ClassOfMethodDecl = CatImplClass->getClassInterface(); |
| 1266 | } |
David Blaikie | 4e4d084 | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 1267 | if (!getLangOpts().DebuggerSupport) { |
Fariborz Jahanian | 458a7fb | 2012-03-07 00:58:41 +0000 | [diff] [blame] | 1268 | if (IV->getAccessControl() == ObjCIvarDecl::Private) { |
| 1269 | if (!declaresSameEntity(ClassDeclared, IDecl) || |
| 1270 | !declaresSameEntity(ClassOfMethodDecl, ClassDeclared)) |
| 1271 | Diag(MemberLoc, diag::error_private_ivar_access) |
| 1272 | << IV->getDeclName(); |
| 1273 | } else if (!IDecl->isSuperClassOf(ClassOfMethodDecl)) |
| 1274 | // @protected |
| 1275 | Diag(MemberLoc, diag::error_protected_ivar_access) |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 1276 | << IV->getDeclName(); |
Fariborz Jahanian | 458a7fb | 2012-03-07 00:58:41 +0000 | [diff] [blame] | 1277 | } |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 1278 | } |
Fariborz Jahanian | b25466e | 2012-08-07 23:48:10 +0000 | [diff] [blame] | 1279 | bool warn = true; |
David Blaikie | 4e4d084 | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 1280 | if (getLangOpts().ObjCAutoRefCount) { |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 1281 | Expr *BaseExp = BaseExpr.get()->IgnoreParenImpCasts(); |
| 1282 | if (UnaryOperator *UO = dyn_cast<UnaryOperator>(BaseExp)) |
| 1283 | if (UO->getOpcode() == UO_Deref) |
| 1284 | BaseExp = UO->getSubExpr()->IgnoreParenCasts(); |
| 1285 | |
| 1286 | if (DeclRefExpr *DE = dyn_cast<DeclRefExpr>(BaseExp)) |
Fariborz Jahanian | b25466e | 2012-08-07 23:48:10 +0000 | [diff] [blame] | 1287 | if (DE->getType().getObjCLifetime() == Qualifiers::OCL_Weak) { |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 1288 | Diag(DE->getLocation(), diag::error_arc_weak_ivar_access); |
Fariborz Jahanian | b25466e | 2012-08-07 23:48:10 +0000 | [diff] [blame] | 1289 | warn = false; |
| 1290 | } |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 1291 | } |
Fariborz Jahanian | ed6662d | 2012-08-08 16:41:04 +0000 | [diff] [blame] | 1292 | if (warn) { |
Fariborz Jahanian | cff863f | 2012-08-07 16:38:44 +0000 | [diff] [blame] | 1293 | if (ObjCMethodDecl *MD = getCurMethodDecl()) { |
| 1294 | ObjCMethodFamily MF = MD->getMethodFamily(); |
| 1295 | warn = (MF != OMF_init && MF != OMF_dealloc && |
Fariborz Jahanian | 2620229 | 2013-02-14 19:07:19 +0000 | [diff] [blame] | 1296 | MF != OMF_finalize && |
| 1297 | !IvarBacksCurrentMethodAccessor(IDecl, MD, IV)); |
Fariborz Jahanian | cff863f | 2012-08-07 16:38:44 +0000 | [diff] [blame] | 1298 | } |
| 1299 | if (warn) |
| 1300 | Diag(MemberLoc, diag::warn_direct_ivar_access) << IV->getDeclName(); |
| 1301 | } |
Jordan Rose | 7a27048 | 2012-09-28 22:21:35 +0000 | [diff] [blame] | 1302 | |
| 1303 | ObjCIvarRefExpr *Result = new (Context) ObjCIvarRefExpr(IV, IV->getType(), |
Fariborz Jahanian | 0c70181 | 2013-04-02 18:57:54 +0000 | [diff] [blame] | 1304 | MemberLoc, OpLoc, |
Jordan Rose | 7a27048 | 2012-09-28 22:21:35 +0000 | [diff] [blame] | 1305 | BaseExpr.take(), |
| 1306 | IsArrow); |
| 1307 | |
| 1308 | if (getLangOpts().ObjCAutoRefCount) { |
| 1309 | if (IV->getType().getObjCLifetime() == Qualifiers::OCL_Weak) { |
| 1310 | DiagnosticsEngine::Level Level = |
| 1311 | Diags.getDiagnosticLevel(diag::warn_arc_repeated_use_of_weak, |
| 1312 | MemberLoc); |
| 1313 | if (Level != DiagnosticsEngine::Ignored) |
Fariborz Jahanian | 569b4ad | 2013-05-21 21:20:26 +0000 | [diff] [blame] | 1314 | recordUseOfEvaluatedWeak(Result); |
Jordan Rose | 7a27048 | 2012-09-28 22:21:35 +0000 | [diff] [blame] | 1315 | } |
| 1316 | } |
| 1317 | |
| 1318 | return Owned(Result); |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 1319 | } |
| 1320 | |
| 1321 | // Objective-C property access. |
| 1322 | const ObjCObjectPointerType *OPT; |
| 1323 | if (!IsArrow && (OPT = BaseType->getAs<ObjCObjectPointerType>())) { |
Douglas Gregor | 5a706dc | 2011-10-10 16:09:49 +0000 | [diff] [blame] | 1324 | if (!SS.isEmpty() && !SS.isInvalid()) { |
Douglas Gregor | b5ae92f | 2011-10-09 23:22:49 +0000 | [diff] [blame] | 1325 | Diag(SS.getRange().getBegin(), diag::err_qualified_objc_access) |
| 1326 | << 0 << SS.getScopeRep() |
| 1327 | << FixItHint::CreateRemoval(SS.getRange()); |
| 1328 | SS.clear(); |
| 1329 | } |
| 1330 | |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 1331 | // This actually uses the base as an r-value. |
| 1332 | BaseExpr = DefaultLvalueConversion(BaseExpr.take()); |
| 1333 | if (BaseExpr.isInvalid()) |
| 1334 | return ExprError(); |
| 1335 | |
| 1336 | assert(Context.hasSameUnqualifiedType(BaseType, BaseExpr.get()->getType())); |
| 1337 | |
| 1338 | IdentifierInfo *Member = MemberName.getAsIdentifierInfo(); |
| 1339 | |
| 1340 | const ObjCObjectType *OT = OPT->getObjectType(); |
| 1341 | |
| 1342 | // id, with and without qualifiers. |
| 1343 | if (OT->isObjCId()) { |
| 1344 | // Check protocols on qualified interfaces. |
| 1345 | Selector Sel = PP.getSelectorTable().getNullarySelector(Member); |
| 1346 | if (Decl *PMDecl = FindGetterSetterNameDecl(OPT, Member, Sel, Context)) { |
| 1347 | if (ObjCPropertyDecl *PD = dyn_cast<ObjCPropertyDecl>(PMDecl)) { |
| 1348 | // Check the use of this declaration |
| 1349 | if (DiagnoseUseOfDecl(PD, MemberLoc)) |
| 1350 | return ExprError(); |
| 1351 | |
John McCall | 3c3b7f9 | 2011-10-25 17:37:35 +0000 | [diff] [blame] | 1352 | return Owned(new (Context) ObjCPropertyRefExpr(PD, |
| 1353 | Context.PseudoObjectTy, |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 1354 | VK_LValue, |
| 1355 | OK_ObjCProperty, |
| 1356 | MemberLoc, |
| 1357 | BaseExpr.take())); |
| 1358 | } |
| 1359 | |
| 1360 | if (ObjCMethodDecl *OMD = dyn_cast<ObjCMethodDecl>(PMDecl)) { |
| 1361 | // Check the use of this method. |
| 1362 | if (DiagnoseUseOfDecl(OMD, MemberLoc)) |
| 1363 | return ExprError(); |
| 1364 | Selector SetterSel = |
Adrian Prantl | 80e8ea9 | 2013-06-07 22:29:12 +0000 | [diff] [blame] | 1365 | SelectorTable::constructSetterSelector(PP.getIdentifierTable(), |
| 1366 | PP.getSelectorTable(), |
| 1367 | Member); |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 1368 | ObjCMethodDecl *SMD = 0; |
| 1369 | if (Decl *SDecl = FindGetterSetterNameDecl(OPT, /*Property id*/0, |
| 1370 | SetterSel, Context)) |
| 1371 | SMD = dyn_cast<ObjCMethodDecl>(SDecl); |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 1372 | |
John McCall | 3c3b7f9 | 2011-10-25 17:37:35 +0000 | [diff] [blame] | 1373 | return Owned(new (Context) ObjCPropertyRefExpr(OMD, SMD, |
| 1374 | Context.PseudoObjectTy, |
| 1375 | VK_LValue, OK_ObjCProperty, |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 1376 | MemberLoc, BaseExpr.take())); |
| 1377 | } |
| 1378 | } |
| 1379 | // Use of id.member can only be for a property reference. Do not |
| 1380 | // use the 'id' redefinition in this case. |
| 1381 | if (IsArrow && ShouldTryAgainWithRedefinitionType(*this, BaseExpr)) |
| 1382 | return LookupMemberExpr(R, BaseExpr, IsArrow, OpLoc, SS, |
| 1383 | ObjCImpDecl, HasTemplateArgs); |
| 1384 | |
| 1385 | return ExprError(Diag(MemberLoc, diag::err_property_not_found) |
| 1386 | << MemberName << BaseType); |
| 1387 | } |
| 1388 | |
| 1389 | // 'Class', unqualified only. |
| 1390 | if (OT->isObjCClass()) { |
| 1391 | // Only works in a method declaration (??!). |
| 1392 | ObjCMethodDecl *MD = getCurMethodDecl(); |
| 1393 | if (!MD) { |
| 1394 | if (ShouldTryAgainWithRedefinitionType(*this, BaseExpr)) |
| 1395 | return LookupMemberExpr(R, BaseExpr, IsArrow, OpLoc, SS, |
| 1396 | ObjCImpDecl, HasTemplateArgs); |
| 1397 | |
| 1398 | goto fail; |
| 1399 | } |
| 1400 | |
| 1401 | // Also must look for a getter name which uses property syntax. |
| 1402 | Selector Sel = PP.getSelectorTable().getNullarySelector(Member); |
| 1403 | ObjCInterfaceDecl *IFace = MD->getClassInterface(); |
| 1404 | ObjCMethodDecl *Getter; |
| 1405 | if ((Getter = IFace->lookupClassMethod(Sel))) { |
| 1406 | // Check the use of this method. |
| 1407 | if (DiagnoseUseOfDecl(Getter, MemberLoc)) |
| 1408 | return ExprError(); |
| 1409 | } else |
| 1410 | Getter = IFace->lookupPrivateMethod(Sel, false); |
| 1411 | // If we found a getter then this may be a valid dot-reference, we |
| 1412 | // will look for the matching setter, in case it is needed. |
| 1413 | Selector SetterSel = |
Adrian Prantl | 80e8ea9 | 2013-06-07 22:29:12 +0000 | [diff] [blame] | 1414 | SelectorTable::constructSetterSelector(PP.getIdentifierTable(), |
| 1415 | PP.getSelectorTable(), |
| 1416 | Member); |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 1417 | ObjCMethodDecl *Setter = IFace->lookupClassMethod(SetterSel); |
| 1418 | if (!Setter) { |
| 1419 | // If this reference is in an @implementation, also check for 'private' |
| 1420 | // methods. |
| 1421 | Setter = IFace->lookupPrivateMethod(SetterSel, false); |
| 1422 | } |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 1423 | |
| 1424 | if (Setter && DiagnoseUseOfDecl(Setter, MemberLoc)) |
| 1425 | return ExprError(); |
| 1426 | |
| 1427 | if (Getter || Setter) { |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 1428 | return Owned(new (Context) ObjCPropertyRefExpr(Getter, Setter, |
John McCall | 3c3b7f9 | 2011-10-25 17:37:35 +0000 | [diff] [blame] | 1429 | Context.PseudoObjectTy, |
| 1430 | VK_LValue, OK_ObjCProperty, |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 1431 | MemberLoc, BaseExpr.take())); |
| 1432 | } |
| 1433 | |
| 1434 | if (ShouldTryAgainWithRedefinitionType(*this, BaseExpr)) |
| 1435 | return LookupMemberExpr(R, BaseExpr, IsArrow, OpLoc, SS, |
| 1436 | ObjCImpDecl, HasTemplateArgs); |
| 1437 | |
| 1438 | return ExprError(Diag(MemberLoc, diag::err_property_not_found) |
| 1439 | << MemberName << BaseType); |
| 1440 | } |
| 1441 | |
| 1442 | // Normal property access. |
Fariborz Jahanian | 6326e05 | 2011-06-28 00:00:52 +0000 | [diff] [blame] | 1443 | return HandleExprPropertyRefExpr(OPT, BaseExpr.get(), OpLoc, |
| 1444 | MemberName, MemberLoc, |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 1445 | SourceLocation(), QualType(), false); |
| 1446 | } |
| 1447 | |
| 1448 | // Handle 'field access' to vectors, such as 'V.xx'. |
| 1449 | if (BaseType->isExtVectorType()) { |
| 1450 | // FIXME: this expr should store IsArrow. |
| 1451 | IdentifierInfo *Member = MemberName.getAsIdentifierInfo(); |
| 1452 | ExprValueKind VK = (IsArrow ? VK_LValue : BaseExpr.get()->getValueKind()); |
| 1453 | QualType ret = CheckExtVectorComponent(*this, BaseType, VK, OpLoc, |
| 1454 | Member, MemberLoc); |
| 1455 | if (ret.isNull()) |
| 1456 | return ExprError(); |
| 1457 | |
| 1458 | return Owned(new (Context) ExtVectorElementExpr(ret, VK, BaseExpr.take(), |
| 1459 | *Member, MemberLoc)); |
| 1460 | } |
| 1461 | |
| 1462 | // Adjust builtin-sel to the appropriate redefinition type if that's |
| 1463 | // not just a pointer to builtin-sel again. |
| 1464 | if (IsArrow && |
| 1465 | BaseType->isSpecificBuiltinType(BuiltinType::ObjCSel) && |
Douglas Gregor | 01a4cf1 | 2011-08-11 20:58:55 +0000 | [diff] [blame] | 1466 | !Context.getObjCSelRedefinitionType()->isObjCSelType()) { |
| 1467 | BaseExpr = ImpCastExprToType(BaseExpr.take(), |
| 1468 | Context.getObjCSelRedefinitionType(), |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 1469 | CK_BitCast); |
| 1470 | return LookupMemberExpr(R, BaseExpr, IsArrow, OpLoc, SS, |
| 1471 | ObjCImpDecl, HasTemplateArgs); |
| 1472 | } |
| 1473 | |
| 1474 | // Failure cases. |
| 1475 | fail: |
| 1476 | |
| 1477 | // Recover from dot accesses to pointers, e.g.: |
| 1478 | // type *foo; |
| 1479 | // foo.bar |
| 1480 | // This is actually well-formed in two cases: |
| 1481 | // - 'type' is an Objective C type |
| 1482 | // - 'bar' is a pseudo-destructor name which happens to refer to |
| 1483 | // the appropriate pointer type |
| 1484 | if (const PointerType *Ptr = BaseType->getAs<PointerType>()) { |
| 1485 | if (!IsArrow && Ptr->getPointeeType()->isRecordType() && |
| 1486 | MemberName.getNameKind() != DeclarationName::CXXDestructorName) { |
| 1487 | Diag(OpLoc, diag::err_typecheck_member_reference_suggestion) |
| 1488 | << BaseType << int(IsArrow) << BaseExpr.get()->getSourceRange() |
| 1489 | << FixItHint::CreateReplacement(OpLoc, "->"); |
| 1490 | |
| 1491 | // Recurse as an -> access. |
| 1492 | IsArrow = true; |
| 1493 | return LookupMemberExpr(R, BaseExpr, IsArrow, OpLoc, SS, |
| 1494 | ObjCImpDecl, HasTemplateArgs); |
| 1495 | } |
| 1496 | } |
| 1497 | |
| 1498 | // If the user is trying to apply -> or . to a function name, it's probably |
| 1499 | // because they forgot parentheses to call that function. |
John McCall | 6dbba4f | 2011-10-11 23:14:30 +0000 | [diff] [blame] | 1500 | if (tryToRecoverWithCall(BaseExpr, |
| 1501 | PDiag(diag::err_member_reference_needs_call), |
| 1502 | /*complain*/ false, |
Eli Friedman | 059d578 | 2012-01-13 02:20:01 +0000 | [diff] [blame] | 1503 | IsArrow ? &isPointerToRecordType : &isRecordType)) { |
John McCall | 6dbba4f | 2011-10-11 23:14:30 +0000 | [diff] [blame] | 1504 | if (BaseExpr.isInvalid()) |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 1505 | return ExprError(); |
John McCall | 6dbba4f | 2011-10-11 23:14:30 +0000 | [diff] [blame] | 1506 | BaseExpr = DefaultFunctionArrayConversion(BaseExpr.take()); |
| 1507 | return LookupMemberExpr(R, BaseExpr, IsArrow, OpLoc, SS, |
| 1508 | ObjCImpDecl, HasTemplateArgs); |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 1509 | } |
| 1510 | |
Matt Beaumont-Gay | 7d90fe5 | 2012-04-21 01:12:48 +0000 | [diff] [blame] | 1511 | Diag(OpLoc, diag::err_typecheck_member_reference_struct_union) |
Matt Beaumont-Gay | 73664a4 | 2012-04-21 02:13:04 +0000 | [diff] [blame] | 1512 | << BaseType << BaseExpr.get()->getSourceRange() << MemberLoc; |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 1513 | |
| 1514 | return ExprError(); |
| 1515 | } |
| 1516 | |
| 1517 | /// The main callback when the parser finds something like |
| 1518 | /// expression . [nested-name-specifier] identifier |
| 1519 | /// expression -> [nested-name-specifier] identifier |
| 1520 | /// where 'identifier' encompasses a fairly broad spectrum of |
| 1521 | /// possibilities, including destructor and operator references. |
| 1522 | /// |
| 1523 | /// \param OpKind either tok::arrow or tok::period |
| 1524 | /// \param HasTrailingLParen whether the next token is '(', which |
| 1525 | /// is used to diagnose mis-uses of special members that can |
| 1526 | /// only be called |
James Dennett | 699c904 | 2012-06-15 07:13:21 +0000 | [diff] [blame] | 1527 | /// \param ObjCImpDecl the current Objective-C \@implementation |
| 1528 | /// decl; this is an ugly hack around the fact that Objective-C |
| 1529 | /// \@implementations aren't properly put in the context chain |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 1530 | ExprResult Sema::ActOnMemberAccessExpr(Scope *S, Expr *Base, |
| 1531 | SourceLocation OpLoc, |
| 1532 | tok::TokenKind OpKind, |
| 1533 | CXXScopeSpec &SS, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 1534 | SourceLocation TemplateKWLoc, |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 1535 | UnqualifiedId &Id, |
| 1536 | Decl *ObjCImpDecl, |
| 1537 | bool HasTrailingLParen) { |
| 1538 | if (SS.isSet() && SS.isInvalid()) |
| 1539 | return ExprError(); |
| 1540 | |
| 1541 | // Warn about the explicit constructor calls Microsoft extension. |
David Blaikie | 4e4d084 | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 1542 | if (getLangOpts().MicrosoftExt && |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 1543 | Id.getKind() == UnqualifiedId::IK_ConstructorName) |
| 1544 | Diag(Id.getSourceRange().getBegin(), |
| 1545 | diag::ext_ms_explicit_constructor_call); |
| 1546 | |
| 1547 | TemplateArgumentListInfo TemplateArgsBuffer; |
| 1548 | |
| 1549 | // Decompose the name into its component parts. |
| 1550 | DeclarationNameInfo NameInfo; |
| 1551 | const TemplateArgumentListInfo *TemplateArgs; |
| 1552 | DecomposeUnqualifiedId(Id, TemplateArgsBuffer, |
| 1553 | NameInfo, TemplateArgs); |
| 1554 | |
| 1555 | DeclarationName Name = NameInfo.getName(); |
| 1556 | bool IsArrow = (OpKind == tok::arrow); |
| 1557 | |
| 1558 | NamedDecl *FirstQualifierInScope |
| 1559 | = (!SS.isSet() ? 0 : FindFirstQualifierInScope(S, |
| 1560 | static_cast<NestedNameSpecifier*>(SS.getScopeRep()))); |
| 1561 | |
| 1562 | // This is a postfix expression, so get rid of ParenListExprs. |
| 1563 | ExprResult Result = MaybeConvertParenListExprToParenExpr(S, Base); |
| 1564 | if (Result.isInvalid()) return ExprError(); |
| 1565 | Base = Result.take(); |
| 1566 | |
| 1567 | if (Base->getType()->isDependentType() || Name.isDependentName() || |
| 1568 | isDependentScopeSpecifier(SS)) { |
| 1569 | Result = ActOnDependentMemberExpr(Base, Base->getType(), |
| 1570 | IsArrow, OpLoc, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 1571 | SS, TemplateKWLoc, FirstQualifierInScope, |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 1572 | NameInfo, TemplateArgs); |
| 1573 | } else { |
| 1574 | LookupResult R(*this, NameInfo, LookupMemberName); |
| 1575 | ExprResult BaseResult = Owned(Base); |
| 1576 | Result = LookupMemberExpr(R, BaseResult, IsArrow, OpLoc, |
| 1577 | SS, ObjCImpDecl, TemplateArgs != 0); |
| 1578 | if (BaseResult.isInvalid()) |
| 1579 | return ExprError(); |
| 1580 | Base = BaseResult.take(); |
| 1581 | |
| 1582 | if (Result.isInvalid()) { |
| 1583 | Owned(Base); |
| 1584 | return ExprError(); |
| 1585 | } |
| 1586 | |
| 1587 | if (Result.get()) { |
| 1588 | // The only way a reference to a destructor can be used is to |
| 1589 | // immediately call it, which falls into this case. If the |
| 1590 | // next token is not a '(', produce a diagnostic and build the |
| 1591 | // call now. |
| 1592 | if (!HasTrailingLParen && |
| 1593 | Id.getKind() == UnqualifiedId::IK_DestructorName) |
| 1594 | return DiagnoseDtorReference(NameInfo.getLoc(), Result.get()); |
| 1595 | |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 1596 | return Result; |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 1597 | } |
| 1598 | |
Kaelyn Uhrain | 2b90f76 | 2012-04-25 19:49:54 +0000 | [diff] [blame] | 1599 | ActOnMemberAccessExtraArgs ExtraArgs = {S, Id, ObjCImpDecl, HasTrailingLParen}; |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 1600 | Result = BuildMemberReferenceExpr(Base, Base->getType(), |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 1601 | OpLoc, IsArrow, SS, TemplateKWLoc, |
Kaelyn Uhrain | 2b90f76 | 2012-04-25 19:49:54 +0000 | [diff] [blame] | 1602 | FirstQualifierInScope, R, TemplateArgs, |
| 1603 | false, &ExtraArgs); |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 1604 | } |
| 1605 | |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 1606 | return Result; |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 1607 | } |
| 1608 | |
| 1609 | static ExprResult |
| 1610 | BuildFieldReferenceExpr(Sema &S, Expr *BaseExpr, bool IsArrow, |
| 1611 | const CXXScopeSpec &SS, FieldDecl *Field, |
| 1612 | DeclAccessPair FoundDecl, |
| 1613 | const DeclarationNameInfo &MemberNameInfo) { |
| 1614 | // x.a is an l-value if 'a' has a reference type. Otherwise: |
| 1615 | // x.a is an l-value/x-value/pr-value if the base is (and note |
| 1616 | // that *x is always an l-value), except that if the base isn't |
| 1617 | // an ordinary object then we must have an rvalue. |
| 1618 | ExprValueKind VK = VK_LValue; |
| 1619 | ExprObjectKind OK = OK_Ordinary; |
| 1620 | if (!IsArrow) { |
| 1621 | if (BaseExpr->getObjectKind() == OK_Ordinary) |
| 1622 | VK = BaseExpr->getValueKind(); |
| 1623 | else |
| 1624 | VK = VK_RValue; |
| 1625 | } |
| 1626 | if (VK != VK_RValue && Field->isBitField()) |
| 1627 | OK = OK_BitField; |
| 1628 | |
| 1629 | // Figure out the type of the member; see C99 6.5.2.3p3, C++ [expr.ref] |
| 1630 | QualType MemberType = Field->getType(); |
| 1631 | if (const ReferenceType *Ref = MemberType->getAs<ReferenceType>()) { |
| 1632 | MemberType = Ref->getPointeeType(); |
| 1633 | VK = VK_LValue; |
| 1634 | } else { |
| 1635 | QualType BaseType = BaseExpr->getType(); |
| 1636 | if (IsArrow) BaseType = BaseType->getAs<PointerType>()->getPointeeType(); |
Matt Arsenault | 34b0adb | 2013-02-26 21:16:00 +0000 | [diff] [blame] | 1637 | |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 1638 | Qualifiers BaseQuals = BaseType.getQualifiers(); |
Matt Arsenault | 34b0adb | 2013-02-26 21:16:00 +0000 | [diff] [blame] | 1639 | |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 1640 | // GC attributes are never picked up by members. |
| 1641 | BaseQuals.removeObjCGCAttr(); |
Matt Arsenault | 34b0adb | 2013-02-26 21:16:00 +0000 | [diff] [blame] | 1642 | |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 1643 | // CVR attributes from the base are picked up by members, |
| 1644 | // except that 'mutable' members don't pick up 'const'. |
| 1645 | if (Field->isMutable()) BaseQuals.removeConst(); |
Matt Arsenault | 34b0adb | 2013-02-26 21:16:00 +0000 | [diff] [blame] | 1646 | |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 1647 | Qualifiers MemberQuals |
| 1648 | = S.Context.getCanonicalType(MemberType).getQualifiers(); |
Matt Arsenault | 34b0adb | 2013-02-26 21:16:00 +0000 | [diff] [blame] | 1649 | |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 1650 | assert(!MemberQuals.hasAddressSpace()); |
Matt Arsenault | 34b0adb | 2013-02-26 21:16:00 +0000 | [diff] [blame] | 1651 | |
| 1652 | |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 1653 | Qualifiers Combined = BaseQuals + MemberQuals; |
| 1654 | if (Combined != MemberQuals) |
| 1655 | MemberType = S.Context.getQualifiedType(MemberType, Combined); |
| 1656 | } |
Matt Arsenault | 34b0adb | 2013-02-26 21:16:00 +0000 | [diff] [blame] | 1657 | |
Daniel Jasper | f8cc02e | 2012-06-06 08:32:04 +0000 | [diff] [blame] | 1658 | S.UnusedPrivateFields.remove(Field); |
| 1659 | |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 1660 | ExprResult Base = |
| 1661 | S.PerformObjectMemberConversion(BaseExpr, SS.getScopeRep(), |
| 1662 | FoundDecl, Field); |
| 1663 | if (Base.isInvalid()) |
| 1664 | return ExprError(); |
Eli Friedman | 5f2987c | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 1665 | return S.Owned(BuildMemberExpr(S, S.Context, Base.take(), IsArrow, SS, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 1666 | /*TemplateKWLoc=*/SourceLocation(), |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 1667 | Field, FoundDecl, MemberNameInfo, |
| 1668 | MemberType, VK, OK)); |
| 1669 | } |
| 1670 | |
| 1671 | /// Builds an implicit member access expression. The current context |
| 1672 | /// is known to be an instance method, and the given unqualified lookup |
| 1673 | /// set is known to contain only instance members, at least one of which |
| 1674 | /// is from an appropriate type. |
| 1675 | ExprResult |
| 1676 | Sema::BuildImplicitMemberExpr(const CXXScopeSpec &SS, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 1677 | SourceLocation TemplateKWLoc, |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 1678 | LookupResult &R, |
| 1679 | const TemplateArgumentListInfo *TemplateArgs, |
| 1680 | bool IsKnownInstance) { |
| 1681 | assert(!R.empty() && !R.isAmbiguous()); |
| 1682 | |
| 1683 | SourceLocation loc = R.getNameLoc(); |
| 1684 | |
| 1685 | // We may have found a field within an anonymous union or struct |
| 1686 | // (C++ [class.union]). |
| 1687 | // FIXME: template-ids inside anonymous structs? |
| 1688 | if (IndirectFieldDecl *FD = R.getAsSingle<IndirectFieldDecl>()) |
| 1689 | return BuildAnonymousStructUnionMemberReference(SS, R.getNameLoc(), FD); |
| 1690 | |
| 1691 | // If this is known to be an instance access, go ahead and build an |
| 1692 | // implicit 'this' expression now. |
| 1693 | // 'this' expression now. |
Douglas Gregor | 341350e | 2011-10-18 16:47:30 +0000 | [diff] [blame] | 1694 | QualType ThisTy = getCurrentThisType(); |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 1695 | assert(!ThisTy.isNull() && "didn't correctly pre-flight capture of 'this'"); |
| 1696 | |
| 1697 | Expr *baseExpr = 0; // null signifies implicit access |
| 1698 | if (IsKnownInstance) { |
| 1699 | SourceLocation Loc = R.getNameLoc(); |
| 1700 | if (SS.getRange().isValid()) |
| 1701 | Loc = SS.getRange().getBegin(); |
Eli Friedman | 72899c3 | 2012-01-07 04:59:52 +0000 | [diff] [blame] | 1702 | CheckCXXThisCapture(Loc); |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 1703 | baseExpr = new (Context) CXXThisExpr(loc, ThisTy, /*isImplicit=*/true); |
| 1704 | } |
| 1705 | |
| 1706 | return BuildMemberReferenceExpr(baseExpr, ThisTy, |
| 1707 | /*OpLoc*/ SourceLocation(), |
| 1708 | /*IsArrow*/ true, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 1709 | SS, TemplateKWLoc, |
Douglas Gregor | 2b1ad8b | 2011-06-23 00:49:38 +0000 | [diff] [blame] | 1710 | /*FirstQualifierInScope*/ 0, |
| 1711 | R, TemplateArgs); |
| 1712 | } |