Reputation: 35438
Ok, I know this sounds like a broken question, but let me explain before the downvotes start: we are using C++11 as a baseline for our development (targeting several platforms). Recently a few changes needed to be done in our codebase and suddenly the need for some C++17 features crawled in.
All is fine till now, on our developer platform all compiles nicely, but on one of the continuous integration platforms (Ubuntu 18.04) we have got some errors, like:
/usr/include/ev++.h:355:46: error: ISO C++1z does not allow dynamic exception specifications dynamic_loop (unsigned int flags = AUTO) throw (bad_loop)
(c++1z dynamic exception specification error gives a good explanation why this happens and also offers some hacks on how to make it disappear)
But I started thinking (theoretically only, of course) that would it be possible that we specify some portions of a source file to be compiled with code conforming to C++11 and other parts with code conforming to C++17?
(And just to clarify: No, we don't want to upgrade, and yes, we have solved the problem, again, I am just interested in a theoretical approach)
Upvotes: 1
Views: 991
Reputation: 10315
In theory-theory it would be possible. Compiling different parts of file with different standards is effectivelly splitting the file and using different backend for every of these parts. It should not be that hard. But there is one big caveat - ABI compatibility. When you realize that linking object files compiled with different standards is often not possible, you see this whole idea is a landmine. The compiler would have to either keep the ABI stable (which would be nice but with the amount of changes made with every standard, keeping the ABI compatible between them would be a nightmare) or somehow translate the ABIs of different standards (this would also be nightmarish I suppose). Even now the most popular way to keep the ABI problems 'in check' is using extern "C"
to avoid all fuss.
So the answer is - it would be possible in theory but the practical implications of such choice would be so dramatic that it is not worth it.
Upvotes: 1