Commit Graph

1270 Commits

Author SHA1 Message Date
Moritz Klammler
fe471bcbe9 Autodetect the best option to use Boost.Test
The conditional inclusion of either the library or the header-only
version of the Boost.Test header wasn't tremendously useful in practice
because the tests/CMakeLists.txt file would unconditionally add compile
definitions to basically fore dynamic linking.

This patch adds feature detection to the tests/CMakeLists.txt file to
determine whether to use dynamic linking, static linking or the
header-only version (in that order of preference, for best performance).

The automatic detection could be overridden if needed by defining the
TOML11_WITH_BOOST_TEST_{HEADER,STATIC,DYNAMIC}
variables on the CMake command line.

While we are at it, instead of having a conditional
#define BOOST_TEST_NO_LIB
in each unit test file, handle this once in the CMakeLists.txt file.
2022-09-29 17:59:28 +02:00
Moritz Klammler
5312b8eb0e Honor UNITTEST_FRAMEWORK_LIBRARY_EXIST in all unit test files
Most unit test files checked UNITTEST_FRAMEWORK_LIBRARY_EXIST and
adapted themselves accordingly to either use the header-only version or
link with the library.  Alas, eight files didn't so the project couldn't
really be tested with the header-only version of that Boost library.

This patch adds the missing pre-processor logic to the files that were
missing it.  The style of using no indentation after the '#' was
followed from the existing unit test files.  Some other files in this
repository do indent their pre-processor logic, though.

Since replicating the conditional in every file is kind of verbose,
tedious and, apparently, easily forgotten, I'm wondering whether
isolating that logic into a tiny little auxiliary header and then
unconditionally including that one in each unit test file would be a
good idea, though.
2022-09-29 17:59:28 +02:00
Moritz Klammler
cf8a977be2 Don't deliberately dereference the null pointer
This patch addresses a static analysis issue reported by Cppcheck 2.9
where several member functions of the toml::discard_comment class
defined in the toml/comments.hpp header were implemented to deliberately
dereference the null pointer returned unconditionally by the
always-empty container's data() member function.  This behavior wasn't
technically wrong because those functions all have as precondition that
the container is non-empty so they must never be called on an instance
of toml::discard_comment but we can still be more helpful without
adversely affecting code generation.  Instead of dereferencing the null
pointer, this patch has these functions call an inline private helper
function which is defined to invoke __builtin_unreachable() if available
"and then" throw an exception with a helpful error message.  Even at the
-O1 level, GCC will optimize the code under the assumption that the
function will never be called (i.e. no assembly is emitted), making
failure to ensure this undefined behavior exactly as if the null pointer
had been dereferenced.  However, static analysis will now understand the
programmer's intent and remain silent.  Furthermore, when using the -O0
or -Og levels, GCC won't optimize under this assumption so the exception
will be thrown and might be helpful for debugging.  Compilers that don't
have __builtin_unreachable() won't get any help in determining that the
function must not be called and will have to figure this out by
analyzing the calling code -- which really shouldn't exist in the first
place anyway as the whole point is that these functions must not be
called.
2022-09-29 17:59:28 +02:00
Moritz Klammler
8bb2c63a01 Don't compare iterators from potentially different containers
This patch addresses a static analysis issue reported by Cppcheck 2.9
where an assertion in the toml/region.hpp header would compare two
container's (that are known to be of type std::vector<char>) begin() and
end() iterators in order to verify that they are the same.  This
assertion either passes or invokes undefined behavior.  Which isn't
technically wrong because calling code must always ensure that
preconditions are met and assertions therefore pass anyway but it does
make the value that is added by having the assertion in the first place
marginal.  Fortunately, the assertion was easy to rewrite: Just compare
the container's address itself.  This is well-defined regardless of
whether the assertion will pass or fail.
2022-09-29 17:59:28 +02:00
Moritz Klammler
79c125b54f Initialize data members for defaulted c'tors
This patch addresses a static analysis issue reported by Cppcheck 2.9
where several classes in the toml/datetime.hpp header explicitly default
all their special member functions, including the default constructor,
but don't provide initializers for their data members.  This might or
might not have caused any observable surprising behavior but I agree
with Cppcheck on this one in that an explicitly defaulted default
constructor should be expected to initialize all data members.  So let's
do that.
2022-09-29 17:59:27 +02:00
ToruNiina
b02aaed4fc fix: use fs::path, not fs::path::string() result 2022-09-29 21:28:35 +09:00
ToruNiina
c2af975609 fix: add missing include file and specifiers 2022-09-29 20:14:58 +09:00
Toru Niina
c3a3423fb2 Merge pull request #193 from lukash/replace-fstream
Use C-style IO instead of ifstream for parsing
2022-09-24 00:17:52 +09:00
Lukáš Hrázký
6c2c804eff fix: Improve error handling of ifstream a bit
Set the exceptions mask so that exceptions are thrown when an I/O error
occurs. Also throw the same exception type when the opening fails.
2022-09-08 17:05:15 +02:00
Lukáš Hrázký
021d84623c chore: De-duplicate code for parse(std::filesystem::path) 2022-09-08 17:05:15 +02:00
Lukáš Hrázký
bf9c9d620d feat: Add a parse(FILE *) interface
The fstream classes are notorious for their non-existent error handling.

