Skip to content
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

[conv.lval] Add example of erroneous 'trap representation' being read #7049

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Eisenwave
Copy link
Contributor

@Eisenwave Eisenwave commented Jun 5, 2024

Fixes #7047.

image

@Eisenwave Eisenwave force-pushed the erroneous-conv-lval-example branch 2 times, most recently from ab27d48 to bb7bf60 Compare June 5, 2024 11:56
@Eisenwave Eisenwave force-pushed the erroneous-conv-lval-example branch from bb7bf60 to b1822f7 Compare June 5, 2024 11:57
@Eisenwave
Copy link
Contributor Author

Now presumably based on CWG2899.

If CWG2899 is accepted, this example would need to be shifted up by one bullet, and it may make sense to extend the example to show how this happens without erroneous values, like in the issue.

@jensmaurer
Copy link
Member

I take this as a request to add an example to CWG2899. Done.

@Eisenwave
Copy link
Contributor Author

Eisenwave commented Jun 10, 2024

@jensmaurer thanks, it makes sense to add it as an example there.

However, the reason why I've originally suggested the example was that it isn't obvious how erroneous values can trigger this form of UB, so ideally, CWG2899 should show both scenarios (erroneous and non-erroneous cause):

bool f() {
+  bool e;            // e has erroneous value (6.7.4 [[basic.indet]](https://wg21.link/basic.indet))
+  bool u = e;        // undefined behavior if the value of e is not a valid value representation for bool
+
  bool b = true;
  char c = 42;
  memcpy(&b, &c, 1);  // implicitly creates objects at b (23.5.3 [[cstring.syn](https://wg21.link/cstring.syn)], 6.7.2 [[intro.object](https://wg21.link/intro.object)])
  return b;           // undefined behavior if 42 is not a valid value representation for bool
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[conv.lval] Add example of indeterminate values that are not valid for the type CWG2899
2 participants