-
Notifications
You must be signed in to change notification settings - Fork 7
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
[expr.new] p16 should give more clear requirement #380
Comments
It seems that the integral value is 0 on all known implementations... Do we really want to allow non-zero offsets? The concerns are related to [basic.stc.dynamic.allocation] p3.2. I think we should harmonize the use of strictest fundamental alignment and new-extended alignment, by specifying that the strictest fundamental alignment is not a new-extended alignment. |
Ah right, I missed that rule, so I removed the additional part. |
I'm not seeing a problem here. The quoted rule allows implementations to put an array cookie at the start of an array allocation (this is needed for non-trivial types to run destructors when deleting the array), and constrains implementations that the result of the new-expression must still be sufficiently aligned for objects larger than char, given that the allocation function is already so constrained in [basic.stc.dynamic.allocation] p3.2. An implementation can choose that integral value as it sees fit; obviously, it needs to increase the size of the allocation accordingly. Is your suggested "such that" amendment supposed to be explanatory (which is normatively superfluous)? If not, what additional requirement would it impose that isn't already implied by things said elsewhere? |
This is covered by the previous sentence:
But |
I think we should impose a similar restriction on the adjustment for new T[N] where T are other types other than #include <iostream>
void* operator new[](std::size_t N){
auto p = malloc(N);
std::cout<<p<<std::endl;
return p;
}
void operator delete[](void* ptr) noexcept{
std::cout<< ptr<<std::endl;
free(ptr);
}
struct A{
virtual void show(){}
~A(){}
};
int main(){
A* table = new A[5];
std::cout<< "new result "<<table<<std::endl;
delete [] table;
} In the current wording, we do not impose the requirement for the address returned by allocation function and that of the new-expression. |
Right, but the rules of the language still allow it (maybe for uniform treatment). Not a defect, as far as I can see. Feel free to write a paper with some implementation analysis why we don't need that allowance (anymore).
We already do. The allocation function has to return storage that is suitably aligned; see [basic.stc.dynamic.allocation] p3.2. Since The special case for |
The returned address of the allocation function does indeed satisfy the alignment requirement of any object type, however, it does not mean, the implementation will choose an address that offsets the positive number of bytes from the returned address since we didn't impose the requirement on what the address the implementation can choose for the case in #380 (comment). |
We already have that requirement. The allocation function is required to return storage suitably aligned for an "A" (among other objects) due to the rule "if the allocation function is named operator new[], the storage is aligned for any object that does not have new-extended alignment (6.7.6) and is no larger than the requested size" The new-expression returns a pointer to the created array, whose elements must be suitably aligned (otherwise they can't exist). |
Full name of submitter (unless configured in github; will be published with the issue): Jim X
[expr.new] p16 says:
So, what the integral value could be? Is it can be any integral? Obviously, the integral cannot be an arbitrary value. As implied by [expr.new.note] p9
The offsets of an integral multiple of the strictest fundamental alignment should make the result of the new-expression satisfies the alignment requirement imposed by the object type.
Suggested Resolution
Incidentally, can the integral multiple of the strictest fundamental alignment really make the result satisfy therequirement? Consider a hypothetical example:Assume the allocation function returns the address with the value0x1
(because this address can satisfy alignment ofunsinged char
when the alignment is1
) and the alignment imposed byint
is4
. There exists no integral multiple of4
that make the result address satisfies by4
.The text was updated successfully, but these errors were encountered: