-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Report error on duplicate named arg names #4367
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 8 commits
167ec54
233d8d9
3d9a3e6
93b1425
36a6908
b6be6fe
1c156a3
9800147
7cf7957
e3bfecd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1060,17 +1060,34 @@ template <typename... Args> constexpr auto count_static_named_args() -> int { | |
| } | ||
|
|
||
| template <typename Char> struct named_arg_info { | ||
| FMT_CONSTEXPR named_arg_info() : name(nullptr), id(0) {} | ||
| FMT_CONSTEXPR named_arg_info(const Char* a_name, const int an_id) | ||
| : name(a_name), id(an_id) {} | ||
| const Char* name; | ||
| int id; | ||
| }; | ||
|
|
||
| template <typename Char> | ||
| FMT_CONSTEXPR void check_for_duplicate( | ||
| const named_arg_info<Char>* const named_args, const int named_arg_index, | ||
|
||
| const Char* const arg_name) { | ||
| const basic_string_view<Char> arg_name_view(arg_name); | ||
|
||
| for (auto i = 0; i < named_arg_index; ++i) { | ||
| if (basic_string_view<Char>(named_args[i].name) == arg_name_view) { | ||
| report_error("duplicate named args found"); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| template <typename Char, typename T, FMT_ENABLE_IF(!is_named_arg<T>::value)> | ||
| void init_named_arg(named_arg_info<Char>*, int& arg_index, int&, const T&) { | ||
| ++arg_index; | ||
| } | ||
|
|
||
| template <typename Char, typename T, FMT_ENABLE_IF(is_named_arg<T>::value)> | ||
| void init_named_arg(named_arg_info<Char>* named_args, int& arg_index, | ||
| int& named_arg_index, const T& arg) { | ||
| check_for_duplicate(named_args, named_arg_index, arg.name); | ||
| named_args[named_arg_index++] = {arg.name, arg_index++}; | ||
| } | ||
|
|
||
|
|
@@ -1084,6 +1101,7 @@ template <typename T, typename Char, | |
| FMT_ENABLE_IF(is_static_named_arg<T>::value)> | ||
| FMT_CONSTEXPR void init_static_named_arg(named_arg_info<Char>* named_args, | ||
| int& arg_index, int& named_arg_index) { | ||
| check_for_duplicate(named_args, named_arg_index, T::name); | ||
|
||
| named_args[named_arg_index++] = {T::name, arg_index++}; | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Initialization is done in
init*named_arg, we shouldn't duplicate it here.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm going to try your idea of only calling if the index is greater than zero, but if that doesn't work, I need the default construct and if I have the default construct, GCC10 will need the other one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both functions have been removed. The if check appeased GCC13, it seems.