SergiusTheBest / plog

Portable, simple and extensible C++ logging library
MIT License
2.21k stars 391 forks source link

Question about C++20 standard compatibility ? #236

Closed niva-xx closed 1 year ago

niva-xx commented 1 year ago

Hi All,

Following an attempt to build all the examples with VS2022 v143 vc17 using the C++20 standard, line 194 of Record.h appears an error C2280: attempt to reference a function deleted at the first "PLOG <<" used in the Demo/main.cpp client code on line 37.

Noting among all the examples that only CXX11 and CXX17 are present, just this question, is PLOG compatible with client code that meets C++20 standards?

Line 194 of Record.h:                 enum { value = sizeof(operator<<(meta::declval(), meta::declval<const T>())) != sizeof(No) };

An attempt with /permissive results to same issue C2280.

Thank you Nicolas

SergiusTheBest commented 1 year ago

Hi @niva-xx ,

Yes, it should be compatible. I'll take a closer look at the issue.

SergiusTheBest commented 1 year ago

@niva-xx I pushed the fix into develop branch. Please, try it. It turned out that MSVC in C++20 made operator<<(std::ostream&, const wchar_t*) = delete and it didn't play well with metaprogramming.

niva-xx commented 1 year ago

@niva-xx I pushed the fix into develop branch. Please, try it. It turned out that MSVC in C++20 made operator<<(std::ostream&, const wchar_t*) = delete and it didn't play well with metaprogramming.

Thank you for the quick answer.

It works now using VS2022 v143 vc17 C++20 standard for all projects (including Demo ) except DemoManaged.

Error reported is E2020 the managed nullptr cannot be used here. Refering '_Literal_zero' in lines 44, 50, 54 of' compare' include MSVC/14.30.30705 when compiling MyClass.cpp of DemoManaged.

C++/CLI does not support versions newer than C++17. It is described here https://cplusplus.com/forum/windows/281465.

niva-xx commented 1 year ago

Thank you for resolving this issue so quickly. I wish you the best for this year. Courage.

SergiusTheBest commented 1 year ago

@niva-xx Thank you!

jsm174 commented 1 year ago

@SergiusTheBest, hello I believe I am having this same issue using on macos compiling with GCC 12.2.0:

[build] In file included from /Users/jmillard/vpinball/plog/Appenders/IAppender.h:2,
[build]                  from /Users/jmillard/vpinball/plog/Logger.h:2,
[build]                  from /Users/jmillard/vpinball/plog/Log.h:7,
[build]                  from /Users/jmillard/vpinball/main_standalone.h:696:
[build] /Users/jmillard/vpinball/plog/Record.h: In instantiation of 'plog::Record& plog::Record::operator<<(const T&) [with T = wchar_t*]':
[build] /Users/jmillard/vpinball/codeview.cpp:1181:96:   required from here
[build] /Users/jmillard/vpinball/plog/Record.h:308:23: error: use of deleted function 'std::basic_ostream<char, _Traits>& std::operator<<(basic_ostream<char, _Traits>&, const wchar_t*) [with _Traits = char_traits<char>]'
[build]   308 |             m_message << data;
[build]       |             ~~~~~~~~~~^~~~~~~
[build] In file included from /opt/homebrew/Cellar/gcc/12.2.0/include/c++/12/istream:39,
[build]                  from /opt/homebrew/Cellar/gcc/12.2.0/include/c++/12/sstream:38,
[build]                  from /Users/jmillard/vpinball/plog/Util.h:6,
[build]                  from /Users/jmillard/vpinball/plog/Record.h:4:
[build] /opt/homebrew/Cellar/gcc/12.2.0/include/c++/12/ostream:642:5: note: declared here
[build]   642 |     operator<<(basic_ostream<char, _Traits>&, const wchar_t*) = delete;
[build]       |     ^~~~~~~~

If I switch my cmake I don't get this error.

set(CMAKE_CXX_STANDARD 17)

SergiusTheBest commented 1 year ago

@jsm174 Hey! Do you use the latest master?

jsm174 commented 1 year ago

Yes, I grabbed the latest after reading this issue.

Just tried again just to make sure something wasn't cached. Same.

When I do a git diff the only diff from the older plog is Record.h

git status
On branch standalone
Your branch is up to date with 'origin/standalone'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
    modified:   plog/Record.h

FWIW, I do not get this error with C++ 20 and Clang 13 or Clang 14, only GCC.

SergiusTheBest commented 1 year ago

@jsm174 That's weird. I've checked on GCC 12.1.0 and it worked fine. I'll check on GCC 12.2.0 later. Thanks for reporting!

SergiusTheBest commented 1 year ago

@jsm174 Could you post what code is located at /Users/jmillard/vpinball/main_standalone.h:696? I checked building with GCC 12.2.0 and had no issues.

jsm174 commented 1 year ago

Thanks for looking into this:

https://github.com/vpinball/vpinball/blob/313872b7e31b1f1b6a457de1792aa7e62f69d778/main_standalone.h#L696

SergiusTheBest commented 1 year ago

@jsm174 I figured out the issue! Your code misses defining PLOG_ENABLE_WCHAR_INPUT, so plog disables all its own wchar logic and wchar goes directly to std::ostream. And std::ostream do not work with wchar since C++20.

jsm174 commented 1 year ago

Wow. This is great. I will see if I can add that. (We have to do some wchar trickery since we are using bits of wine and trying to stay compatible with existing code)