Skip to content

Commit fd6fce7

Browse files
committed
Add if not test
1 parent e101a74 commit fd6fce7

File tree

4 files changed

+30
-21
lines changed

4 files changed

+30
-21
lines changed

clang/include/clang/Sema/SemaCodeCompletion.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ class SemaCodeCompletion : public SemaBase {
152152
void CodeCompleteDesignator(const QualType BaseType,
153153
llvm::ArrayRef<Expr *> InitExprs,
154154
const Designation &D);
155-
void CodeCompleteIfConst(Scope *S) const;
155+
void CodeCompleteIfConst(Scope *S, bool AfterExclaim) const;
156156
void CodeCompleteAfterIf(Scope *S, bool IsBracedThen);
157157

158158
void CodeCompleteQualifiedId(Scope *S, CXXScopeSpec &SS, bool EnteringContext,

clang/lib/Parse/ParseStmt.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1556,7 +1556,7 @@ StmtResult Parser::ParseIfStatement(SourceLocation *TrailingElseLoc) {
15561556

15571557
if (Tok.is(tok::code_completion)) {
15581558
cutOffParsing();
1559-
Actions.CodeCompletion().CodeCompleteIfConst(getCurScope());
1559+
Actions.CodeCompletion().CodeCompleteIfConst(getCurScope(), NotLocation.isValid());
15601560
return StmtError();
15611561
}
15621562
}

clang/lib/Sema/SemaCodeComplete.cpp

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6749,29 +6749,31 @@ void SemaCodeCompletion::CodeCompleteInitializer(Scope *S, Decl *D) {
67496749
CodeCompleteExpression(S, Data);
67506750
}
67516751

6752-
void SemaCodeCompletion::CodeCompleteIfConst(Scope *S) const {
6752+
void SemaCodeCompletion::CodeCompleteIfConst(Scope *S, bool AfterExclaim) const {
67536753
ResultBuilder Results(SemaRef, CodeCompleter->getAllocator(),
67546754
CodeCompleter->getCodeCompletionTUInfo(),
67556755
CodeCompletionContext::CCC_Other);
67566756
CodeCompletionBuilder Builder(Results.getAllocator(),
67576757
Results.getCodeCompletionTUInfo());
67586758
Results.EnterNewScope();
67596759
if (getLangOpts().CPlusPlus17) {
6760-
if (Results.includeCodePatterns()) {
6761-
Builder.AddTypedTextChunk("constexpr");
6762-
Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace);
6763-
Builder.AddChunk(CodeCompletionString::CK_LeftParen);
6764-
Builder.AddPlaceholderChunk("condition");
6765-
Builder.AddChunk(CodeCompletionString::CK_RightParen);
6766-
Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace);
6767-
Builder.AddChunk(CodeCompletionString::CK_LeftBrace);
6768-
Builder.AddChunk(CodeCompletionString::CK_VerticalSpace);
6769-
Builder.AddPlaceholderChunk("statements");
6770-
Builder.AddChunk(CodeCompletionString::CK_VerticalSpace);
6771-
Builder.AddChunk(CodeCompletionString::CK_RightBrace);
6772-
Results.AddResult({Builder.TakeString()});
6773-
} else {
6774-
Results.AddResult({"constexpr"});
6760+
if (!AfterExclaim) {
6761+
if (Results.includeCodePatterns()) {
6762+
Builder.AddTypedTextChunk("constexpr");
6763+
Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace);
6764+
Builder.AddChunk(CodeCompletionString::CK_LeftParen);
6765+
Builder.AddPlaceholderChunk("condition");
6766+
Builder.AddChunk(CodeCompletionString::CK_RightParen);
6767+
Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace);
6768+
Builder.AddChunk(CodeCompletionString::CK_LeftBrace);
6769+
Builder.AddChunk(CodeCompletionString::CK_VerticalSpace);
6770+
Builder.AddPlaceholderChunk("statements");
6771+
Builder.AddChunk(CodeCompletionString::CK_VerticalSpace);
6772+
Builder.AddChunk(CodeCompletionString::CK_RightBrace);
6773+
Results.AddResult({Builder.TakeString()});
6774+
} else {
6775+
Results.AddResult({"constexpr"});
6776+
}
67756777
}
67766778
}
67776779
if (getLangOpts().CPlusPlus23) {
Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1+
template <bool Flag>
12
void test() {
2-
if c
3-
// RUN: %clang_cc1 -fsyntax-only -std=c++17 -code-completion-at=%s:2:7 %s -o - | FileCheck -check-prefix=CHECK-CXX17 %s
4-
// RUN: %clang_cc1 -fsyntax-only -std=c++23 -code-completion-at=%s:2:7 %s -o - | FileCheck -check-prefix=CHECK-CXX23 %s
3+
if constexpr (Flag) {
4+
return;
5+
}
6+
// RUN: %clang_cc1 -fsyntax-only -std=c++17 -code-completion-at=%s:3:7 %s -o - | FileCheck -check-prefix=CHECK-CXX17 %s
7+
// RUN: %clang_cc1 -fsyntax-only -std=c++23 -code-completion-at=%s:3:7 %s -o - | FileCheck -check-prefix=CHECK-CXX23 %s
58
// CHECK-CXX17: constexpr
69
// CHECK-CXX23: consteval
10+
if !c
11+
// RUN: %clang_cc1 -fsyntax-only -std=c++23 -code-completion-at=%s:10:8 %s -o - | FileCheck -check-prefix=CHECK-CXX23-NOT %s
12+
// CHECK-CXX23-NOT: consteval
13+
}

0 commit comments

Comments
 (0)