Commit a391671
committed
add StringFrom for std::nullptr_t values
In C++11, the nullptr_t type was introduced, and in some projects NULL
is defined as nullptr. In this case, the C++ compiler will produce
warnings when trying to convert NULL to a string, because it is
ambiguous which conversion is used.
test.cpp:89:2: error: call to 'StringFrom' is ambiguous
CHECK_EQUAL(NULL, actual);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/local/include/CppUTest/UtestMacros.h:127:3: note: expanded from macro 'CHECK_EQUAL'
CHECK_EQUAL_LOCATION(expected, actual, NULL, __FILE__, __LINE__)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/local/include/CppUTest/UtestMacros.h:138:52: note: expanded from macro 'CHECK_EQUAL_LOCATION'
UtestShell::getCurrent()->assertEquals(true, StringFrom(expected).asCharString(), StringFrom(actual).asCharString(), text, file, line); \
^~~~~~~~~~
/usr/local/include/CppUTest/SimpleString.h:138:14: note: candidate function
SimpleString StringFrom(const void* value);
^
/usr/local/include/CppUTest/SimpleString.h:139:14: note: candidate function
SimpleString StringFrom(void (*value)());
^
/usr/local/include/CppUTest/SimpleString.h:141:14: note: candidate function
SimpleString StringFrom(const char *value);
^
/usr/local/include/CppUTest/SimpleString.h:137:14: note: candidate function
SimpleString StringFrom(bool value);
^
/usr/local/include/CppUTest/SimpleString.h:157:14: note: candidate function
SimpleString StringFrom(const SimpleString& other);
^
/usr/local/include/CppUTest/SimpleString.h:171:14: note: candidate function
SimpleString StringFrom(const std::string& other);
These warnings can be resolved by providing a StringFrom which takes the
nullptr_t as the argument, avoiding the need for conversions at all.
According to the C++ standard, the define __cplusplus is set to a value greater
than 199711L when C++ 11 is supported. Thus, we'll check this when implementing
the function, in order to allow building on older C++ standards.
Additionally, avoid a compiler warning due to the expected unused parameter in
the implementation of StringFrom.
Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>1 parent 1317b74 commit a391671
File tree
3 files changed
+19
-1
lines changed- include/CppUTest
- src/CppUTest
- tests/CppUTest
3 files changed
+19
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
174 | 174 | | |
175 | 175 | | |
176 | 176 | | |
177 | | - | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
178 | 180 | | |
179 | 181 | | |
180 | 182 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
540 | 540 | | |
541 | 541 | | |
542 | 542 | | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
543 | 549 | | |
544 | 550 | | |
545 | 551 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
572 | 572 | | |
573 | 573 | | |
574 | 574 | | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
575 | 585 | | |
576 | 586 | | |
577 | 587 | | |
| |||
0 commit comments