-
Notifications
You must be signed in to change notification settings - Fork 10.8k
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
typeof_unqual does not remove qualifiers from qualified array types #92667
Comments
@llvm/issue-subscribers-clang-frontend Author: None (Halalaluyafail3)
Clang does not remove qualifiers from qualified array types, i.e. array types with qualified element types with typeof_unqual in some situations. See [GCC bug 112841](https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112841) which has the following example:
```cpp
const char* const animals[] = {
"aardvark",
"bluejay",
"catte",
};
int main (int argc, char* argv[]) {
const char* animals2_array1[3];
typeof_unqual(animals) animals2_array;
animals2_array1[0] = 0;
animals2_array[0] = 0;
return 0;
}
```
Clang has `typeof_unqual(animals)` result in a const qualified type which results in the assignment `animals2_array[0] = 0;` failing.
|
This looks like the correct behavior to me. In the final version of C23, there's an example specific to this (C23 6.7.3.6p7 EXAMPLE 2):
Note: |
Properly remove qualifiers for both the element type and the array type Fixes llvm#92667
Oh, wait a second, something odd is going on here: https://godbolt.org/z/4r6M49WrT The static_assert passes, but the code still does not compile. So something is amiss. |
@AaronBallman Currently, only the top-level const was removed, leaving us with an invalid non-const array of const element type. So the array type matches the non-const type, but the element type does not (when checking if the modification is valid) This also allowed strange things like https://godbolt.org/z/11xG499PG |
Clang does not remove qualifiers from qualified array types, i.e. array types with qualified element types with typeof_unqual in some situations. See GCC bug 112841 which has the following example:
Clang has
typeof_unqual(animals)
result in a const qualified type which results in the assignmentanimals2_array[0] = 0;
failing.The text was updated successfully, but these errors were encountered: