clang API Documentation
00001 //===--- Sema.cpp - AST Builder and Semantic Analysis Implementation ------===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file implements the actions class which performs semantic analysis and 00011 // builds an AST out of a parse stream. 00012 // 00013 //===----------------------------------------------------------------------===// 00014 00015 #include "clang/Sema/SemaInternal.h" 00016 #include "clang/Sema/DelayedDiagnostic.h" 00017 #include "TargetAttributesSema.h" 00018 #include "llvm/ADT/DenseMap.h" 00019 #include "llvm/ADT/SmallSet.h" 00020 #include "llvm/ADT/APFloat.h" 00021 #include "llvm/Support/CrashRecoveryContext.h" 00022 #include "clang/Sema/CXXFieldCollector.h" 00023 #include "clang/Sema/TemplateDeduction.h" 00024 #include "clang/Sema/ExternalSemaSource.h" 00025 #include "clang/Sema/ObjCMethodList.h" 00026 #include "clang/Sema/PrettyDeclStackTrace.h" 00027 #include "clang/Sema/Scope.h" 00028 #include "clang/Sema/ScopeInfo.h" 00029 #include "clang/Sema/SemaConsumer.h" 00030 #include "clang/AST/ASTContext.h" 00031 #include "clang/AST/ASTDiagnostic.h" 00032 #include "clang/AST/DeclCXX.h" 00033 #include "clang/AST/DeclObjC.h" 00034 #include "clang/AST/Expr.h" 00035 #include "clang/AST/ExprCXX.h" 00036 #include "clang/AST/StmtCXX.h" 00037 #include "clang/Lex/HeaderSearch.h" 00038 #include "clang/Lex/Preprocessor.h" 00039 #include "clang/Basic/FileManager.h" 00040 #include "clang/Basic/PartialDiagnostic.h" 00041 #include "clang/Basic/TargetInfo.h" 00042 using namespace clang; 00043 using namespace sema; 00044 00045 FunctionScopeInfo::~FunctionScopeInfo() { } 00046 00047 void FunctionScopeInfo::Clear() { 00048 HasBranchProtectedScope = false; 00049 HasBranchIntoScope = false; 00050 HasIndirectGoto = false; 00051 00052 SwitchStack.clear(); 00053 Returns.clear(); 00054 ErrorTrap.reset(); 00055 PossiblyUnreachableDiags.clear(); 00056 } 00057 00058 BlockScopeInfo::~BlockScopeInfo() { } 00059 LambdaScopeInfo::~LambdaScopeInfo() { } 00060 00061 PrintingPolicy Sema::getPrintingPolicy(const ASTContext &Context, 00062 const Preprocessor &PP) { 00063 PrintingPolicy Policy = Context.getPrintingPolicy(); 00064 Policy.Bool = Context.getLangOpts().Bool; 00065 if (!Policy.Bool) { 00066 if (MacroInfo *BoolMacro = PP.getMacroInfo(&Context.Idents.get("bool"))) { 00067 Policy.Bool = BoolMacro->isObjectLike() && 00068 BoolMacro->getNumTokens() == 1 && 00069 BoolMacro->getReplacementToken(0).is(tok::kw__Bool); 00070 } 00071 } 00072 00073 return Policy; 00074 } 00075 00076 void Sema::ActOnTranslationUnitScope(Scope *S) { 00077 TUScope = S; 00078 PushDeclContext(S, Context.getTranslationUnitDecl()); 00079 00080 VAListTagName = PP.getIdentifierInfo("__va_list_tag"); 00081 } 00082 00083 Sema::Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer, 00084 TranslationUnitKind TUKind, 00085 CodeCompleteConsumer *CodeCompleter) 00086 : TheTargetAttributesSema(0), FPFeatures(pp.getLangOpts()), 00087 LangOpts(pp.getLangOpts()), PP(pp), Context(ctxt), Consumer(consumer), 00088 Diags(PP.getDiagnostics()), SourceMgr(PP.getSourceManager()), 00089 CollectStats(false), ExternalSource(0), CodeCompleter(CodeCompleter), 00090 CurContext(0), OriginalLexicalContext(0), 00091 PackContext(0), MSStructPragmaOn(false), VisContext(0), 00092 ExprNeedsCleanups(false), LateTemplateParser(0), OpaqueParser(0), 00093 IdResolver(pp), StdInitializerList(0), CXXTypeInfoDecl(0), MSVCGuidDecl(0), 00094 NSNumberDecl(0), 00095 NSStringDecl(0), StringWithUTF8StringMethod(0), 00096 NSArrayDecl(0), ArrayWithObjectsMethod(0), 00097 NSDictionaryDecl(0), DictionaryWithObjectsMethod(0), 00098 GlobalNewDeleteDeclared(false), 00099 ObjCShouldCallSuperDealloc(false), 00100 ObjCShouldCallSuperFinalize(false), 00101 TUKind(TUKind), 00102 NumSFINAEErrors(0), InFunctionDeclarator(0), 00103 AccessCheckingSFINAE(false), InNonInstantiationSFINAEContext(false), 00104 NonInstantiationEntries(0), ArgumentPackSubstitutionIndex(-1), 00105 CurrentInstantiationScope(0), TyposCorrected(0), 00106 AnalysisWarnings(*this) 00107 { 00108 TUScope = 0; 00109 00110 LoadedExternalKnownNamespaces = false; 00111 for (unsigned I = 0; I != NSAPI::NumNSNumberLiteralMethods; ++I) 00112 NSNumberLiteralMethods[I] = 0; 00113 00114 if (getLangOpts().ObjC1) 00115 NSAPIObj.reset(new NSAPI(Context)); 00116 00117 if (getLangOpts().CPlusPlus) 00118 FieldCollector.reset(new CXXFieldCollector()); 00119 00120 // Tell diagnostics how to render things from the AST library. 00121 PP.getDiagnostics().SetArgToStringFn(&FormatASTNodeDiagnosticArgument, 00122 &Context); 00123 00124 ExprEvalContexts.push_back( 00125 ExpressionEvaluationContextRecord(PotentiallyEvaluated, 0, 00126 false, 0, false)); 00127 00128 FunctionScopes.push_back(new FunctionScopeInfo(Diags)); 00129 } 00130 00131 void Sema::Initialize() { 00132 // Tell the AST consumer about this Sema object. 00133 Consumer.Initialize(Context); 00134 00135 // FIXME: Isn't this redundant with the initialization above? 00136 if (SemaConsumer *SC = dyn_cast<SemaConsumer>(&Consumer)) 00137 SC->InitializeSema(*this); 00138 00139 // Tell the external Sema source about this Sema object. 00140 if (ExternalSemaSource *ExternalSema 00141 = dyn_cast_or_null<ExternalSemaSource>(Context.getExternalSource())) 00142 ExternalSema->InitializeSema(*this); 00143 00144 // Initialize predefined 128-bit integer types, if needed. 00145 if (PP.getTargetInfo().getPointerWidth(0) >= 64) { 00146 // If either of the 128-bit integer types are unavailable to name lookup, 00147 // define them now. 00148 DeclarationName Int128 = &Context.Idents.get("__int128_t"); 00149 if (IdResolver.begin(Int128) == IdResolver.end()) 00150 PushOnScopeChains(Context.getInt128Decl(), TUScope); 00151 00152 DeclarationName UInt128 = &Context.Idents.get("__uint128_t"); 00153 if (IdResolver.begin(UInt128) == IdResolver.end()) 00154 PushOnScopeChains(Context.getUInt128Decl(), TUScope); 00155 } 00156 00157 00158 // Initialize predefined Objective-C types: 00159 if (PP.getLangOpts().ObjC1) { 00160 // If 'SEL' does not yet refer to any declarations, make it refer to the 00161 // predefined 'SEL'. 00162 DeclarationName SEL = &Context.Idents.get("SEL"); 00163 if (IdResolver.begin(SEL) == IdResolver.end()) 00164 PushOnScopeChains(Context.getObjCSelDecl(), TUScope); 00165 00166 // If 'id' does not yet refer to any declarations, make it refer to the 00167 // predefined 'id'. 00168 DeclarationName Id = &Context.Idents.get("id"); 00169 if (IdResolver.begin(Id) == IdResolver.end()) 00170 PushOnScopeChains(Context.getObjCIdDecl(), TUScope); 00171 00172 // Create the built-in typedef for 'Class'. 00173 DeclarationName Class = &Context.Idents.get("Class"); 00174 if (IdResolver.begin(Class) == IdResolver.end()) 00175 PushOnScopeChains(Context.getObjCClassDecl(), TUScope); 00176 00177 // Create the built-in forward declaratino for 'Protocol'. 00178 DeclarationName Protocol = &Context.Idents.get("Protocol"); 00179 if (IdResolver.begin(Protocol) == IdResolver.end()) 00180 PushOnScopeChains(Context.getObjCProtocolDecl(), TUScope); 00181 } 00182 } 00183 00184 Sema::~Sema() { 00185 if (PackContext) FreePackedContext(); 00186 if (VisContext) FreeVisContext(); 00187 delete TheTargetAttributesSema; 00188 MSStructPragmaOn = false; 00189 // Kill all the active scopes. 00190 for (unsigned I = 1, E = FunctionScopes.size(); I != E; ++I) 00191 delete FunctionScopes[I]; 00192 if (FunctionScopes.size() == 1) 00193 delete FunctionScopes[0]; 00194 00195 // Tell the SemaConsumer to forget about us; we're going out of scope. 00196 if (SemaConsumer *SC = dyn_cast<SemaConsumer>(&Consumer)) 00197 SC->ForgetSema(); 00198 00199 // Detach from the external Sema source. 00200 if (ExternalSemaSource *ExternalSema 00201 = dyn_cast_or_null<ExternalSemaSource>(Context.getExternalSource())) 00202 ExternalSema->ForgetSema(); 00203 } 00204 00205 /// makeUnavailableInSystemHeader - There is an error in the current 00206 /// context. If we're still in a system header, and we can plausibly 00207 /// make the relevant declaration unavailable instead of erroring, do 00208 /// so and return true. 00209 bool Sema::makeUnavailableInSystemHeader(SourceLocation loc, 00210 StringRef msg) { 00211 // If we're not in a function, it's an error. 00212 FunctionDecl *fn = dyn_cast<FunctionDecl>(CurContext); 00213 if (!fn) return false; 00214 00215 // If we're in template instantiation, it's an error. 00216 if (!ActiveTemplateInstantiations.empty()) 00217 return false; 00218 00219 // If that function's not in a system header, it's an error. 00220 if (!Context.getSourceManager().isInSystemHeader(loc)) 00221 return false; 00222 00223 // If the function is already unavailable, it's not an error. 00224 if (fn->hasAttr<UnavailableAttr>()) return true; 00225 00226 fn->addAttr(new (Context) UnavailableAttr(loc, Context, msg)); 00227 return true; 00228 } 00229 00230 ASTMutationListener *Sema::getASTMutationListener() const { 00231 return getASTConsumer().GetASTMutationListener(); 00232 } 00233 00234 /// \brief Print out statistics about the semantic analysis. 00235 void Sema::PrintStats() const { 00236 llvm::errs() << "\n*** Semantic Analysis Stats:\n"; 00237 llvm::errs() << NumSFINAEErrors << " SFINAE diagnostics trapped.\n"; 00238 00239 BumpAlloc.PrintStats(); 00240 AnalysisWarnings.PrintStats(); 00241 } 00242 00243 /// ImpCastExprToType - If Expr is not of type 'Type', insert an implicit cast. 00244 /// If there is already an implicit cast, merge into the existing one. 00245 /// The result is of the given category. 00246 ExprResult Sema::ImpCastExprToType(Expr *E, QualType Ty, 00247 CastKind Kind, ExprValueKind VK, 00248 const CXXCastPath *BasePath, 00249 CheckedConversionKind CCK) { 00250 #ifndef NDEBUG 00251 if (VK == VK_RValue && !E->isRValue()) { 00252 switch (Kind) { 00253 default: 00254 assert(0 && "can't implicitly cast lvalue to rvalue with this cast kind"); 00255 case CK_LValueToRValue: 00256 case CK_ArrayToPointerDecay: 00257 case CK_FunctionToPointerDecay: 00258 case CK_ToVoid: 00259 break; 00260 } 00261 } 00262 assert((VK == VK_RValue || !E->isRValue()) && "can't cast rvalue to lvalue"); 00263 #endif 00264 00265 QualType ExprTy = Context.getCanonicalType(E->getType()); 00266 QualType TypeTy = Context.getCanonicalType(Ty); 00267 00268 if (ExprTy == TypeTy) 00269 return Owned(E); 00270 00271 if (getLangOpts().ObjCAutoRefCount) 00272 CheckObjCARCConversion(SourceRange(), Ty, E, CCK); 00273 00274 // If this is a derived-to-base cast to a through a virtual base, we 00275 // need a vtable. 00276 if (Kind == CK_DerivedToBase && 00277 BasePathInvolvesVirtualBase(*BasePath)) { 00278 QualType T = E->getType(); 00279 if (const PointerType *Pointer = T->getAs<PointerType>()) 00280 T = Pointer->getPointeeType(); 00281 if (const RecordType *RecordTy = T->getAs<RecordType>()) 00282 MarkVTableUsed(E->getLocStart(), 00283 cast<CXXRecordDecl>(RecordTy->getDecl())); 00284 } 00285 00286 if (ImplicitCastExpr *ImpCast = dyn_cast<ImplicitCastExpr>(E)) { 00287 if (ImpCast->getCastKind() == Kind && (!BasePath || BasePath->empty())) { 00288 ImpCast->setType(Ty); 00289 ImpCast->setValueKind(VK); 00290 return Owned(E); 00291 } 00292 } 00293 00294 return Owned(ImplicitCastExpr::Create(Context, Ty, Kind, E, BasePath, VK)); 00295 } 00296 00297 /// ScalarTypeToBooleanCastKind - Returns the cast kind corresponding 00298 /// to the conversion from scalar type ScalarTy to the Boolean type. 00299 CastKind Sema::ScalarTypeToBooleanCastKind(QualType ScalarTy) { 00300 switch (ScalarTy->getScalarTypeKind()) { 00301 case Type::STK_Bool: return CK_NoOp; 00302 case Type::STK_CPointer: return CK_PointerToBoolean; 00303 case Type::STK_BlockPointer: return CK_PointerToBoolean; 00304 case Type::STK_ObjCObjectPointer: return CK_PointerToBoolean; 00305 case Type::STK_MemberPointer: return CK_MemberPointerToBoolean; 00306 case Type::STK_Integral: return CK_IntegralToBoolean; 00307 case Type::STK_Floating: return CK_FloatingToBoolean; 00308 case Type::STK_IntegralComplex: return CK_IntegralComplexToBoolean; 00309 case Type::STK_FloatingComplex: return CK_FloatingComplexToBoolean; 00310 } 00311 return CK_Invalid; 00312 } 00313 00314 /// \brief Used to prune the decls of Sema's UnusedFileScopedDecls vector. 00315 static bool ShouldRemoveFromUnused(Sema *SemaRef, const DeclaratorDecl *D) { 00316 if (D->isUsed()) 00317 return true; 00318 00319 if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) { 00320 // UnusedFileScopedDecls stores the first declaration. 00321 // The declaration may have become definition so check again. 00322 const FunctionDecl *DeclToCheck; 00323 if (FD->hasBody(DeclToCheck)) 00324 return !SemaRef->ShouldWarnIfUnusedFileScopedDecl(DeclToCheck); 00325 00326 // Later redecls may add new information resulting in not having to warn, 00327 // so check again. 00328 DeclToCheck = FD->getMostRecentDecl(); 00329 if (DeclToCheck != FD) 00330 return !SemaRef->ShouldWarnIfUnusedFileScopedDecl(DeclToCheck); 00331 } 00332 00333 if (const VarDecl *VD = dyn_cast<VarDecl>(D)) { 00334 // UnusedFileScopedDecls stores the first declaration. 00335 // The declaration may have become definition so check again. 00336 const VarDecl *DeclToCheck = VD->getDefinition(); 00337 if (DeclToCheck) 00338 return !SemaRef->ShouldWarnIfUnusedFileScopedDecl(DeclToCheck); 00339 00340 // Later redecls may add new information resulting in not having to warn, 00341 // so check again. 00342 DeclToCheck = VD->getMostRecentDecl(); 00343 if (DeclToCheck != VD) 00344 return !SemaRef->ShouldWarnIfUnusedFileScopedDecl(DeclToCheck); 00345 } 00346 00347 return false; 00348 } 00349 00350 namespace { 00351 struct UndefinedInternal { 00352 NamedDecl *decl; 00353 FullSourceLoc useLoc; 00354 00355 UndefinedInternal(NamedDecl *decl, FullSourceLoc useLoc) 00356 : decl(decl), useLoc(useLoc) {} 00357 }; 00358 00359 bool operator<(const UndefinedInternal &l, const UndefinedInternal &r) { 00360 return l.useLoc.isBeforeInTranslationUnitThan(r.useLoc); 00361 } 00362 } 00363 00364 /// checkUndefinedInternals - Check for undefined objects with internal linkage. 00365 static void checkUndefinedInternals(Sema &S) { 00366 if (S.UndefinedInternals.empty()) return; 00367 00368 // Collect all the still-undefined entities with internal linkage. 00369 SmallVector<UndefinedInternal, 16> undefined; 00370 for (llvm::DenseMap<NamedDecl*,SourceLocation>::iterator 00371 i = S.UndefinedInternals.begin(), e = S.UndefinedInternals.end(); 00372 i != e; ++i) { 00373 NamedDecl *decl = i->first; 00374 00375 // Ignore attributes that have become invalid. 00376 if (decl->isInvalidDecl()) continue; 00377 00378 // __attribute__((weakref)) is basically a definition. 00379 if (decl->hasAttr<WeakRefAttr>()) continue; 00380 00381 if (FunctionDecl *fn = dyn_cast<FunctionDecl>(decl)) { 00382 if (fn->isPure() || fn->hasBody()) 00383 continue; 00384 } else { 00385 if (cast<VarDecl>(decl)->hasDefinition() != VarDecl::DeclarationOnly) 00386 continue; 00387 } 00388 00389 // We build a FullSourceLoc so that we can sort with array_pod_sort. 00390 FullSourceLoc loc(i->second, S.Context.getSourceManager()); 00391 undefined.push_back(UndefinedInternal(decl, loc)); 00392 } 00393 00394 if (undefined.empty()) return; 00395 00396 // Sort (in order of use site) so that we're not (as) dependent on 00397 // the iteration order through an llvm::DenseMap. 00398 llvm::array_pod_sort(undefined.begin(), undefined.end()); 00399 00400 for (SmallVectorImpl<UndefinedInternal>::iterator 00401 i = undefined.begin(), e = undefined.end(); i != e; ++i) { 00402 NamedDecl *decl = i->decl; 00403 S.Diag(decl->getLocation(), diag::warn_undefined_internal) 00404 << isa<VarDecl>(decl) << decl; 00405 S.Diag(i->useLoc, diag::note_used_here); 00406 } 00407 } 00408 00409 void Sema::LoadExternalWeakUndeclaredIdentifiers() { 00410 if (!ExternalSource) 00411 return; 00412 00413 SmallVector<std::pair<IdentifierInfo *, WeakInfo>, 4> WeakIDs; 00414 ExternalSource->ReadWeakUndeclaredIdentifiers(WeakIDs); 00415 for (unsigned I = 0, N = WeakIDs.size(); I != N; ++I) { 00416 llvm::DenseMap<IdentifierInfo*,WeakInfo>::iterator Pos 00417 = WeakUndeclaredIdentifiers.find(WeakIDs[I].first); 00418 if (Pos != WeakUndeclaredIdentifiers.end()) 00419 continue; 00420 00421 WeakUndeclaredIdentifiers.insert(WeakIDs[I]); 00422 } 00423 } 00424 00425 /// ActOnEndOfTranslationUnit - This is called at the very end of the 00426 /// translation unit when EOF is reached and all but the top-level scope is 00427 /// popped. 00428 void Sema::ActOnEndOfTranslationUnit() { 00429 assert(DelayedDiagnostics.getCurrentPool() == NULL 00430 && "reached end of translation unit with a pool attached?"); 00431 00432 // Only complete translation units define vtables and perform implicit 00433 // instantiations. 00434 if (TUKind == TU_Complete) { 00435 DiagnoseUseOfUnimplementedSelectors(); 00436 00437 // If any dynamic classes have their key function defined within 00438 // this translation unit, then those vtables are considered "used" and must 00439 // be emitted. 00440 for (DynamicClassesType::iterator I = DynamicClasses.begin(ExternalSource), 00441 E = DynamicClasses.end(); 00442 I != E; ++I) { 00443 assert(!(*I)->isDependentType() && 00444 "Should not see dependent types here!"); 00445 if (const CXXMethodDecl *KeyFunction = Context.getKeyFunction(*I)) { 00446 const FunctionDecl *Definition = 0; 00447 if (KeyFunction->hasBody(Definition)) 00448 MarkVTableUsed(Definition->getLocation(), *I, true); 00449 } 00450 } 00451 00452 // If DefinedUsedVTables ends up marking any virtual member functions it 00453 // might lead to more pending template instantiations, which we then need 00454 // to instantiate. 00455 DefineUsedVTables(); 00456 00457 // C++: Perform implicit template instantiations. 00458 // 00459 // FIXME: When we perform these implicit instantiations, we do not 00460 // carefully keep track of the point of instantiation (C++ [temp.point]). 00461 // This means that name lookup that occurs within the template 00462 // instantiation will always happen at the end of the translation unit, 00463 // so it will find some names that should not be found. Although this is 00464 // common behavior for C++ compilers, it is technically wrong. In the 00465 // future, we either need to be able to filter the results of name lookup 00466 // or we need to perform template instantiations earlier. 00467 PerformPendingInstantiations(); 00468 } 00469 00470 // Remove file scoped decls that turned out to be used. 00471 UnusedFileScopedDecls.erase(std::remove_if(UnusedFileScopedDecls.begin(0, 00472 true), 00473 UnusedFileScopedDecls.end(), 00474 std::bind1st(std::ptr_fun(ShouldRemoveFromUnused), 00475 this)), 00476 UnusedFileScopedDecls.end()); 00477 00478 if (TUKind == TU_Prefix) { 00479 // Translation unit prefixes don't need any of the checking below. 00480 TUScope = 0; 00481 return; 00482 } 00483 00484 // Check for #pragma weak identifiers that were never declared 00485 // FIXME: This will cause diagnostics to be emitted in a non-determinstic 00486 // order! Iterating over a densemap like this is bad. 00487 LoadExternalWeakUndeclaredIdentifiers(); 00488 for (llvm::DenseMap<IdentifierInfo*,WeakInfo>::iterator 00489 I = WeakUndeclaredIdentifiers.begin(), 00490 E = WeakUndeclaredIdentifiers.end(); I != E; ++I) { 00491 if (I->second.getUsed()) continue; 00492 00493 Diag(I->second.getLocation(), diag::warn_weak_identifier_undeclared) 00494 << I->first; 00495 } 00496 00497 if (TUKind == TU_Module) { 00498 // If we are building a module, resolve all of the exported declarations 00499 // now. 00500 if (Module *CurrentModule = PP.getCurrentModule()) { 00501 ModuleMap &ModMap = PP.getHeaderSearchInfo().getModuleMap(); 00502 00503 llvm::SmallVector<Module *, 2> Stack; 00504 Stack.push_back(CurrentModule); 00505 while (!Stack.empty()) { 00506 Module *Mod = Stack.back(); 00507 Stack.pop_back(); 00508 00509 // Resolve the exported declarations. 00510 // FIXME: Actually complain, once we figure out how to teach the 00511 // diagnostic client to deal with complains in the module map at this 00512 // point. 00513 ModMap.resolveExports(Mod, /*Complain=*/false); 00514 00515 // Queue the submodules, so their exports will also be resolved. 00516 for (Module::submodule_iterator Sub = Mod->submodule_begin(), 00517 SubEnd = Mod->submodule_end(); 00518 Sub != SubEnd; ++Sub) { 00519 Stack.push_back(*Sub); 00520 } 00521 } 00522 } 00523 00524 // Modules don't need any of the checking below. 00525 TUScope = 0; 00526 return; 00527 } 00528 00529 // C99 6.9.2p2: 00530 // A declaration of an identifier for an object that has file 00531 // scope without an initializer, and without a storage-class 00532 // specifier or with the storage-class specifier static, 00533 // constitutes a tentative definition. If a translation unit 00534 // contains one or more tentative definitions for an identifier, 00535 // and the translation unit contains no external definition for 00536 // that identifier, then the behavior is exactly as if the 00537 // translation unit contains a file scope declaration of that 00538 // identifier, with the composite type as of the end of the 00539 // translation unit, with an initializer equal to 0. 00540 llvm::SmallSet<VarDecl *, 32> Seen; 00541 for (TentativeDefinitionsType::iterator 00542 T = TentativeDefinitions.begin(ExternalSource), 00543 TEnd = TentativeDefinitions.end(); 00544 T != TEnd; ++T) 00545 { 00546 VarDecl *VD = (*T)->getActingDefinition(); 00547 00548 // If the tentative definition was completed, getActingDefinition() returns 00549 // null. If we've already seen this variable before, insert()'s second 00550 // return value is false. 00551 if (VD == 0 || VD->isInvalidDecl() || !Seen.insert(VD)) 00552 continue; 00553 00554 if (const IncompleteArrayType *ArrayT 00555 = Context.getAsIncompleteArrayType(VD->getType())) { 00556 if (RequireCompleteType(VD->getLocation(), 00557 ArrayT->getElementType(), 00558 diag::err_tentative_def_incomplete_type_arr)) { 00559 VD->setInvalidDecl(); 00560 continue; 00561 } 00562 00563 // Set the length of the array to 1 (C99 6.9.2p5). 00564 Diag(VD->getLocation(), diag::warn_tentative_incomplete_array); 00565 llvm::APInt One(Context.getTypeSize(Context.getSizeType()), true); 00566 QualType T = Context.getConstantArrayType(ArrayT->getElementType(), 00567 One, ArrayType::Normal, 0); 00568 VD->setType(T); 00569 } else if (RequireCompleteType(VD->getLocation(), VD->getType(), 00570 diag::err_tentative_def_incomplete_type)) 00571 VD->setInvalidDecl(); 00572 00573 // Notify the consumer that we've completed a tentative definition. 00574 if (!VD->isInvalidDecl()) 00575 Consumer.CompleteTentativeDefinition(VD); 00576 00577 } 00578 00579 if (LangOpts.CPlusPlus0x && 00580 Diags.getDiagnosticLevel(diag::warn_delegating_ctor_cycle, 00581 SourceLocation()) 00582 != DiagnosticsEngine::Ignored) 00583 CheckDelegatingCtorCycles(); 00584 00585 // If there were errors, disable 'unused' warnings since they will mostly be 00586 // noise. 00587 if (!Diags.hasErrorOccurred()) { 00588 // Output warning for unused file scoped decls. 00589 for (UnusedFileScopedDeclsType::iterator 00590 I = UnusedFileScopedDecls.begin(ExternalSource), 00591 E = UnusedFileScopedDecls.end(); I != E; ++I) { 00592 if (ShouldRemoveFromUnused(this, *I)) 00593 continue; 00594 00595 if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(*I)) { 00596 const FunctionDecl *DiagD; 00597 if (!FD->hasBody(DiagD)) 00598 DiagD = FD; 00599 if (DiagD->isDeleted()) 00600 continue; // Deleted functions are supposed to be unused. 00601 if (DiagD->isReferenced()) { 00602 if (isa<CXXMethodDecl>(DiagD)) 00603 Diag(DiagD->getLocation(), diag::warn_unneeded_member_function) 00604 << DiagD->getDeclName(); 00605 else 00606 Diag(DiagD->getLocation(), diag::warn_unneeded_internal_decl) 00607 << /*function*/0 << DiagD->getDeclName(); 00608 } else { 00609 Diag(DiagD->getLocation(), 00610 isa<CXXMethodDecl>(DiagD) ? diag::warn_unused_member_function 00611 : diag::warn_unused_function) 00612 << DiagD->getDeclName(); 00613 } 00614 } else { 00615 const VarDecl *DiagD = cast<VarDecl>(*I)->getDefinition(); 00616 if (!DiagD) 00617 DiagD = cast<VarDecl>(*I); 00618 if (DiagD->isReferenced()) { 00619 Diag(DiagD->getLocation(), diag::warn_unneeded_internal_decl) 00620 << /*variable*/1 << DiagD->getDeclName(); 00621 } else { 00622 Diag(DiagD->getLocation(), diag::warn_unused_variable) 00623 << DiagD->getDeclName(); 00624 } 00625 } 00626 } 00627 00628 checkUndefinedInternals(*this); 00629 } 00630 00631 // Check we've noticed that we're no longer parsing the initializer for every 00632 // variable. If we miss cases, then at best we have a performance issue and 00633 // at worst a rejects-valid bug. 00634 assert(ParsingInitForAutoVars.empty() && 00635 "Didn't unmark var as having its initializer parsed"); 00636 00637 TUScope = 0; 00638 } 00639 00640 00641 //===----------------------------------------------------------------------===// 00642 // Helper functions. 00643 //===----------------------------------------------------------------------===// 00644 00645 DeclContext *Sema::getFunctionLevelDeclContext() { 00646 DeclContext *DC = CurContext; 00647 00648 while (true) { 00649 if (isa<BlockDecl>(DC) || isa<EnumDecl>(DC)) { 00650 DC = DC->getParent(); 00651 } else if (isa<CXXMethodDecl>(DC) && 00652 cast<CXXMethodDecl>(DC)->getOverloadedOperator() == OO_Call && 00653 cast<CXXRecordDecl>(DC->getParent())->isLambda()) { 00654 DC = DC->getParent()->getParent(); 00655 } 00656 else break; 00657 } 00658 00659 return DC; 00660 } 00661 00662 /// getCurFunctionDecl - If inside of a function body, this returns a pointer 00663 /// to the function decl for the function being parsed. If we're currently 00664 /// in a 'block', this returns the containing context. 00665 FunctionDecl *Sema::getCurFunctionDecl() { 00666 DeclContext *DC = getFunctionLevelDeclContext(); 00667 return dyn_cast<FunctionDecl>(DC); 00668 } 00669 00670 ObjCMethodDecl *Sema::getCurMethodDecl() { 00671 DeclContext *DC = getFunctionLevelDeclContext(); 00672 return dyn_cast<ObjCMethodDecl>(DC); 00673 } 00674 00675 NamedDecl *Sema::getCurFunctionOrMethodDecl() { 00676 DeclContext *DC = getFunctionLevelDeclContext(); 00677 if (isa<ObjCMethodDecl>(DC) || isa<FunctionDecl>(DC)) 00678 return cast<NamedDecl>(DC); 00679 return 0; 00680 } 00681 00682 void Sema::EmitCurrentDiagnostic(unsigned DiagID) { 00683 // FIXME: It doesn't make sense to me that DiagID is an incoming argument here 00684 // and yet we also use the current diag ID on the DiagnosticsEngine. This has 00685 // been made more painfully obvious by the refactor that introduced this 00686 // function, but it is possible that the incoming argument can be 00687 // eliminnated. If it truly cannot be (for example, there is some reentrancy 00688 // issue I am not seeing yet), then there should at least be a clarifying 00689 // comment somewhere. 00690 if (llvm::Optional<TemplateDeductionInfo*> Info = isSFINAEContext()) { 00691 switch (DiagnosticIDs::getDiagnosticSFINAEResponse( 00692 Diags.getCurrentDiagID())) { 00693 case DiagnosticIDs::SFINAE_Report: 00694 // We'll report the diagnostic below. 00695 break; 00696 00697 case DiagnosticIDs::SFINAE_SubstitutionFailure: 00698 // Count this failure so that we know that template argument deduction 00699 // has failed. 00700 ++NumSFINAEErrors; 00701 00702 // Make a copy of this suppressed diagnostic and store it with the 00703 // template-deduction information. 00704 if (*Info && !(*Info)->hasSFINAEDiagnostic()) { 00705 Diagnostic DiagInfo(&Diags); 00706 (*Info)->addSFINAEDiagnostic(DiagInfo.getLocation(), 00707 PartialDiagnostic(DiagInfo, Context.getDiagAllocator())); 00708 } 00709 00710 Diags.setLastDiagnosticIgnored(); 00711 Diags.Clear(); 00712 return; 00713 00714 case DiagnosticIDs::SFINAE_AccessControl: { 00715 // Per C++ Core Issue 1170, access control is part of SFINAE. 00716 // Additionally, the AccessCheckingSFINAE flag can be used to temporarily 00717 // make access control a part of SFINAE for the purposes of checking 00718 // type traits. 00719 if (!AccessCheckingSFINAE && !getLangOpts().CPlusPlus0x) 00720 break; 00721 00722 SourceLocation Loc = Diags.getCurrentDiagLoc(); 00723 00724 // Suppress this diagnostic. 00725 ++NumSFINAEErrors; 00726 00727 // Make a copy of this suppressed diagnostic and store it with the 00728 // template-deduction information. 00729 if (*Info && !(*Info)->hasSFINAEDiagnostic()) { 00730 Diagnostic DiagInfo(&Diags); 00731 (*Info)->addSFINAEDiagnostic(DiagInfo.getLocation(), 00732 PartialDiagnostic(DiagInfo, Context.getDiagAllocator())); 00733 } 00734 00735 Diags.setLastDiagnosticIgnored(); 00736 Diags.Clear(); 00737 00738 // Now the diagnostic state is clear, produce a C++98 compatibility 00739 // warning. 00740 Diag(Loc, diag::warn_cxx98_compat_sfinae_access_control); 00741 00742 // The last diagnostic which Sema produced was ignored. Suppress any 00743 // notes attached to it. 00744 Diags.setLastDiagnosticIgnored(); 00745 return; 00746 } 00747 00748 case DiagnosticIDs::SFINAE_Suppress: 00749 // Make a copy of this suppressed diagnostic and store it with the 00750 // template-deduction information; 00751 if (*Info) { 00752 Diagnostic DiagInfo(&Diags); 00753 (*Info)->addSuppressedDiagnostic(DiagInfo.getLocation(), 00754 PartialDiagnostic(DiagInfo, Context.getDiagAllocator())); 00755 } 00756 00757 // Suppress this diagnostic. 00758 Diags.setLastDiagnosticIgnored(); 00759 Diags.Clear(); 00760 return; 00761 } 00762 } 00763 00764 // Set up the context's printing policy based on our current state. 00765 Context.setPrintingPolicy(getPrintingPolicy()); 00766 00767 // Emit the diagnostic. 00768 if (!Diags.EmitCurrentDiagnostic()) 00769 return; 00770 00771 // If this is not a note, and we're in a template instantiation 00772 // that is different from the last template instantiation where 00773 // we emitted an error, print a template instantiation 00774 // backtrace. 00775 if (!DiagnosticIDs::isBuiltinNote(DiagID) && 00776 !ActiveTemplateInstantiations.empty() && 00777 ActiveTemplateInstantiations.back() 00778 != LastTemplateInstantiationErrorContext) { 00779 PrintInstantiationStack(); 00780 LastTemplateInstantiationErrorContext = ActiveTemplateInstantiations.back(); 00781 } 00782 } 00783 00784 Sema::SemaDiagnosticBuilder 00785 Sema::Diag(SourceLocation Loc, const PartialDiagnostic& PD) { 00786 SemaDiagnosticBuilder Builder(Diag(Loc, PD.getDiagID())); 00787 PD.Emit(Builder); 00788 00789 return Builder; 00790 } 00791 00792 /// \brief Looks through the macro-expansion chain for the given 00793 /// location, looking for a macro expansion with the given name. 00794 /// If one is found, returns true and sets the location to that 00795 /// expansion loc. 00796 bool Sema::findMacroSpelling(SourceLocation &locref, StringRef name) { 00797 SourceLocation loc = locref; 00798 if (!loc.isMacroID()) return false; 00799 00800 // There's no good way right now to look at the intermediate 00801 // expansions, so just jump to the expansion location. 00802 loc = getSourceManager().getExpansionLoc(loc); 00803 00804 // If that's written with the name, stop here. 00805 SmallVector<char, 16> buffer; 00806 if (getPreprocessor().getSpelling(loc, buffer) == name) { 00807 locref = loc; 00808 return true; 00809 } 00810 return false; 00811 } 00812 00813 /// \brief Determines the active Scope associated with the given declaration 00814 /// context. 00815 /// 00816 /// This routine maps a declaration context to the active Scope object that 00817 /// represents that declaration context in the parser. It is typically used 00818 /// from "scope-less" code (e.g., template instantiation, lazy creation of 00819 /// declarations) that injects a name for name-lookup purposes and, therefore, 00820 /// must update the Scope. 00821 /// 00822 /// \returns The scope corresponding to the given declaraion context, or NULL 00823 /// if no such scope is open. 00824 Scope *Sema::getScopeForContext(DeclContext *Ctx) { 00825 00826 if (!Ctx) 00827 return 0; 00828 00829 Ctx = Ctx->getPrimaryContext(); 00830 for (Scope *S = getCurScope(); S; S = S->getParent()) { 00831 // Ignore scopes that cannot have declarations. This is important for 00832 // out-of-line definitions of static class members. 00833 if (S->getFlags() & (Scope::DeclScope | Scope::TemplateParamScope)) 00834 if (DeclContext *Entity = static_cast<DeclContext *> (S->getEntity())) 00835 if (Ctx == Entity->getPrimaryContext()) 00836 return S; 00837 } 00838 00839 return 0; 00840 } 00841 00842 /// \brief Enter a new function scope 00843 void Sema::PushFunctionScope() { 00844 if (FunctionScopes.size() == 1) { 00845 // Use the "top" function scope rather than having to allocate 00846 // memory for a new scope. 00847 FunctionScopes.back()->Clear(); 00848 FunctionScopes.push_back(FunctionScopes.back()); 00849 return; 00850 } 00851 00852 FunctionScopes.push_back(new FunctionScopeInfo(getDiagnostics())); 00853 } 00854 00855 void Sema::PushBlockScope(Scope *BlockScope, BlockDecl *Block) { 00856 FunctionScopes.push_back(new BlockScopeInfo(getDiagnostics(), 00857 BlockScope, Block)); 00858 } 00859 00860 void Sema::PushLambdaScope(CXXRecordDecl *Lambda, 00861 CXXMethodDecl *CallOperator) { 00862 FunctionScopes.push_back(new LambdaScopeInfo(getDiagnostics(), Lambda, 00863 CallOperator)); 00864 } 00865 00866 void Sema::PopFunctionScopeInfo(const AnalysisBasedWarnings::Policy *WP, 00867 const Decl *D, const BlockExpr *blkExpr) { 00868 FunctionScopeInfo *Scope = FunctionScopes.pop_back_val(); 00869 assert(!FunctionScopes.empty() && "mismatched push/pop!"); 00870 00871 // Issue any analysis-based warnings. 00872 if (WP && D) 00873 AnalysisWarnings.IssueWarnings(*WP, Scope, D, blkExpr); 00874 else { 00875 for (SmallVectorImpl<sema::PossiblyUnreachableDiag>::iterator 00876 i = Scope->PossiblyUnreachableDiags.begin(), 00877 e = Scope->PossiblyUnreachableDiags.end(); 00878 i != e; ++i) { 00879 const sema::PossiblyUnreachableDiag &D = *i; 00880 Diag(D.Loc, D.PD); 00881 } 00882 } 00883 00884 if (FunctionScopes.back() != Scope) { 00885 delete Scope; 00886 } 00887 } 00888 00889 void Sema::PushCompoundScope() { 00890 getCurFunction()->CompoundScopes.push_back(CompoundScopeInfo()); 00891 } 00892 00893 void Sema::PopCompoundScope() { 00894 FunctionScopeInfo *CurFunction = getCurFunction(); 00895 assert(!CurFunction->CompoundScopes.empty() && "mismatched push/pop"); 00896 00897 CurFunction->CompoundScopes.pop_back(); 00898 } 00899 00900 /// \brief Determine whether any errors occurred within this function/method/ 00901 /// block. 00902 bool Sema::hasAnyUnrecoverableErrorsInThisFunction() const { 00903 return getCurFunction()->ErrorTrap.hasUnrecoverableErrorOccurred(); 00904 } 00905 00906 BlockScopeInfo *Sema::getCurBlock() { 00907 if (FunctionScopes.empty()) 00908 return 0; 00909 00910 return dyn_cast<BlockScopeInfo>(FunctionScopes.back()); 00911 } 00912 00913 LambdaScopeInfo *Sema::getCurLambda() { 00914 if (FunctionScopes.empty()) 00915 return 0; 00916 00917 return dyn_cast<LambdaScopeInfo>(FunctionScopes.back()); 00918 } 00919 00920 // Pin this vtable to this file. 00921 ExternalSemaSource::~ExternalSemaSource() {} 00922 00923 void ExternalSemaSource::ReadMethodPool(Selector Sel) { } 00924 00925 void ExternalSemaSource::ReadKnownNamespaces( 00926 SmallVectorImpl<NamespaceDecl *> &Namespaces) { 00927 } 00928 00929 void PrettyDeclStackTraceEntry::print(raw_ostream &OS) const { 00930 SourceLocation Loc = this->Loc; 00931 if (!Loc.isValid() && TheDecl) Loc = TheDecl->getLocation(); 00932 if (Loc.isValid()) { 00933 Loc.print(OS, S.getSourceManager()); 00934 OS << ": "; 00935 } 00936 OS << Message; 00937 00938 if (TheDecl && isa<NamedDecl>(TheDecl)) { 00939 std::string Name = cast<NamedDecl>(TheDecl)->getNameAsString(); 00940 if (!Name.empty()) 00941 OS << " '" << Name << '\''; 00942 } 00943 00944 OS << '\n'; 00945 } 00946 00947 /// \brief Figure out if an expression could be turned into a call. 00948 /// 00949 /// Use this when trying to recover from an error where the programmer may have 00950 /// written just the name of a function instead of actually calling it. 00951 /// 00952 /// \param E - The expression to examine. 00953 /// \param ZeroArgCallReturnTy - If the expression can be turned into a call 00954 /// with no arguments, this parameter is set to the type returned by such a 00955 /// call; otherwise, it is set to an empty QualType. 00956 /// \param OverloadSet - If the expression is an overloaded function 00957 /// name, this parameter is populated with the decls of the various overloads. 00958 bool Sema::isExprCallable(const Expr &E, QualType &ZeroArgCallReturnTy, 00959 UnresolvedSetImpl &OverloadSet) { 00960 ZeroArgCallReturnTy = QualType(); 00961 OverloadSet.clear(); 00962 00963 if (E.getType() == Context.OverloadTy) { 00964 OverloadExpr::FindResult FR = OverloadExpr::find(const_cast<Expr*>(&E)); 00965 const OverloadExpr *Overloads = FR.Expression; 00966 00967 for (OverloadExpr::decls_iterator it = Overloads->decls_begin(), 00968 DeclsEnd = Overloads->decls_end(); it != DeclsEnd; ++it) { 00969 OverloadSet.addDecl(*it); 00970 00971 // Check whether the function is a non-template which takes no 00972 // arguments. 00973 if (const FunctionDecl *OverloadDecl 00974 = dyn_cast<FunctionDecl>((*it)->getUnderlyingDecl())) { 00975 if (OverloadDecl->getMinRequiredArguments() == 0) 00976 ZeroArgCallReturnTy = OverloadDecl->getResultType(); 00977 } 00978 } 00979 00980 // Ignore overloads that are pointer-to-member constants. 00981 if (FR.HasFormOfMemberPointer) 00982 return false; 00983 00984 return true; 00985 } 00986 00987 if (const DeclRefExpr *DeclRef = dyn_cast<DeclRefExpr>(E.IgnoreParens())) { 00988 if (const FunctionDecl *Fun = dyn_cast<FunctionDecl>(DeclRef->getDecl())) { 00989 if (Fun->getMinRequiredArguments() == 0) 00990 ZeroArgCallReturnTy = Fun->getResultType(); 00991 return true; 00992 } 00993 } 00994 00995 // We don't have an expression that's convenient to get a FunctionDecl from, 00996 // but we can at least check if the type is "function of 0 arguments". 00997 QualType ExprTy = E.getType(); 00998 const FunctionType *FunTy = NULL; 00999 QualType PointeeTy = ExprTy->getPointeeType(); 01000 if (!PointeeTy.isNull()) 01001 FunTy = PointeeTy->getAs<FunctionType>(); 01002 if (!FunTy) 01003 FunTy = ExprTy->getAs<FunctionType>(); 01004 if (!FunTy && ExprTy == Context.BoundMemberTy) { 01005 // Look for the bound-member type. If it's still overloaded, give up, 01006 // although we probably should have fallen into the OverloadExpr case above 01007 // if we actually have an overloaded bound member. 01008 QualType BoundMemberTy = Expr::findBoundMemberType(&E); 01009 if (!BoundMemberTy.isNull()) 01010 FunTy = BoundMemberTy->castAs<FunctionType>(); 01011 } 01012 01013 if (const FunctionProtoType *FPT = 01014 dyn_cast_or_null<FunctionProtoType>(FunTy)) { 01015 if (FPT->getNumArgs() == 0) 01016 ZeroArgCallReturnTy = FunTy->getResultType(); 01017 return true; 01018 } 01019 return false; 01020 } 01021 01022 /// \brief Give notes for a set of overloads. 01023 /// 01024 /// A companion to isExprCallable. In cases when the name that the programmer 01025 /// wrote was an overloaded function, we may be able to make some guesses about 01026 /// plausible overloads based on their return types; such guesses can be handed 01027 /// off to this method to be emitted as notes. 01028 /// 01029 /// \param Overloads - The overloads to note. 01030 /// \param FinalNoteLoc - If we've suppressed printing some overloads due to 01031 /// -fshow-overloads=best, this is the location to attach to the note about too 01032 /// many candidates. Typically this will be the location of the original 01033 /// ill-formed expression. 01034 static void noteOverloads(Sema &S, const UnresolvedSetImpl &Overloads, 01035 const SourceLocation FinalNoteLoc) { 01036 int ShownOverloads = 0; 01037 int SuppressedOverloads = 0; 01038 for (UnresolvedSetImpl::iterator It = Overloads.begin(), 01039 DeclsEnd = Overloads.end(); It != DeclsEnd; ++It) { 01040 // FIXME: Magic number for max shown overloads stolen from 01041 // OverloadCandidateSet::NoteCandidates. 01042 if (ShownOverloads >= 4 && 01043 S.Diags.getShowOverloads() == DiagnosticsEngine::Ovl_Best) { 01044 ++SuppressedOverloads; 01045 continue; 01046 } 01047 01048 NamedDecl *Fn = (*It)->getUnderlyingDecl(); 01049 S.Diag(Fn->getLocation(), diag::note_possible_target_of_call); 01050 ++ShownOverloads; 01051 } 01052 01053 if (SuppressedOverloads) 01054 S.Diag(FinalNoteLoc, diag::note_ovl_too_many_candidates) 01055 << SuppressedOverloads; 01056 } 01057 01058 static void notePlausibleOverloads(Sema &S, SourceLocation Loc, 01059 const UnresolvedSetImpl &Overloads, 01060 bool (*IsPlausibleResult)(QualType)) { 01061 if (!IsPlausibleResult) 01062 return noteOverloads(S, Overloads, Loc); 01063 01064 UnresolvedSet<2> PlausibleOverloads; 01065 for (OverloadExpr::decls_iterator It = Overloads.begin(), 01066 DeclsEnd = Overloads.end(); It != DeclsEnd; ++It) { 01067 const FunctionDecl *OverloadDecl = cast<FunctionDecl>(*It); 01068 QualType OverloadResultTy = OverloadDecl->getResultType(); 01069 if (IsPlausibleResult(OverloadResultTy)) 01070 PlausibleOverloads.addDecl(It.getDecl()); 01071 } 01072 noteOverloads(S, PlausibleOverloads, Loc); 01073 } 01074 01075 /// Determine whether the given expression can be called by just 01076 /// putting parentheses after it. Notably, expressions with unary 01077 /// operators can't be because the unary operator will start parsing 01078 /// outside the call. 01079 static bool IsCallableWithAppend(Expr *E) { 01080 E = E->IgnoreImplicit(); 01081 return (!isa<CStyleCastExpr>(E) && 01082 !isa<UnaryOperator>(E) && 01083 !isa<BinaryOperator>(E) && 01084 !isa<CXXOperatorCallExpr>(E)); 01085 } 01086 01087 bool Sema::tryToRecoverWithCall(ExprResult &E, const PartialDiagnostic &PD, 01088 bool ForceComplain, 01089 bool (*IsPlausibleResult)(QualType)) { 01090 SourceLocation Loc = E.get()->getExprLoc(); 01091 SourceRange Range = E.get()->getSourceRange(); 01092 01093 QualType ZeroArgCallTy; 01094 UnresolvedSet<4> Overloads; 01095 if (isExprCallable(*E.get(), ZeroArgCallTy, Overloads) && 01096 !ZeroArgCallTy.isNull() && 01097 (!IsPlausibleResult || IsPlausibleResult(ZeroArgCallTy))) { 01098 // At this point, we know E is potentially callable with 0 01099 // arguments and that it returns something of a reasonable type, 01100 // so we can emit a fixit and carry on pretending that E was 01101 // actually a CallExpr. 01102 SourceLocation ParenInsertionLoc = 01103 PP.getLocForEndOfToken(Range.getEnd()); 01104 Diag(Loc, PD) 01105 << /*zero-arg*/ 1 << Range 01106 << (IsCallableWithAppend(E.get()) 01107 ? FixItHint::CreateInsertion(ParenInsertionLoc, "()") 01108 : FixItHint()); 01109 notePlausibleOverloads(*this, Loc, Overloads, IsPlausibleResult); 01110 01111 // FIXME: Try this before emitting the fixit, and suppress diagnostics 01112 // while doing so. 01113 E = ActOnCallExpr(0, E.take(), ParenInsertionLoc, 01114 MultiExprArg(*this, 0, 0), 01115 ParenInsertionLoc.getLocWithOffset(1)); 01116 return true; 01117 } 01118 01119 if (!ForceComplain) return false; 01120 01121 Diag(Loc, PD) << /*not zero-arg*/ 0 << Range; 01122 notePlausibleOverloads(*this, Loc, Overloads, IsPlausibleResult); 01123 E = ExprError(); 01124 return true; 01125 }