-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
GENERATE() changes compile time length of arrays #2012
Comments
Right, so, there are two parts to this.
I cannot change 1), and fixing 2) by forcing a pointer decay would break people who already use it with all literals having the same size. I will have to think about whether there is an use case for having different size string literals deduce as the same size, and if not, In the meantime, if you have this issue in your code, consider passing |
Thank you for answer. For general case there is the only solution - detect reference to array. It is a question what to do with it. One option is static assert for length, but it is code breakage. If somebody used Detection itself can be implemented with function overload, e.g., |
Update: I've decided that for v3 I am going to make arrays decay. Not sure if I will port this to v2 as well. |
Description
GENERATE macro takes type of first argument and cast all other args to it. It is ok for most cases but for string literals it is bad. It takes length of first literal and force it for all.
TEST_CASE("t", "[t]") { auto& str = GENERATE("123", "1"); WARN(typeid(str).name()); }
Output
warning: A4_c
Usually you don't see it. If you use std::string to store the result of GENERATE then everything works fine, all lengths are correct. But some string implementations use length from type of array. E.g., https://stackoverflow.com/questions/2384107/magic-arguments-in-function-templates
This template magic works wrong with GENERATE. I cann't say this is a bug, because I have no idea how to fix it. May be detect arrays and generate compilation error if lengths are different?
It is very bad rule in C++ that references to arrays with different lengths can be cast to each other.
The text was updated successfully, but these errors were encountered: