Skip to content

Commit

Permalink
Merge pull request #2116 from guwirth/close-793
Browse files Browse the repository at this point in the history
handle type traits ...::type
  • Loading branch information
guwirth authored Apr 22, 2021
2 parents 316d3cb + f2cdeca commit fa66ecc
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
13 changes: 10 additions & 3 deletions cxx-squid/src/main/java/org/sonar/cxx/parser/CxxGrammarImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,12 @@ private static void expressions(LexerfulGrammarBuilder b) {
).skipIfOneChild();

b.rule(relationalExpression).is(
compareExpression, b.zeroOrMore(b.firstOf("<", ">", "<=", ">="), compareExpression) // C++
compareExpression,
b.zeroOrMore(
b.firstOf(
"<", b.sequence(">", b.nextNot("::", "type")), "<=", ">="),
compareExpression
) // C++
).skipIfOneChild();

b.rule(equalityExpression).is(
Expand Down Expand Up @@ -2204,8 +2209,10 @@ private static void templates(LexerfulGrammarBuilder b) {
)
);

b.rule(typeTraits).is( // syntax sugar to handle type trais (not part of standard)
nestedNameSpecifier, "type", b.optional("*"), b.optional("=", initializerClause)
b.rule(typeTraits).is( // syntax sugar to handle type traits ...::type (not part of C++ grammar)
b.zeroOrMore(b.sequence(IDENTIFIER, "::")),
simpleTemplateId, "::", "type", b.optional("*"),
b.optional("=", initializerClause)
);

b.rule(innerTypeParameter).is(
Expand Down
12 changes: 12 additions & 0 deletions cxx-squid/src/test/resources/parser/own/C++11/type-traits.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,15 @@ void destroy(T* t)
std::cout << "destroying non-trivially destructible T\n";
t->~T();
}

// issue #793
template<class T,
typename std::enable_if<
!std::is_trivially_destructible<T>{} &&
(std::is_class<T>{} || std::is_union<T>{})
>::type* = nullptr>
void destroy(T* t)
{
std::cout << "destroying non-trivially destructible T\n";
t->~T();
}

0 comments on commit fa66ecc

Please sign in to comment.