-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[C++] Expose nullptr_t from stddef.h in C++ mode #154599
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
libc++ provides
nullptr_tin all language modes. It would be really nice if we could remove ourstddef.hheader, but I'm not sure how the Clang headers would detect whether to provide it or not in C++03.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know that it's possible to not vend
stddef.h; do we know that every libc actually provides a complete header that works with Clang?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or is your suggestion that we move
stddef.hto something more like:Either way, I think it's orthogonal to this fix because that's a pretty substantial change that requires a fair amount of investigation. Are you okay with landing the changes as-is and doing that exploration in a follow-up if someone gets the chance? (I'm going to be out of office for a while, so I'm not able to commit to that work myself.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I meant libc++'s
stddef.hwith "ourstddef.h". We currently have a wrapping header to providenullptr_tcorrectly: https://godbolt.org/z/W41dKKbd4.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah! I see what you mean, thanks!
So you're okay with the current changes as-is because it heads in the right direction for libc++?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1, but it might be a challenge too. I'm not certain libc++ should provide
nullptr_tin C++03 mode; that's taking an identifier from the user in that language mode andnullptrdoesn't work in C++03 anyway: https://godbolt.org/z/96vMdbobeThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We claim to be a C++11 implementation, not a C++03 implementation. Just one that mostly works with
-std=c++03. Whether that was the right thing to do is debatable, but it's where we are today.Well, it does with libc++.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's not how I understood the RFC, unless I missed something. I understood it as libc++ is a C++03 and later implementation but that we're not making fixes to C++03 unless there's some major security vulnerability or other extenuating circumstance.
It's a non-conforming extension.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has nothing to do with the RFC. libc++ has always provided a lot of "extensions" in C++03. From the very beginning we've had C++11 features implemented in C++03. I actually think it probably was a huge mistake, but we can't change it 15 years later. This is one of the main reasons we want to split the headers, so we can leave the cruft behind and not have massive workarounds for all the stuff we provide in 03.
If you look at it as a C++03 implementation. If you look at it as a C++11 implementation that works with C++03 compiler it's not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I'm viewing it from the perspective of a user of Clang. This is non-conforming and has surprising behavior as a result: https://godbolt.org/z/9qPYPndKb
But, it sounds like this is moot because:
is definitely true. :-)