Skip to content

Commit c40dbbb

Browse files
committed
Add noexcept to decl in override code completion
1 parent 71022ee commit c40dbbb

File tree

1 file changed

+32
-31
lines changed

1 file changed

+32
-31
lines changed

clang/lib/Sema/SemaCodeComplete.cpp

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ class ResultBuilder {
184184

185185
/// Overloaded C++ member functions found by SemaLookup.
186186
/// Used to determine when one overload is dominated by another.
187-
llvm::DenseMap<std::pair<DeclContext *, /*Name*/uintptr_t>, ShadowMapEntry>
187+
llvm::DenseMap<std::pair<DeclContext *, /*Name*/ uintptr_t>, ShadowMapEntry>
188188
OverloadMap;
189189

190190
/// If we're potentially referring to a C++ member function, the set
@@ -1426,16 +1426,16 @@ void ResultBuilder::AddResult(Result R, DeclContext *CurContext,
14261426
}
14271427
// Detect cases where a ref-qualified method cannot be invoked.
14281428
switch (Method->getRefQualifier()) {
1429-
case RQ_LValue:
1430-
if (ObjectKind != VK_LValue && !MethodQuals.hasConst())
1431-
return;
1432-
break;
1433-
case RQ_RValue:
1434-
if (ObjectKind == VK_LValue)
1435-
return;
1436-
break;
1437-
case RQ_None:
1438-
break;
1429+
case RQ_LValue:
1430+
if (ObjectKind != VK_LValue && !MethodQuals.hasConst())
1431+
return;
1432+
break;
1433+
case RQ_RValue:
1434+
if (ObjectKind == VK_LValue)
1435+
return;
1436+
break;
1437+
case RQ_None:
1438+
break;
14391439
}
14401440

14411441
/// Check whether this dominates another overloaded method, which should
@@ -1483,9 +1483,7 @@ void ResultBuilder::AddResult(Result R) {
14831483
void ResultBuilder::EnterNewScope() { ShadowMaps.emplace_back(); }
14841484

14851485
/// Exit from the current scope.
1486-
void ResultBuilder::ExitScope() {
1487-
ShadowMaps.pop_back();
1488-
}
1486+
void ResultBuilder::ExitScope() { ShadowMaps.pop_back(); }
14891487

14901488
/// Determines whether this given declaration will be found by
14911489
/// ordinary name lookup.
@@ -2468,7 +2466,8 @@ static void AddOrdinaryNameResults(Sema::ParserCompletionContext CCC, Scope *S,
24682466
ReturnType = Method->getReturnType();
24692467
else if (SemaRef.getCurBlock() &&
24702468
!SemaRef.getCurBlock()->ReturnType.isNull())
2471-
ReturnType = SemaRef.getCurBlock()->ReturnType;;
2469+
ReturnType = SemaRef.getCurBlock()->ReturnType;
2470+
;
24722471
if (ReturnType.isNull() || ReturnType->isVoidType()) {
24732472
Builder.AddTypedTextChunk("return");
24742473
Builder.AddChunk(CodeCompletionString::CK_SemiColon);
@@ -3294,7 +3293,7 @@ AddFunctionTypeQualsToCompletionString(CodeCompletionBuilder &Result,
32943293
}
32953294

32963295
static void
3297-
AddFunctionExceptSpecToCompletionString(CodeCompletionBuilder &Result,
3296+
AddFunctionExceptSpecToCompletionString(std::string &NameAndSignature,
32983297
const FunctionDecl *Function) {
32993298
const auto *Proto = Function->getType()->getAs<FunctionProtoType>();
33003299
if (!Proto)
@@ -3304,7 +3303,7 @@ AddFunctionExceptSpecToCompletionString(CodeCompletionBuilder &Result,
33043303
switch (ExceptInfo.Type) {
33053304
case EST_BasicNoexcept:
33063305
case EST_NoexceptTrue:
3307-
Result.AddInformativeChunk(" noexcept");
3306+
NameAndSignature += " noexcept";
33083307
break;
33093308

33103309
default:
@@ -3527,6 +3526,13 @@ CodeCompletionResult::createCodeCompletionStringForOverride(
35273526
std::string NameAndSignature;
35283527
// For overrides all chunks go into the result, none are informative.
35293528
printOverrideString(*CCS, BeforeName, NameAndSignature);
3529+
3530+
// If the virtual function is declared with "noexcept", add it in the result
3531+
// code completion string.
3532+
const auto *VirtualFunc = dyn_cast<FunctionDecl>(Declaration);
3533+
assert(VirtualFunc && "overridden decl must be a function");
3534+
AddFunctionExceptSpecToCompletionString(NameAndSignature, VirtualFunc);
3535+
35303536
NameAndSignature += " override";
35313537

35323538
Result.AddTextChunk(Result.getAllocator().CopyString(BeforeName));
@@ -3580,7 +3586,6 @@ CodeCompletionString *CodeCompletionResult::createCodeCompletionStringForDecl(
35803586
AddFunctionParameterChunks(PP, Policy, Function, Result);
35813587
Result.AddChunk(CodeCompletionString::CK_RightParen);
35823588
AddFunctionTypeQualsToCompletionString(Result, Function);
3583-
AddFunctionExceptSpecToCompletionString(Result, Function);
35843589
};
35853590

35863591
if (const auto *Function = dyn_cast<FunctionDecl>(ND)) {
@@ -3663,7 +3668,6 @@ CodeCompletionString *CodeCompletionResult::createCodeCompletionStringForDecl(
36633668
AddFunctionParameterChunks(PP, Policy, Function, Result);
36643669
Result.AddChunk(CodeCompletionString::CK_RightParen);
36653670
AddFunctionTypeQualsToCompletionString(Result, Function);
3666-
AddFunctionExceptSpecToCompletionString(Result, Function);
36673671
return Result.TakeString();
36683672
}
36693673

@@ -4770,7 +4774,8 @@ static void AddEnumerators(ResultBuilder &Results, ASTContext &Context,
47704774
EnumDecl *Enum, DeclContext *CurContext,
47714775
const CoveredEnumerators &Enumerators) {
47724776
NestedNameSpecifier *Qualifier = Enumerators.SuggestedQualifier;
4773-
if (Context.getLangOpts().CPlusPlus && !Qualifier && Enumerators.Seen.empty()) {
4777+
if (Context.getLangOpts().CPlusPlus && !Qualifier &&
4778+
Enumerators.Seen.empty()) {
47744779
// If there are no prior enumerators in C++, check whether we have to
47754780
// qualify the names of the enumerators that we suggest, because they
47764781
// may not be visible in this scope.
@@ -5173,8 +5178,7 @@ AddObjCProperties(const CodeCompletionContext &CCContext,
51735178
AllowNullaryMethods, CurContext, AddedProperties,
51745179
Results, IsBaseExprStatement, IsClassProperty,
51755180
/*InOriginalClass*/ false);
5176-
} else if (const auto *Category =
5177-
dyn_cast<ObjCCategoryDecl>(Container)) {
5181+
} else if (const auto *Category = dyn_cast<ObjCCategoryDecl>(Container)) {
51785182
// Look through protocols.
51795183
for (auto *P : Category->protocols())
51805184
AddObjCProperties(CCContext, P, AllowCategories, AllowNullaryMethods,
@@ -6032,8 +6036,7 @@ void Sema::CodeCompleteCase(Scope *S) {
60326036

60336037
Expr *CaseVal = Case->getLHS()->IgnoreParenCasts();
60346038
if (auto *DRE = dyn_cast<DeclRefExpr>(CaseVal))
6035-
if (auto *Enumerator =
6036-
dyn_cast<EnumConstantDecl>(DRE->getDecl())) {
6039+
if (auto *Enumerator = dyn_cast<EnumConstantDecl>(DRE->getDecl())) {
60376040
// We look into the AST of the case statement to determine which
60386041
// enumerator was named. Alternatively, we could compute the value of
60396042
// the integral constant expression, then compare it against the
@@ -8260,11 +8263,10 @@ void Sema::CodeCompleteObjCInstanceMessage(Scope *S, Expr *Receiver,
82608263
return;
82618264
RecExpr = Conv.get();
82628265
}
8263-
QualType ReceiverType = RecExpr
8264-
? RecExpr->getType()
8265-
: Super ? Context.getObjCObjectPointerType(
8266-
Context.getObjCInterfaceType(Super))
8267-
: Context.getObjCIdType();
8266+
QualType ReceiverType = RecExpr ? RecExpr->getType()
8267+
: Super ? Context.getObjCObjectPointerType(
8268+
Context.getObjCInterfaceType(Super))
8269+
: Context.getObjCIdType();
82688270

82698271
// If we're messaging an expression with type "id" or "Class", check
82708272
// whether we know something special about the receiver that allows
@@ -10113,8 +10115,7 @@ void Sema::CodeCompleteIncludedFile(llvm::StringRef Dir, bool Angled) {
1011310115
};
1011410116

1011510117
// Helper: scans IncludeDir for nice files, and adds results for each.
10116-
auto AddFilesFromIncludeDir = [&](StringRef IncludeDir,
10117-
bool IsSystem,
10118+
auto AddFilesFromIncludeDir = [&](StringRef IncludeDir, bool IsSystem,
1011810119
DirectoryLookup::LookupType_t LookupType) {
1011910120
llvm::SmallString<128> Dir = IncludeDir;
1012010121
if (!NativeRelDir.empty()) {

0 commit comments

Comments
 (0)