Allow tomlplusplus to be built by C++20 modules#266
Allow tomlplusplus to be built by C++20 modules#266marzer merged 11 commits intomarzer:masterfrom mikomikotaishi:master
Conversation
|
Alternatively the module that it exports could be named just "tomlpp" instead of "tomlplusplus", for convenience |
|
Hello! That was 3 years ago; I don't remember why I closed it. If anything, modules were in a much worse state back then, so it's really not a good reference point. Feel free to treat that old issue report as if it didn't exist. :) |
|
Hi, are there still any changes you are looking for before you accept and merge my pull request? |
Two things:
After that I'm happy to see this merged 👍🏼 |
OK, changes have been made as requested |
|
@mikomikotaishi Thanks very much for addressing my questions regarding the CMake variable #if TOML_TEST_MODULE
import toml;
#else
#include <toml++/toml.hpp>
#endif
The tests could then be built either with |
To be honest, I haven't written any example tests bundled with this project but I do have a basically identical copy (only difference is I aliased all type names to PascalCase) of all the files in this pull request in one of my own projects, which compiles and uses tomlplusplus fine. Here is my project that uses tomlplusplus, it compiles fine and the code works. As for bundling some tests with this project, I admit I'm honestly not that great with CMake, I only know enough to get my own projects and this library to compile, but not how to link example test cases to locate libraries correctly for whatever reason. I can try bundling your suggestions with the macros though |
|
Thanks @mikomikotaishi Honestly I do have quite some CMake experience, but I haven't yet tried out C++ modules, I have to admit. I'm still stuck at C++17 🤷 When your pull request is merged, would you use it yourself, for your project, replacing your original "openJuice/tomlpp/tomlpp.cppm" file? |
| inline namespace literals { | ||
| using toml::literals::operator""_toml; | ||
| using toml::literals::operator""_tpath; | ||
| } |
There was a problem hiding this comment.
Do you use Visual C++? I just tried it out, using the latest update of Visual Studio 2022 (version 17.13.5). Unfortunately if fails to export the operators from toml::literals, saying:
>S:\tomlplusplus\src\modules\tomlpp.cppm(22,21): error C2872: 'literals': ambiguous symbol
> S:\tomlplusplus\src\modules\tomlpp.cppm(21,22):
> could be 'toml::literals'
> S:\tomlplusplus\include\toml++\impl\parser.hpp(322,19):
> or 'toml::v3::literals'
>S:\tomlplusplus\src\modules\tomlpp.cppm(22,31): error C2039: '""_toml': is not a member of 'toml::literals'
> S:\tomlplusplus\src\modules\tomlpp.cppm(21,22):
> see declaration of 'toml::literals'
>S:\tomlplusplus\src\modules\tomlpp.cppm(22,9): error C2873: '""_toml': symbol cannot be used in a using-declaration
>S:\tomlplusplus\src\modules\tomlpp.cppm(23,21): error C2872: 'literals': ambiguous symbol
> S:\tomlplusplus\src\modules\tomlpp.cppm(21,22):
> could be 'toml::literals'
> S:\tomlplusplus\include\toml++\impl\parser.hpp(322,19):
> or 'toml::v3::literals'
>S:\tomlplusplus\src\modules\tomlpp.cppm(23,31): error C2039: '""_tpath': is not a member of 'toml::literals'
> S:\tomlplusplus\src\modules\tomlpp.cppm(21,22):
> see declaration of 'toml::literals'
>S:\tomlplusplus\src\modules\tomlpp.cppm(23,9): error C2873: '""_tpath': symbol cannot be used in a using-declaration
Do you have a clue how to fix this?
There was a problem hiding this comment.
That's very strange. I use Clang and no such error occurs on my end. I can look at it a bit more closely in a bit
For now try commenting those out and trying again? I always thought MSVC was the most well-equipped for modules funnily enough
There was a problem hiding this comment.
I don't know whether the "ambiguous symbol" errors are caused by a compiler bug. But it appears that these MSVC errors go away when explicitly using the operators from toml::v3::literals. As follows:
inline namespace literals {
using toml::v3::literals::operator""_toml;
using toml::v3::literals::operator""_tpath;
}Hope that helps!
There was a problem hiding this comment.
It may be an inline namespace thing I think, I'll try changing that to use the v3 scope and see if it works on Clang as well
|
I just tried your module in simple_parser.cpp. Did a CMake build, having Unfortunately the compiler says: Not sure if it's an MSVC bug, I'm using the latest VS2022 update (version 17.13.5). Any clue? PS @mikomikotaishi Could you please check if simple_parser does compile (and run) with Clang, when you let it do |
That file tomlpp.cppm exports all the symbols in PascalCase, which is the convention I am using in that project, so if I were to use it I would have to make a few adjustments to re-exporting them in my own project the way I aliased them there. At the moment I would probably just replace the #include with an import there, because modules can't be re-aliased/renamed |
Sure I'll test it and let you know, might take a bit of CMake trickery but given my past experience with it it does seem to work |
|
@N-Dekker It seems to work on Clang for me, maybe it's a weird compiler issue |
|
@marzer Any update on this, is it ready to be merged? |
|
Nope, looks all good, thanks 😄 |
|
Sorry for that, but I have a silly question
Is it somehow possible to import the module w/o adding .cppm file into the project? |
|
Hi, I am a little confused what you mean. The module is declared in that file, so naturally it must be part of the project to be imported. Could you clarify what it is you would like? |
What does this change do?
This allows tomlplusplus to optionally be built with C++20 modules.
Is it related to an exisiting bug report or feature request?
No, but this may potentially be a suggested feature by users of C++20 and later. (Mentioned by #172, though that is for a header unit rather than a module.)
Pre-merge checklist
origin/master(if necessary)