-
Notifications
You must be signed in to change notification settings - Fork 249
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
[BUG] Bad operator=
error message for @value type
s
#1071
Comments
I'm definitely in favour of clear, friendly error messages. But instead of requiring all data members to have default initializers, I'd prefer the error to be something like: |
Hi there! Basically, the root cause here is that the AFAIU, in order to tell if adding such a constructor is valid, one just has to iterate over all the member variables and check that either:
In terms of code, I don't know how to implement some parts of these checks: basic_value: (inout t: meta::type_declaration) =
{
t.copyable();
for t.get_member_functions() do (inout mf) {
mf.require( !mf.is_protected() && !mf.is_virtual(),
"a value type may not have a protected or virtual function" );
mf.require( !mf.is_destructor() || mf.is_public() || mf.is_default_access(),
"a value type may not have a non-public destructor" );
}
if !t.has_default_ctor() {
for t.get_member_objects() do (in mo) {
mo.require(
mo.has_initializer() || /* if cpp2 type: */ mo./* get the type declaration */.has_default_ctor()
/* else: defer check to cpp1 compiler using std::is_default_constructible */,
"a value type must be default constructible"
);
}
t.add_member( "operator=: (out this) = { }");
}
} If some of you have ideas on how to proceed, I'd be very interested to discuss! |
@value type
s
@value type
soperator=
error message for @value type
s
For reference: #1259 |
I strongly recommend reading #821.
I suppose this ties back to #844. |
Hi folks!
I ran into a very confusing bug while experimenting with cppfront. Consider the following type:
Cppfront refuses to compile this code snippet and produces the following error message:
However, there is nothing wrong with the
operator=
here. The problem is actually that a value type must be default constructible, which is not the case in this example. This error message got me very confused at first, and I had to look into the sources to understand what was going on. Maybe the missing piece to get a better diagnostic is to require all data members of@value
types to be declared with a default initializer. What do you think of this?I'd be happy to submit a PR to fix this in the definition of the
@value
metaclass, but I'd rather make sure that my analysis is correct first.Best regards,
Alex
The text was updated successfully, but these errors were encountered: