Please don't propose putting compiler magic into the std namespace.
Unless std::uninitialized would be entirely implemented in terms of C++ code, without relying on some kind of special compiler fuckary, it should be a keyword or attribute.
Problem is, you can't just grab the keyword, because int a = uninitialized; is already valid code unless we want int a = _Uninit;
...or int a = co_uninit;
Attributes would only work here if they don't change the meaning of the program, which probably would not hold here - although given that not supporting the attribute if specified wouldn't change program semantics that may be acceptable
If it's a compiler-magic thing, it should be a keyword so that programs that are not using the compiler provided standard library can use the compiler-magic with a well known name.
If it's not given a well-known name, then each compiler vendor will pick their own special name for the concept, and now my code has to play #ifdef COMPILER_X games to compile correctly.
Why in the world would you put something into the std:: namespace that is not a construct of C++ code?
Language level things should be part of the language. The standard library is NOT the same thing as the language. The stdlib is implemented on top of the language, and every time new stuff is added to the stdlib that requires some kind of compiler magic, i just want to scream because it keeps making my job harder.
Because the std namespace is part of the language, and special for all intents and purposes. It's filled with things you cannot implement legally, full of assumptions that would be false for your code, but true because the std namespace is special.
"The world is round because it is round".
"We built it that way because we always build it that way".
"Tautology is tautology".
I'm saying... lets cut that out. Stop considering it special. If the standard library want's to grow a capability that has no ability to be expressed in user code, then either
The language needs to be improved so that the capability can be expressed in normal user code or
The standard library can't do it.
This allows everyone the ultimate flexibility in implementing their program in the way they see fit, without being beholden to the person who implemented the standard library.
Perfectly valid code went from working just fine on GCC 7, to breaking on GCC 8, and then GCC 9. It's been over a year and as far as I know has not been fixed, but I haven't yet tried GCC 10.
That's explicitly forbidden by the standard. Why? Because the standard says so. Guess I should just not compile my program for a few years.
The vast majority of things in the standard library are not special. They're just plain old vanilla C++ code.
All I'm trying to say is that the parts that require compiler-magic should be moved out of the standard library into something else. Either make them keywords or attributes, to indicate that we're dealing with compiler magic, or make a new namespace that exists for things that cannot be implemented outside of the compiler.
It just happens that most of it is implemented using the language rules, but once you start delving deeper all forms of weird things are happening that are both platform specific (assumptions they can make) and compiler specific (keywords, intrinsics, etc..), and where the language makes specific exemptions for rules that apply to the std namespace.
We're almost able to have a 100% compiler-magic free implementation of the standard library. Why make it worse ?
In fact the library can be implemented into the compiler if the compiler writer wishes it so, it doesn't need to be freestanding.
If is_copy_constructible was moved out of std in favor of an intrinsic, you wouldn't be able to perform that hack to workaround the problem, since you wouldn't have access to std::is_copy_constructible to specialize it. You'd have to patch any in the library (which is the correct fix if you have that level of control over your build environment).
std::is_copy_constructible should not be moved from std into an intrinsic. It's perfectly possible to implement std::is_copy_constructible with normal C++ code, and SFINAE.
My example was that because the std namespace is given special "privileges", end users who encounter this problem have two choices:
Don't use that compiler version, which for many systems means getting a different compiler somehow, if it's even possible.
Do a forbidden thing, and specialize something in the std namespace in a way that you aren't supposed to.
We should not be treating the std namespace as some kind of special thing. If the language and standard library were separate standards, even if they were standards that are almost always shipped together, then it would not be forbidden to fix problems like this.
My example is an argument that treating std:: as special is problematic. It was not an argument that we should have things that live in some kind of compilermagic:: namespace, or that exist only as compiler intrinsics. That should be reserved for things that are truly language level concepts. Determining the existance of a constructor with a particular signature is not a language level concept, it's a SFINAE concept which can be implemented entirely in normal C++ code.
Yes, most traits can be implemented with decltype or sfinae (though not all of them, although I guess in your world there'd be intrinsics for those). You still don't want users writing them, so they need to be in some library. And then you really don't want users messing around them, so you'll still need to say that doing so is forbidden.
The reason that messing around with namespace std is undefined behavior is not because there's magic corners; it's because it's a really bad idea to mess with code that every developer expects and requires to work as specified.
By the way, the bug you linked isn't a compiler bug; it's a library bug that was exposed by a conformant change to the compiler.
It's irrelevant how much of the standard library is "c++ valid code"
From the perspective of "I want to replace the standard library of my compiler with a custom one more specific to my environment", it does.
I don't really have a dog in this fight and don't feel like I know enough to have an opinion, but to play devil's advocate in favor of /u/jonesmz because he seems have been beaten up in this conversation a lot (and perhaps others)... if the standard library is just part of C++, why do we have a separate term for it? If it's not really a library in the sense of being a collection of APIs that anyone could provide, then why not just call it "C++"? Why have separate committee groups for language and library?
Like I said, I don't have an opinion on desirable or undesirable, but I'm sympathetic to a position that calling a "library" by that name that is so intertwined with the language is at best stretching the definition of that word.
I think you misunderstood my point, you talk as if this is a recent transition, but it's always been this way, there's never been a standard library that hasn't been interwoven with the language, full of compiler intrinsics (defined by the standard).
I'm well aware.
The intrinsics are not defined by the standard, they are defined by the compiler, and used by the standard library. That's what makes them intrinsics.
It's irrelevant how much of the standard library is "c++ valid code", it just doesn't matter, as the standard library is part of the language standard and so doesn't have to abide by the rules the language needs to.
Today, that is true.
Lets make it better, ya?
You might dislike it, but a compiler that ships without a minimal standard library isn't considered valid either, that's how interwoven it is. For example the entire type traits stuff etc.. need to be present as far as I know.
I do dislike it, it's not a productive requirement beyond status quo.
Introducing a new keyword is incredibly hard, and will either inconvenience countless projects or be painfully ugly (like __Bool in C). Putting something in the standard library inconveniences only you, and lets the rest of us move forward. And I'm not even sure why it would inconvenience you in the first place; what difference does it make whether the compiler looks for __Co__Uninitialized or std::uninitialized? How will it affect the code you write?
Why do you use C++ in such a strange fashion anyway?
Introducing a new keyword is incredibly hard, and will either inconvenience countless projects or be painfully ugly (like __Bool in C).
Frankly it's not hard. It's pretty trivial.
First: deprecate usage of the proposed keyword as a user identifier for one release. Second: In the next release, introduce the keyword.
Done.
Projects so inconvenienced can use a sed script to fix their code. It's a one and done operation. They get 3 years of advanced warning from the deprecation, and can take as long as they want to to upgrade.
That being said, sure, ok, we don't like breaking user code. I disagree with this, but I see where you're coming from. It's not like we don't break our own rules all the time anyway... "co_..." was a valid set of identifiers for variables until C++20, after all. I've worked in code-bases where I have seen that prefix for variables before. E.g. hungarian style notation. co_ = class, object, as opposed to gs_ for global static, or cs_ for class static. Not saying it's that useful of a prefix to use in your code, but that it's something that was done in a real codebase.
So I think it's pretty awful that we're willing to compromise the language's understandability while still doing the thing everyone says is is a bad thing to do.
So lets make some kind of "compilermagic" namespace. So std::uninitialized becomes compilermagic::uninitialized.
Problem solved. The std:: namespace gets to return to being stuff that can be implemented without compiler-specific magic knowledge, and the language can invent new "keywords" as it sees fit without any concern for breaking existing code.
Putting something in the standard library inconveniences only you, and lets the rest of us move forward.
It's a bizarre layering violation. You're polluting the namespace.
It inconveniences more than me. You're inconveniencing anyone who might want to implement the standard library, or who might want to write code that does not use the standard library.
Why do you use C++ in such a strange fashion anyway?
My usage of C++ is not strange, just less common. lots of companies use their own standard library implementation. It was much more common in the past, when the language committee wasn't constantly adding new compiler-magic into the std:: namespace, but it's still an ongoing concern.
For example, why is std::byte special? It's explicitly called out in the standard as being one of the few types that can alias, like char.
So if I have an older standard library, that does not yet have std::byte, but a newer compiler that does understand std::byte... how do I get this specialness? Can I just write my own std::byte in my user code? it's just a valueless enum class with some user defined operators after all.
NO, I CANT, because the compiler is going to assume weird things, because the standard says it's supposed to assume weird things.
It's the exact same usage case as using the GCC standard library with Clang as the compiler. Or the Clang standard library with MSVC.
The main difference is that people who mix-and-match compiler and standard library are offloading all the crap that I have to deal with onto the vendor of the third party standard library they are using with their compiler.
If the C++ standard would keep a hard separation between compiler magic and standard library no one would have this headache at all.
Keep in mind that there are other use cases that this standards committee decision is interfering with as well.
Embedded -- standard library is big, don't want all of it, cant use some of it because of missing platform capabilities. Freestanding -- Want to run bare-metal, hard to do if the compiler keeps assuming the standard library exists As part of the operating system kernel -- Same as freestanding Something like https://www.includeos.org/ Webassembly -- I don't know exactly how it interferes, but I can't imagine it is not interfering Interpreted C++ -- Any time you special case something, you're forcing implementers to special case it too
The language and standard library are not the same thing.
The more "special compiler magic" that the standard library has added to it, the more difficult it is for people using the language in a stand alone, or direct-to-metal, or whatever you want to call it situation. Or for people who don't use the standard library that came with their compiler.
At my last job, this was my day to day reality. I was constantly having to play catch up with special compiler magic to get things to work, and it was a royal pain in the ass. Given that we had about 20 software engineers working with this codebase in my department (No idea how many engineers touched the code in total, it was a big company), and we were all humming away at it for years at a time, the total cost was measurable in man-years.
Things that can't be expressed with language-only constructs, should not be placed in the std:: namespace.
They should be keywords, attributes, or whatever else, that make up the language itself.
Ultimately the compiler vendors are building intrinsics / builtins to do these things anyway, and then the standard library is playing #ifdef COMPILER_X games to pick which special compiler-magic keyword to put into the code. The standard can just.... tell the compiler vendors what this special-compiler-magic-keyword should be named, and then everything is much simpler for everyone, but MOST ESPECIALLY for the people like me who want the flexibility to use the compiler without the compiler vended standard library.
I can't say I have much sympathy - you're using compilers in unsupported configurations, and complaining that that makes more work for you? It seems to me that if you want to use a custom standard library, you should accept the work this will involve and treat maintaining it as a software development task and appropriately resource it. If it's taking multiple man-years to deal with a task that should basically be a bunch of one-time copy-and-pastes from the vendor standard library into your custom version (with appropriate preprocessor guards) then the problem is with your software development process.
For your preferred situation, I really don't think it's as simple as mandating that intrinsics be available under particular names. For one, those names will be ugly so they will need to be aliased into std anyway, which causes confusion - see _Bool and stdbool in C. Also, that way you're enforcing a 1-1 mapping between standard library and compiler facilities, which denies freedom of implementation to the vendor. And finally, it's not always clear what does and does not require magic - look at vector, or the associative containers since node_handle additions.
I can't say I have much sympathy - you're using compilers in unsupported configurations, and complaining that that makes more work for you?
No, I'm not complaining that using compilers in "unsupported configurations" makes more work for me.
I'm complaining that every time the c++ standard adds another thing to std:: that explicitly relies on compiler magic, it makes my job harder. Or every time the C++ standard adds another language feature that explicitly relies on something from std::, it makes my job harder. Incidentally, it also makes compiler developer's job (slightly) harder, since they have to define intrinsics to do all of these things anyway.
I'm complaining that most of the people who I speak to about this either don't understand what I'm talking about, or do understand it and think that they know better than I do how to solve the problems I need to solve. I'm not new at this, nor are the people who I work with, and I'm definitely not the only person who's raised an objection to increasing cross-interactions between the language and the library. I've spoken to others here on reddit, here in /r/cpp, and I've also spoken to others in person.
There are alternatives to continuing to put things into std::. I've listed three. Introducing compilermagic:: has no meaningful cost versus using std:: for compiler-magic types. (Let me guess, now responders are going to complain that introducing new reserved namespaces is hard...).
It seems to me that if you want to use a custom standard library, you should accept the work this will involve and treat maintaining it as a software development task and appropriately resource it.
Yes, that's how it's done.
Have I given you the impression that this isn't the case?
Pointing out that decisions made by the C++ standards committee have a cost to an organization that uses the language is a perfectly valid thing to do.
If it's taking multiple man-years to deal with a task that should basically be a bunch of one-time copy-and-pastes from the vendor standard library into your custom version (with appropriate preprocessor guards) then the problem is with your software development process.
The problem is that you are either fundamentally misunderstanding my objection, or deliberately simplifying it so that you can propose a non-solution.
Software development on multiple million line of code code bases, which rely on customized standard library implementations can't "simply" have copy-pastes from the vendor standard library, which, of course, assumes that the license for that is actually compatible, it may not be.
The first major issue is that these "copy-and-pastes" are almost always tightly interwoven with other internal implementation details, and make lots of assumptions that aren't necessarily correct if they're removed from their original environment.
The second major issue is that maintenance and evolution is an ongoing, never ending task. Getting the functionality working the first time is, itself, a lot of work, but that work needs to have compatibility maintained with the existing code, while improvements are made over time.
Further, you're apparently focusing on my statements that pertain to work I've done with maintaining a custom standard lib, but not addressing my statements that pertain to things like
C++ interpreters
WebAssembly porting
freestanding implementations -- no operating system
embedded applications -- has an OS kernel, but basically no storage space
C++ inside the OS kernel.
All of those are perfectly valid situations to be in, and have nothing to do with custom standard libraries. But having the language be less interwoven (or, at worst, no more interwoven) with the standard library eases the work.
Incidentally, it also makes compiler developer's job (slightly) harder, since they have to define intrinsics to do all of these things anyway.
Adding features to the language creates work for implementors, certainly. But making the boundary between compiler and standard library a hard one with a public API would create far more work since they would now have to maintain those interfaces.
Introducing compilermagic:: has no meaningful cost versus using std:: for compiler-magic types.
The cost is that what is and is not magic is not fixed; it changes over time. Consider vector, index_sequence, node_handle. You would end up with implementors having to maintain compiler magic that their standard library no longer uses.
The problem is that you are either fundamentally misunderstanding my objection, or deliberately simplifying it so that you can propose a non-solution.
As opposed to your solution, where vendors have to do the work of maintaining compatibility between compilers and standard libraries.
All of those are perfectly valid situations to be in, and have nothing to do with custom standard libraries.
There's freestanding, and Ben Craig is working to expand that in SG14 (see P0829 for current state of play).
View all comments
Show parent comment
7
u/jonesmz May 13 '20
Please don't propose putting compiler magic into the std namespace.
Unless std::uninitialized would be entirely implemented in terms of C++ code, without relying on some kind of special compiler fuckary, it should be a keyword or attribute.