From 80fa4022cae9f6e9d879d9f7ff1f2753a2a45bbc Mon Sep 17 00:00:00 2001 From: Bert Date: Thu, 23 Jun 2016 23:12:45 +0200 Subject: [PATCH] support Visual C++ throw(...) --- .../org/sonar/cxx/parser/CxxGrammarImpl.java | 7 ++++++- .../cxx/parser/ExceptionHandlingTest.java | 2 ++ .../parser/own/VC/exception-specification.cc | 18 ++++++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 cxx-squid/src/test/resources/parser/own/VC/exception-specification.cc diff --git a/cxx-squid/src/main/java/org/sonar/cxx/parser/CxxGrammarImpl.java b/cxx-squid/src/main/java/org/sonar/cxx/parser/CxxGrammarImpl.java index 26c780ee9c..375908f67c 100644 --- a/cxx-squid/src/main/java/org/sonar/cxx/parser/CxxGrammarImpl.java +++ b/cxx-squid/src/main/java/org/sonar/cxx/parser/CxxGrammarImpl.java @@ -1751,7 +1751,12 @@ private static void exceptionHandling(LexerfulGrammarBuilder b) { b.rule(dynamicExceptionSpecification).is(CxxKeyword.THROW, "(", b.optional(typeIdList), ")"); // C++ - b.rule(typeIdList).is(typeId, b.optional("..."), b.zeroOrMore(",", typeId, b.optional("..."))); // C++ + b.rule(typeIdList).is( + b.firstOf( + b.sequence(typeId, b.optional("..."), b.zeroOrMore(",", typeId, b.optional("..."))), // C++ + "..."// Microsoft extension + ) + ); b.rule(noexceptSpecification).is( b.firstOf( diff --git a/cxx-squid/src/test/java/org/sonar/cxx/parser/ExceptionHandlingTest.java b/cxx-squid/src/test/java/org/sonar/cxx/parser/ExceptionHandlingTest.java index f89cc16f3e..74155d3328 100644 --- a/cxx-squid/src/test/java/org/sonar/cxx/parser/ExceptionHandlingTest.java +++ b/cxx-squid/src/test/java/org/sonar/cxx/parser/ExceptionHandlingTest.java @@ -48,6 +48,7 @@ public void exceptionSpecification_reallife() { p.setRootRule(g.rule(CxxGrammarImpl.exceptionSpecification)); assertThat(p).matches("throw()"); + assertThat(p).matches("throw(...)"); } @Test @@ -60,6 +61,7 @@ public void typeIdList() { assertThat(p).matches("typeId ..."); assertThat(p).matches("typeId , typeId"); assertThat(p).matches("typeId , typeId ..."); + assertThat(p).matches("..."); } @Test diff --git a/cxx-squid/src/test/resources/parser/own/VC/exception-specification.cc b/cxx-squid/src/test/resources/parser/own/VC/exception-specification.cc new file mode 100644 index 0000000000..fd43e8bcf5 --- /dev/null +++ b/cxx-squid/src/test/resources/parser/own/VC/exception-specification.cc @@ -0,0 +1,18 @@ +int myfunc1() throw(){ +} + +int myfunc2() throw(int){ +} + +int myfunc3() throw(int, int){ +} + +int myfunc4() throw(int ...){ +} + +int myfunc5() throw(int ..., int ...){ +} + +int myfunc() throw(...){ +} +