-
Notifications
You must be signed in to change notification settings - Fork 772
[expr.sizeof] Clarify padding in class types CWG2609 #5560
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
base: main
Are you sure you want to change the base?
Conversation
This originated from cplusplus/CWG#89, right? |
Right. |
Doesn't this clarification negative the consensus in cplusplus/CWG#89 (comment)
|
No. We don't say here that |
#5087 suggested that "The representation of a fundamental type is unspecified except as stated in this subclause.". Is such change still suitable? |
The result of
Isn't that just saying the result is the size of the class type? I don't understand what's the difference here. Moreover, the result of
Isn't that exactly implying that the result of Anyway, [basic.def.odr](especially p14) didn't impose any requirement on the size of a class. |
[basic.def.odr] says all class types with a given name are the same throughout the program. Note that |
Generally speaking, [basic.def.odr] essentially requires these user-declared declarations shall obey some rules(such as they have the same tokens) such that they have a consistent definition as if they are a single definition. However, as the padding bits, are not controlled by users. Instead, they are implied processed by the implementations according to the relevant circumstances. Either from this perspective or from the normative definitions in [basic.def.odr], they all impose no requirement that all definitions of the same class should have a consistent size unless we can point out the rule.
Why not squarely say
Honestly, I don't see, if we say
why is the result of |
I think they do strongly imply that the same class should have a consistent size. Otherwise, it's even not guaranteed that variable definition like |
AFAIK, the touched rules for your case
So, in order to ensure that each evaluation of |
|
[temp.over.link] didn't mention the result of an expression at all, it just says
|
Obviously, we can only meaningfully talk about the possibly unspecified runtime result of Nobody should be talking about templates here. |
Perhaps my fault. I meant that I should use the aforementioned certain type |
AFAIK, we can only check whether stuff satisfies a particular rule or not rather than that in order to satisfy the rule the stuff must be what it might not be. char x[size]; The rule says The truth should be that since some rules explicitly say the result of In other words, we can infer the result from conditions but we cannot infer conditions from a result. The result is |
No. I only meant the single array If a strict requirement is actually missing, both "a program containing such declarations is well-formed" and " |
Don't you try to infer the conditions from the result? You mean, in order to get that result, you predict the condition must be true. The truth should be
For example: float f = 256.0f;
char c = f; You shouldn't infer that the program is well-formed just because each run of this program would always get a constant value for The justified process is that, given a set of conditions, if all conditions in the set do not violate any rule defined in this document, then the program is well-formed. Instead of saying that since the program always has a consistent observable result, thus all conditions that form that program are all defined. |
My oversight. I meant to say the value should not vary among all of the aforementioned instances (that determine the type of |
This should have at least an explicit rule to say the result of
Isn't it together with [expr.sizeof] p2
, [basic.types.general] p4
, and [intro.memory] p1
can conclude that the bytes in an object of class type are unspecified? Again, how many bytes depend on how many bits there are, the number of the bits is unspecified since the number of padding bits is unspecified, so the number of the former is as well. Their relationships can be deducible in mathematics. |
Handled by CWG2609 |
Fixes cplusplus/CWG#89