Skip to content

Commit ade2653

Browse files
committed
C++14: add type traits helper support
- supporting type traits helper as typeParameter (e.g. std::enable_if_t) - close #2305 ```C++ template <typename T, typename std::enable_if <std::is_base_of<BaseT, T>::value, int>::type = 0> class A {}; template <typename T, std::enable_if_t<std::is_base_of<BaseT, T>::value, int> = 0> class C {}; ```
1 parent 6e1d456 commit ade2653

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

cxx-squid/src/main/java/org/sonar/cxx/parser/CxxGrammarImpl.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2185,7 +2185,13 @@ private static void templates(LexerfulGrammarBuilder b) {
21852185
b.sequence( // C++ (PEG: different order) todo one up
21862186
typeConstraint,
21872187
b.firstOf(
2188-
b.sequence(b.optional(IDENTIFIER), "=", typeId), // C++
2188+
b.sequence(
2189+
b.optional(IDENTIFIER), "=",
2190+
b.firstOf(
2191+
typeId, // C++
2192+
initializerClause // syntax sugar to handle type traits providing type name (e.g. std::enable_if_t<>=0)
2193+
)
2194+
),
21892195
b.sequence(b.optional("..."), b.optional(IDENTIFIER)) // C++ (PEG: different order)
21902196
)
21912197
)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// C++14 type traits helper were added (issue #2305)
2+
3+
// using types trait with/without helper with/without default value
4+
template <typename T, typename std::enable_if <std::is_base_of<BaseT, T>::value, int>::type = 0> class A {};
5+
template <typename T, typename std::enable_if <std::is_base_of<BaseT, T>::value, int>::type> class B {};
6+
template <typename T, std::enable_if_t<std::is_base_of<BaseT, T>::value, int> = 0> class C {};
7+
template <typename T, std::enable_if_t<std::is_base_of<BaseT, T>::value, int>> class D {};

0 commit comments

Comments
 (0)