Closed ecorm closed 2 years ago
Working on a PR for this.
Ok. I understand now why "foo"
style string literals where not used: it's because of the CharT
template parameter. This is another reason why it shouldn't be hard-coded to output to std::cout
.
Yes, I wrote the basic_json_diagnostics_visitor
class specifically for testing the basic_json_visitor2
and basic_json_visitor2_to_visitor_adaptor
classes during development, for receiving general CBOR and MessagePack key/value pairs and adapting them to JSON string/value pairs. It was never used in code that was tested with many compilers/environments, so its defects weren't caught.
And yes, the CharT
template parameter complicates declaring string constants without excessive verbosity, and needing to support C++11 with less support for constexpr
. Over the life of this project I went through a few attempts, and mostly settled on using static functions as shown here.
Submitted PR #386 .
The reason why I stumbled upon the basic_json_diagnostics_visitor
problems in the first place, is that I found a diagnostic visitor useful in troubleshooting the tests cases I made recently in my previous PRs. I had to write a temporary diagnostic visitor because the existing one wouldn't compile.
Or for constant C strings, like this
Usage of
basic_json_diagnostics_visitor
does not compile in C++11/14 modes due to itsstatic constexpr CharT visit_foo_name[]
members, which result in "unresolved external" linker errors.The fix is to add the following below the class declaration:
It may be cleaner just to use traditional string literals instead directly in the
std::cout
statements.With the above fix, when I run the example below, I get the following output, where there is no separation between the label the value:
Even with the above fix, I get the following compile error in Clang 12.0.0 (but not in GCC 9.4.0):
The fix is to add the following missing override in
basic_json_diagnostics_visitor
:Might I also suggest that a
basic_json_diagnostics_visitor
constructor be added that takes anostream
reference to which the diagnostic info will be output. By default, it could be bound tostd::cout
to preserve the current behavior.Include a small, self-contained example if possible
What compiler, architecture, and operating system?
What jsoncons library version?