This repository has been archived by the owner on Jun 3, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 26
Parse qualifiers correctly #347
Comments
jyn514
added
bug
Something isn't working
parser
Issue to do with parsing the abstract syntax tree
labels
Mar 15, 2020
13 tasks
Nope, not fixed: int f(const int *p) {
const int *q;
p = q;
}
<stdin>:3:3 error: invalid program: cannot assign to variable 'p' with `const` qualifier
p = q;
^^^^ |
Relevant code: Lines 273 to 291 in 0e36d97
I think I need to pass in &mut specs.qualifiers to parse_declarator .
|
More test cases:
|
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Basically the same as #49.
Expected behavior
int *const c
is not the same asint const *c
The
int *const c
declares c as immutable, while the data it points to can be modified.int const *c
declares the data c points to as const, while the variable c can still be modified. Currently we have this backwards.Code
C Standard
6.7.6.1p3:
3 EXAMPLE The following pair of declarations demonstrates the difference between a ''variable pointer to a constant value'' and a ''constant pointer to a variable value''.
The contents of any object pointed to by ptr_to_constant shall not be modified through that pointer, but ptr_to_constant itself may be changed to point to another object. Similarly, the contents of the int pointed to by constant_ptr may be modified, but constant_ptr itself shall always point to the same location.
The text was updated successfully, but these errors were encountered: