diff --git a/src/libs/cplusplus/pp-engine.cpp b/src/libs/cplusplus/pp-engine.cpp
index f6852efc8cd736931aba2b58e27ac60eb9d5b23a..3041fd827e3874d9a53d9ad4b71154d1348a6dba 100644
--- a/src/libs/cplusplus/pp-engine.cpp
+++ b/src/libs/cplusplus/pp-engine.cpp
@@ -757,6 +757,8 @@ bool Preprocessor::markGeneratedTokens(bool markGeneratedTokens,
 void Preprocessor::preprocess(const QString &fileName, const QByteArray &source,
                               QByteArray *result)
 {
+    const int previousIfLevel = iflevel;
+
     QByteArray *previousResult = _result;
     _result = result;
 
@@ -889,6 +891,8 @@ void Preprocessor::preprocess(const QString &fileName, const QByteArray &source,
     env->currentFile = previousFileName;
     env->currentLine = previousCurrentLine;
     _result = previousResult;
+
+    iflevel = previousIfLevel;
 }
 
 void Preprocessor::collectActualArguments(QVector<MacroArgumentReference> *actuals)