r/cpp • MSVC Game Dev PM • Sep 14 '20

Standard C++20 Modules support with MSVC in Visual Studio 2019 version 16.8 | C++ Team Blog

https://devblogs.microsoft.com/cppblog/standard-c20-modules-support-with-msvc-in-visual-studio-2019-version-16-8/
254 Upvotes

128 comments sorted by

View all comments

Show parent comments

5

u/GabrielDosReis Sep 14 '20

If you want to keep the headers, what prevents you from writing export import <header>; and use extern "C++" for the part you're unsure about, while you're gradually benefiting from the increased safety offered by the strong ownership? You get gradual migration and gradual benefits.

1

u/germandiago Sep 14 '20

Nice trick I guess. This would solve the problem even if uglifying a bit things.

5

u/GabrielDosReis Sep 14 '20

Actually, it makes it plain to spot "the ice is thin here" -- a reminder to look for when root causing a clash, especially in large codebase.

1

u/germandiago Sep 15 '20

Actually I am thinking if extern "C++" can be used on classes themselves. In functions you can but I could not find anywhere documentation for classes. What if you have a class that is part of your interface? You need to wrap it in functions in some way?

2

u/GabrielDosReis Sep 15 '20

You can use C++ language linkage specification on any declaration, including class declarations/definitions.

0

u/Minimonium Sep 14 '20

It's not about keeping the headers but allowing huge codebases to move gradually or not touch legally protected parts of the codebase that require a process to change. It's a very classical argument of proponents of the weak ownership model.

The time for debates of weak vs strong ownership models is long gone, the committee settled on the implementation-defined model - which means that you can never benefit from either of them in multi-platform projects.

10

u/GabrielDosReis Sep 14 '20

You might be right that the time for he argument may be long gone (maybe except on reddit :-)), but now is the time of actual practice and MSVC makes it possible for you to test hypothesis, and not just surrender to hypotheticals.

5

u/mwasplund soup Sep 14 '20

Am I reading this correctly, it was decided to let the implementation decide if they want to use strong or weak ownership! This is way worse than deciding to go with weak or strong! At least if they would have completely fallen back to weak ownership I could trust that my code would compile the same for all the compilers, even if they didn't solve ODR issues.

3

u/GabrielDosReis Sep 15 '20

Yes, that was the result of compromise. However, in addition to trying to reverse engineer an opaque standardese, look also at the note indicating intent and future direction the reference of which I provided. Granted, a note is non-normative but that is the whole point of a note: offer clarifications when the normative wording might look opaque or non-obvious.

Another way to look at this is QoI: quality of implementation, because the committee couldn't come to a definitive answer at one point in time.

3

u/mwasplund soup Sep 15 '20

Yes, I understand, and agree with MSVCs decision to default to strong ownership (it actually sounds amazing for the build system I am working on). However, when an implementation is more permissive than is allowed by other implementations (in this case both are valid) I have to design for the worst/strict case. Unless all compilers support strong ownership with at least a flag to enable it, I now have to synthetically emulate weak ownership or just hope that when working in MSVC a developer doesn't introduce a break in CompilerZ (which implemented weak ownership).

6

u/GabrielDosReis Sep 15 '20

I understand where you're coming from, and I empathize with the need for a "defensive programming" when not all toolsets offer the same level of QoI. However, I wouldn't characterize the issue as one implementation being more permissive than another one -- I can also see why the choice of the words "weak" vs. "strong" may imply some form of hierarchy (you can put that one on me).

I am more optimistic than some have suggested in this thread regarding where C++ toolsets would be in the long term, with respect to this point. I expect that as more and more codebase migrate to Modules at scale, strong ownership will no longer be a subject of discussion ("should we support it?") but how it is enabled. Today is one point in time for C++ development; the future looks much more promising.

(and in fact as a bonus, you can already instruct the MSVC linker to be verbose and to tell you when there is a possible clash in symbols, in general).