-
-
Notifications
You must be signed in to change notification settings - Fork 164
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
Program fails to build if windows.h is included after toml++. #99
Comments
Ah, good catch! I think your solution is a good one; them being in a namespace isn't overly critical. |
Fixed in |
@marzer I don't understand how what you did here fixes the problem? For me the build for my project now fails with error C2375 while it worked flawlessly before this change:
Your definition for those functions is also incorrect as it omits both SAL annotations and I would appreciate if you do not copy function definitions from platform header files, but instead include appropriate platform header file if needed, and rely on their existing guards to avoid function redefinitions. If you are concerned about namespace pollution, there are a lot of macros that can be defined prior to including
However, I wouldn't advise doing that unless there is an actual conflict (such as with To be perfectly clear, I do agree that the order of include directives shouldn't break anything and that the reported issue should be fixed -- I just disagree with this particular "fix". |
It doesn't fix your problem. It fixes the problem identified in the issue as reported by @ImTouchk. The thing you're experiencing is a different (but related) issue.
Not including SAL annotations has no impact on it's correctness as far as C++ is concerned. They're preprocessor-only hints for tooling (and for the poor humans forced to read them). You're right that it should have
I'd rather not, if I can avoid it. If the library must always be paired with
Those are useless for a library; if I use them then either my library is the first one to include |
If I am not mistaken SAL annotations are there to enable compiler to verify correctness of the code calling the function at compile time? If you are sure your code doesn't need them that's good for you. However, introducing SAL-less definitions that replace
I disagree with what you think the actual problem is -- actual problem is not including
Is that with or without using precompiled headers? Regardless, most projects on Windows platform will have to include If you are really not comfortable with including
On the contrarry, given that it is a stable API it belongs in the project's
I agree, that's why I said I wouldn't recommend that approach. |
No it won't. Regular attributes, annotations etc are cumulative. A forward declaration can omit them, and have them added later by a full definition or separate forward declaration. In my experience this applies to SAL annotations, too. My code uses those two functions correctly so I don't benefit from the annotations, but me doing this won't impact SAL for anyone who is including Windows.h for their own use since the SAL annotations will still be applied correctly.
Because that would impose an ordering requirement on
Good for you, but it's my library so it's up to me to decide the nature of the issue. I've already outlined my reasoning here and simply do not agree with you about the rest of it. I'll fix the issue by adding the missing API declaration. I'll add an escape-hatch option via a |
@levicki your issue should now be fixed in ba75446. Additionally you can use the (undocumented) switch |
You complain that people don't read documentation, and then you cater to those same people by removing the need to read via hacky workarounds such as this one. I find that really disappointing because it is teaching them the wrong thing. The proper solution for Windows platform is That would teach them to use the platform toolset properly, while this is teaching them that it's OK to copy & paste stuff from random header files (as if copying random bits of code from Stack Overflow wasn't bad enough). In this particular case it might be benign because API is (mostly) stable, but people extrapolate weirdest things and next thing you know they will copy declarations from STL or Boost or God knows what other 3rd party library where API isn't that stable and when someone else on a team later updates said library all hell will break loose. Your fix is not technically wrong, but IMO it is setting a bad example.
Now I feel bad for putting you on a defensive. I apologize for even bringing this up, obviously I was mistaken in my belief that you value my input so I will refrain from reporting any further issues from now on. |
@levicki I value input, but your way of communicating it has come to be oddly entitled somehow, as though you're my customer and I owe you something, and it is very demotivating. Your initial communications with me were great but more recently it feels like you've come to act as though you have some ownership of this project, and be more pushy/insistent accordingly. If you can drop that nonsense I'll be more engaged, otherwise please do move on. |
@marzer I apologize if I am coming through like that, I can be rather passionate when discussing the future of something I use and like (and I do like your library a lot so let me use this opportunity to thank you again for writing it and allowing us to use it). However, even if I contributed code instead of just ideas (and opinions like in this case), I would have never considered myself as having any special rights to your work, not even customer relationship, much less ownership. If that's what you are getting from my feedback then either I am not communicating clearly enough, or there must be some sort of language barrier given how English is not my primary language, or perhaps it is just difference in our temperaments. |
Environment
toml++ version and/or commit hash: dca6945
Compiler: MSVC 19.28.29915
C++ standard mode (e.g. 17, 20, 'latest'): latest/20
Target arch (e.g. x64): x64
Library configuration overrides: -
Relevant compilation flags: -
Describe the bug
Including
windows.h
aftertoml++/toml.h
(but not the other way around) causes the build to fail:Error C2733: MultiByteToWideChar/WideCharToMultiByte: you cannot overload a function with extern "C" linkage.
Steps to reproduce (or a small repro code sample)
Library is added as a cmake subproject and built at the same time.
Additional information
The issue happens in this header:
toml_default_formatter.hpp
, at line205
. I managed to get around this error by placing the declarations in the root namespace and guard them with a macro:Though I'm not sure how it'd be fixed without removing the winapi namespace.
The text was updated successfully, but these errors were encountered: