Skip to content

Commit

Permalink
Merge pull request universal-ctags#1747 from masatake/cxx-handling-fu…
Browse files Browse the repository at this point in the history
…nction-try-block

C++: handle function-try-block
  • Loading branch information
pragmaware authored Apr 30, 2018
2 parents 54afb0f + 98ba4ee commit 576c750
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions Units/parser-cxx.r/function_try_block.d/args.ctags
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--sort=no
4 changes: 4 additions & 0 deletions Units/parser-cxx.r/function_try_block.d/expected.tags
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
S input.cxx /^struct S {$/;" s file:
m input.cxx /^ std::string m;$/;" m struct:S typeref:typename:std::string file:
S input.cxx /^ S(const std::string& arg) try : m(arg, 100) {$/;" f struct:S file:
f input.cxx /^int f(int n = 2) try {$/;" f typeref:typename:int
20 changes: 20 additions & 0 deletions Units/parser-cxx.r/function_try_block.d/input.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/* Taken from
* http://en.cppreference.com/w/cpp/language/function-try-block */

struct S {
std::string m;
S(const std::string& arg) try : m(arg, 100) {
std::cout << "constructed, mn = " << m << '\n';
} catch(const std::exception& e) {
std::cerr << "arg=" << arg << " failed: " << e.what() << '\n';
} // implicit throw; here
};

int f(int n = 2) try {
++n; // increments the function parameter
throw n;
} catch(...) {
++n; // n is in scope and still refers to the function parameter
assert(n == 4);
return n;
}
9 changes: 9 additions & 0 deletions parsers/cxx/cxx_parser_block.c
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,15 @@ static bool cxxParserParseBlockInternal(bool bExpectClosingBracket)
cppBeginStatement();
break;
case CXXKeywordTRY:
if (g_cxx.pToken->pPrev
&& cxxTokenTypeIs(g_cxx.pToken->pPrev, CXXTokenTypeParenthesisChain))
{
/* Maybe we are at "try" of "Function-try-block" like
int f(int n = 2) try { ...
Let's ignore this "try". */
continue;
}
/* Fall through */
case CXXKeywordELSE:
case CXXKeywordDO:
// parse as normal statement/block
Expand Down

0 comments on commit 576c750

Please sign in to comment.