forked from SonarOpenCommunity/sonar-cxx
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- add final grammar changes for C++23 - auto(x) and auto{x} [P0849R8](https://wg21.link/P0849R8) - duplicate attributes [P2156R1](https://wg21.link/P2156R1) - static constexpr [P2647R1](https://wg21.link/P2647R1) - static operator [P2589R0](https://wg21.link/P2589R0) [P1169R4](https://wg21.link/P1169R4) - linked SonarOpenCommunity#2536
- Loading branch information
Showing
9 changed files
with
123 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
void foo() { | ||
// variable definition | ||
auto v(x); | ||
auto v{x}; | ||
ClassTemplate v(x); | ||
ClassTemplate v{x}; | ||
|
||
// new expression | ||
new auto(x); | ||
new auto{x}; | ||
new ClassTemplate(x); | ||
new ClassTemplate{x}; | ||
} | ||
|
||
// function-style cast | ||
template<typename T, typename U> | ||
T cast1(U const &u) { | ||
return auto(u); | ||
} | ||
template<typename T, typename U> | ||
T cast2(U const &u) { | ||
return auto{u}; | ||
} | ||
template<typename T, typename U> | ||
T cast3(U const &u) { | ||
return ClassTemplate(u); | ||
} | ||
template<typename T, typename U> | ||
T cast4(U const &u) { | ||
return ClassTemplate{u}; | ||
} |
8 changes: 8 additions & 0 deletions
8
cxx-squid/src/test/resources/parser/own/C++23/duplicate-attributes.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[[gnu::sample]] [[gnu::sample]] [[gnu::hot]] [[nodiscard]] | ||
inline int f(); // declare f with four attributes | ||
|
||
[[gnu::sample, gnu::sample, gnu::hot, nodiscard]] | ||
int f(); // same as above, but uses a single attr specifier that contains four attributes | ||
|
||
[[using gnu : sample, sample, hot]] [[nodiscard]] [[gnu::sample]] | ||
int f(); // same as above |
9 changes: 9 additions & 0 deletions
9
cxx-squid/src/test/resources/parser/own/C++23/static-constexpr.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
char xdigit1(int n) { | ||
static constexpr char digits[] = "0123456789abcdef"; | ||
return digits[n]; | ||
} | ||
|
||
constexpr char xdigit2(int n) { | ||
static constexpr char digits[] = "0123456789abcdef"; // C++23 | ||
return digits[n]; | ||
} |
56 changes: 56 additions & 0 deletions
56
cxx-squid/src/test/resources/parser/own/C++23/static-operator.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// --- static operator() --- | ||
|
||
// Overload Resolution | ||
struct less { | ||
static constexpr auto operator()(int i, int j) -> bool { | ||
return i < j; | ||
} | ||
using P = bool( * )(int, int); | ||
operator P() const { | ||
return operator(); | ||
} | ||
}; | ||
|
||
void foo() { | ||
static_assert(less {}(1, 2)); | ||
} | ||
|
||
// Lambdas | ||
auto four = []() static { | ||
return 4; | ||
}; | ||
|
||
// Static lambdas with capture | ||
auto under_lock = [lock = std::unique_lock(mtx)]() static { | ||
/* do something */ ; | ||
}; | ||
|
||
// --- static operator[] --- | ||
|
||
template < typename T, std::size_t S > struct array: std::array < T, S > { | ||
static constexpr inline std::size_t extent = []() -> std::size_t { | ||
if constexpr(_is_array < T > ) { | ||
return 1 + T::extent; | ||
} | ||
return 1; | ||
}(); | ||
constexpr decltype(auto) | ||
operator[](std::size_t idx) { | ||
return * (this -> data() + idx); | ||
} | ||
constexpr decltype(auto) | ||
operator[](std::size_t idx, convertible_to < std::size_t > auto && ...args) | ||
requires(sizeof...(args) < extent) && (sizeof...(args) >= 1) { | ||
typename std::array < T, S > ::reference v = * (this -> data() + idx); | ||
return v.operator[](args...); | ||
} | ||
constexpr decltype(auto) | ||
operator[](std::size_t idx) const { | ||
return * (this -> data() + idx); | ||
} | ||
constexpr decltype(auto) | ||
operator[](std::size_t idx, convertible_to < std::size_t > auto && ...args) const requires(sizeof...(args) < extent) && (sizeof...(args) >= 1) { | ||
typename std::array < T, S > ::reference v = * (this -> data() + idx); | ||
return v.operator[](args...); | ||
} | ||
}; |