Skip to content
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

Hack: Expression won't be evaluated. #73

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion integrationTest/expected/dictionaryFindAll.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ ieieieieieieie2
50 | folder/../SimpleTestObject.h | 45 | In the header, I am %d
51 | main.cc | 435 | L=%Lf %LF %Le %LE %Lg %LG %La %LA
52 | main.cc | 89 | Let's try out all the types! Pointer = %p! uint8_t = %u! uint16_t = %u! uint32_t = %u! uint64_t = %lu! float = %f! double = %lf! hexadecimal = %x! Just a normal character = %c
53 | main.cc | 457 | Loop test!
53 | main.cc | 464 | Loop test!
54 | main.cc | 237 | Make sure that the inserted code is before the ++i
55 | folder/Sample.h | 50 | Messages in the Header File
56 | main.cc | 43 | More simplicity
Expand Down Expand Up @@ -93,3 +93,4 @@ ieieieieieieie2
89 | main.cc | 205 | sneaky #define LOG
90 | main.cc | 426 | t=%td %ti %tu %to %tx %tx
91 | main.cc | 417 | z=%zd %zi %zu %zo %zx %zx
92 | main.cc | 451 | This value %d won't be printed.
9 changes: 9 additions & 0 deletions integrationTest/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,13 @@ void testAllTheTypes() {
(long double)14.0);
}

// Expression should be evaluated when severity is lower than NanoLog's.
void expressionShouldBeEvaluated(){
NanoLog::setLogLevel(NOTICE);
int val = 0;
NANO_LOG(DEBUG, "This value %d won't be printed.", val++);
assert(val == 1);
}

int main()
{
Expand Down Expand Up @@ -473,6 +480,8 @@ int main()

logLevelTest();

expressionShouldBeEvaluated();

NanoLog::sync();

printf("\r\nNote: This app is used in the integration tests, but "
Expand Down
7 changes: 4 additions & 3 deletions runtime/NanoLogCpp17.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <cstring>

#include <algorithm>
#include <array>
#include <iostream>
#include <utility>

Expand Down Expand Up @@ -1005,6 +1006,9 @@ log(int &logId,
using namespace NanoLogInternal::Log;
assert(N == static_cast<uint32_t>(sizeof...(Ts)));

if (severity > NanoLog::getLogLevel())
return;

if (logId == UNASSIGNED_LOGID) {
const ParamType *array = paramTypes.data();
StaticLogInfo info(&compress<Ts...>,
Expand Down Expand Up @@ -1084,9 +1088,6 @@ checkFormat(NANOLOG_PRINTF_FORMAT const char *, ...) {}
NanoLogInternal::analyzeFormatString<nParams>(format); \
static int logId = NanoLogInternal::UNASSIGNED_LOGID; \
\
if (NanoLog::severity > NanoLog::getLogLevel()) \
break; \
\
/* Triggers the GNU printf checker by passing it into a no-op function.
* Trick: This call is surrounded by an if false so that the VA_ARGS don't
* evaluate for cases like '++i'.*/ \
Expand Down