This adds a C-style fILE * IO (fopen(), etc.) alternative interface, so
that if a user needs reliable error handling, they can use that, albeit
more inconvenient, but more robust approach.
2022-09-08 17:05:11 +02:00
Toru Niina
bbdbae91eb Merge pull request #196 from Jajauma/AvoidCharStaticCasts
Avoid possible lexer truncation warnings
2022-08-17 23:47:10 +09:00
Jajauma's GitHub
72af7b48d3 Avoid possible lexer truncation warnings
Instead of static_cast calls that convert int to char, literals of type
char are now used directly with the value encoded via escape sequence.

The benefits are:
- code without static_cast is much more compact and expresses intent
better
- fixed value truncation warning on some compilers (e.g. C4309 on Visual
Studio 2017)
2022-08-13 10:30:18 +00:00
Toru Niina
c7627ff6a1 Merge pull request #194 from Helaxious/patch-1
Fix a typo ('optinoal' to 'optional')
2022-07-28 21:02:21 +09:00
helaxious
1c3c84e90a fixed a typo ('optinoal' to 'optional') 2022-07-27 17:58:47 -03:00
ToruNiina
1400dd223f fix: #192 quick fix by checking address 2022-07-01 01:09:22 +09:00
Lukáš Hrázký
594accf9a7 chore: Don't include fstream in lexer 2022-06-30 11:37:53 +02:00
ToruNiina
c1378cd3d1 ci: test older gcc/clang on older ubuntu 2022-06-25 01:18:32 +09:00
ToruNiina
728f73ea24 ci: update compilers available on the os 2022-06-24 23:31:52 +09:00
ToruNiina
4212985443 ci: update os used on ci to the current default 2022-06-22 22:06:11 +09:00
ToruNiina
8e95891af1 fix: report an error if a table is inserted to aot 2022-06-22 21:48:37 +09:00
ToruNiina
2a987ac9ea chore: update toml-test to the latest release 2022-06-22 21:28:31 +09:00
ToruNiina
9e1bfcc962 doc: merge contributions from the same person 2022-06-22 21:24:22 +09:00
ToruNiina
4a0df22548 doc: update contributor list 2022-06-14 23:31:58 +09:00
ToruNiina
1ba3be38d0 fix: point the beginning of value in err msg 2022-06-08 01:33:10 +09:00
ToruNiina
5be587bb68 fix #190: Merge branch 'throw-when-overflow' 2022-06-08 01:27:30 +09:00
ToruNiina
d6efdf7d9e test: check if an exception is thrown by overflow 2022-06-08 00:40:28 +09:00
ToruNiina
12d0dbc6f4 fix: throw if number cannot be read losslessly
it throws when strtoll and strtof that are internally called fail
2022-06-08 00:39:04 +09:00
Toru Niina
6d9e533cf1 Merge pull request #189 from muggenhor/fix/avoid-fname-copy
fix: don't force a copy of std::string fname when moving is an option
2022-06-04 20:49:33 +09:00
Giel van Schijndel
aff6f0f574 fix: don't force a copy of std::string fname when moving is an option
Taking this parameter by const reference forces us to copy it (because
we know we're going to store it). Taking it by r-value reference would
suggest that we _might_ take ownership over it and would also force the
user to make a copy if they wish to retain the original value.

Taking this parameter by value however clearly gives us ownership of its
content without forcing a copy if it's implicit conversion from
`const char*` or explicitly handed over to us by the user via std::move.
2022-06-02 14:39:10 +02:00
ToruNiina
25be97dc39 refactor: style update 2022-05-29 00:37:39 +09:00
Toru Niina
846abd9a49 Merge pull request #188 from ken-matsui/support-changing-color-mode-at-runtime
Support changing color mode at runtime
2022-05-27 22:49:56 +09:00
Ken Matsui
9086b1114f Support changing color mode at runtime 2022-05-27 00:01:28 +09:00
ToruNiina
e8f922a1b8 chore: use the latest release of toml-test on CI
The CI task that corresponds to toml-test HEAD is currently failing.
Using the latest stable release is safer.
2022-05-22 15:40:54 +09:00
Toru Niina
fdb228598d Merge pull request #187 from ken-matsui/support-opting-out-of-error-prefix
Support opting out of the default `[error]` prefix
2022-05-22 15:22:01 +09:00
Ken Matsui
c26aa013cd Support opting out of the default [error] prefix 2022-05-22 13:50:45 +09:00
ToruNiina
5924325652 doc: update unreleased TOML features section 2022-03-17 00:07:48 +09:00
ToruNiina
1836ddc129 test: test -DTOML11_USE_UNRELEASED_TOML_FEATURES 2022-03-16 22:46:21 +09:00
ToruNiina
1c82c7a1dc fix: move cmake option to toplevel cmakelists 2022-03-16 22:40:42 +09:00
ToruNiina
dde351ea40 feat: add escape sequence of ESC
as an unreleased feature
2022-03-16 22:39:52 +09:00
ToruNiina
dcfe39a783 chore: update version number v3.7.1 2022-03-13 01:44:29 +09:00
ToruNiina
2f07030d43 doc: update the list of contributors 2022-03-13 01:40:43 +09:00
ToruNiina
97cc0ef62b fix #166: reorder local/gmtime wrapper for MSVC 2022-03-13 00:20:00 +09:00
ToruNiina
0e80cabe65 Merge branch 'check-specialized-conversion' 2022-03-12 19:00:29 +09:00
ToruNiina
cd97dfcec1 Merge branch 'insertion-to-table-defined-by-dotted-key' 2022-03-12 19:00:07 +09:00
ToruNiina
e60442c6db fix: check if re-open dotkey by a table
like:
```
a.b.c = "foo"
[a.b] # this is invalid
d = "bar"
```
2022-03-12 18:22:01 +09:00
Toru Niina
d39fd88a17 Merge pull request #185 from ax3l/topic-installEmbed
CMake: Optional Install if Embedded
2022-03-07 23:12:33 +09:00
Axel Huebl
7fb8b84143 CMake: Optional Install if Embedded
When adding this library as embedded library with private
"target link", e.g., only used inside private source files, the
library does not need to be installed when the main project gets
installed.

This adds an additional option `toml11_INSTALL` similar to the
test-build control switch in order to skip installing headers and
CMake config files if requested.

Avoids using
```cmake
add_subdirectory(path/to/toml11 EXCLUDE_FROM_ALL)
```

which has further side-effects:
https://cmake.org/cmake/help/v3.0/command/add_subdirectory.html
2022-03-03 18:55:55 -08:00
ToruNiina
03259e2003 fix #177: check specific conversion function
when converting toml::value to array-like
2021-12-25 14:08:55 +09:00
ToruNiina
bf2384d8da fix #182: Merge branch 'workaround-msvc-cplusplus-macro' 2021-12-18 15:41:43 +09:00