Index: lib/Parse/ParseCXXInlineMethods.cpp =================================================================== --- lib/Parse/ParseCXXInlineMethods.cpp +++ lib/Parse/ParseCXXInlineMethods.cpp @@ -832,22 +832,24 @@ } } - if (Tok.isOneOf(tok::identifier, tok::kw_template)) { - Toks.push_back(Tok); - ConsumeToken(); - } else if (Tok.is(tok::code_completion)) { + if (Tok.is(tok::code_completion)) { Toks.push_back(Tok); ConsumeCodeCompletionToken(); - // Consume the rest of the initializers permissively. - // FIXME: We should be able to perform code-completion here even if - // there isn't a subsequent '{' token. - MightBeTemplateArgument = true; - break; + } + + if (Tok.isOneOf(tok::identifier, tok::kw_template)) { + Toks.push_back(Tok); + ConsumeToken(); } else { break; } } while (Tok.is(tok::coloncolon)); + if (Tok.is(tok::code_completion)) { + Toks.push_back(Tok); + ConsumeCodeCompletionToken(); + } + if (Tok.is(tok::less)) MightBeTemplateArgument = true; @@ -888,6 +890,23 @@ // means the initializer is malformed; we'll diagnose it later. if (!getLangOpts().CPlusPlus11) return false; + + const Token &PreviousToken = Toks[Toks.size() - 2]; + if (!MightBeTemplateArgument && + !PreviousToken.isOneOf(tok::identifier, tok::greater, + tok::greatergreater)) { + // Most likely the start of a function body rather than the start of a + // ctor-initializer. Check the token after the corresponding '}'. + TentativeParsingAction PA(*this); + if (SkipUntil(tok::r_brace) && + !Tok.isOneOf(tok::comma, tok::ellipsis, tok::l_brace)) { + // Consider there was a malformed initializer and this is the start + // of the function body + PA.Revert(); + return false; + } + PA.Revert(); + } } // Grab the initializer (or the subexpression of the template argument). Index: test/CodeCompletion/ctor-initializer.cpp =================================================================== --- test/CodeCompletion/ctor-initializer.cpp +++ test/CodeCompletion/ctor-initializer.cpp @@ -1,11 +1,13 @@ struct Base1 { Base1() : {} - // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:2:12 %s -o - | FileCheck -check-prefix=CHECK-CC1 %s + // RUN: %clang_cc1 -fsyntax-only -std=c++98 -code-completion-at=%s:2:12 %s -o - | FileCheck -check-prefix=CHECK-CC1 %s + // RUN: %clang_cc1 -fsyntax-only -std=c++14 -code-completion-at=%s:2:12 %s -o - | FileCheck -check-prefix=CHECK-CC1 %s // CHECK-CC1: COMPLETION: Pattern : member1(<#args#>) // CHECK-CC1: COMPLETION: Pattern : member2(<#args#> Base1(int) : member1(123), {} - // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:7:30 %s -o - | FileCheck -check-prefix=CHECK-CC2 %s + // RUN: %clang_cc1 -fsyntax-only -std=c++98 -code-completion-at=%s:8:30 %s -o - | FileCheck -check-prefix=CHECK-CC2 %s + // RUN: %clang_cc1 -fsyntax-only -std=c++14 -code-completion-at=%s:8:30 %s -o - | FileCheck -check-prefix=CHECK-CC2 %s // CHECK-CC2-NOT: COMPLETION: Pattern : member1(<#args#>) // CHECK-CC2: COMPLETION: Pattern : member2(<#args#> @@ -21,14 +23,16 @@ }; Derived::Derived() : {} -// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:23:22 %s -o - | FileCheck -check-prefix=CHECK-CC3 %s +// RUN: %clang_cc1 -fsyntax-only -std=c++98 -code-completion-at=%s:25:22 %s -o - | FileCheck -check-prefix=CHECK-CC3 %s +// RUN: %clang_cc1 -fsyntax-only -std=c++14 -code-completion-at=%s:25:22 %s -o - | FileCheck -check-prefix=CHECK-CC3 %s // CHECK-CC3: COMPLETION: Pattern : Base1(<#args#>) // CHECK-CC3: COMPLETION: Pattern : deriv1(<#args#>) Derived::Derived(int) try : { } catch (...) { } -// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:28:29 %s -o - | FileCheck -check-prefix=CHECK-CC4 %s +// RUN: %clang_cc1 -fsyntax-only -std=c++98 -code-completion-at=%s:31:29 %s -o - | FileCheck -check-prefix=CHECK-CC4 %s +// RUN: %clang_cc1 -fsyntax-only -std=c++14 -code-completion-at=%s:31:29 %s -o - | FileCheck -check-prefix=CHECK-CC4 %s // CHECK-CC4: COMPLETION: Pattern : Base1(<#args#>) // CHECK-CC4: COMPLETION: Pattern : deriv1(<#args#>) @@ -36,6 +40,7 @@ { } catch (...) { } -// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:35:39 %s -o - | FileCheck -check-prefix=CHECK-CC5 %s +// RUN: %clang_cc1 -fsyntax-only -std=c++98 -code-completion-at=%s:39:39 %s -o - | FileCheck -check-prefix=CHECK-CC5 %s +// RUN: %clang_cc1 -fsyntax-only -std=c++14 -code-completion-at=%s:39:39 %s -o - | FileCheck -check-prefix=CHECK-CC5 %s // CHECK-CC5-NOT: COMPLETION: Pattern : Base1(<#args#>) // CHECK-CC5: COMPLETION: Pattern : deriv1(<#args#>)