@@ -2869,7 +2869,10 @@ static void ifShortCircuit()
28692869 " defined(X) and X/0" ,
28702870 " 0 && 1 bitor (1/0)" ,
28712871 " !(1 || (1/0) bitand 1)" ,
2872- " 0 and 1 xor (1/0)"
2872+ " 0 and 1 xor (1/0)" ,
2873+ " 0 && not (1/0)" ,
2874+ " 0 && compl (1/0)" ,
2875+ " !(1 || not not (1/0))"
28732876 };
28742877 for (const char * const expr : exprs) {
28752878 const std::string code = std::string (" #if " ) + expr + " \n "
@@ -2886,6 +2889,9 @@ static void ifShortCircuit()
28862889 simplecpp::OutputList outputList;
28872890 ASSERT_EQUALS (" " , preprocess (" #if 1 && (1/0)\n #endif\n " , &outputList));
28882891 ASSERT_EQUALS (" file0,1,syntax_error,failed to evaluate #if condition, division/modulo by zero\n " , toString (outputList));
2892+ outputList.clear ();
2893+ ASSERT_EQUALS (" " , preprocess (" #if not (1/0)\n #endif\n " , &outputList));
2894+ ASSERT_EQUALS (" file0,1,syntax_error,failed to evaluate #if condition, division/modulo by zero\n " , toString (outputList));
28892895}
28902896
28912897static void ifZeroCondition ()
@@ -3022,6 +3028,45 @@ static void ifalt() // using "and", "or", etc
30223028 ASSERT_EQUALS (" \n 1" , preprocess (code));
30233029}
30243030
3031+ static void ifAltUnaryOperators () // "not" and "compl" anywhere a unary operator is allowed
3032+ {
3033+ const char * const exprs[] = {
3034+ // at the start of the expression
3035+ " not 0" ,
3036+ " (not 0)" ,
3037+ " not 0 && 1" ,
3038+ " compl 0" ,
3039+ // after a binary operator, "?" or ":"
3040+ " 1 && not 0" ,
3041+ " 1 and not 0" ,
3042+ " 0 || not 0" ,
3043+ " 1 == not 0" ,
3044+ " 0 ? 0 : not 0" ,
3045+ " 1 ? not 0 : 0" ,
3046+ // next to another unary operator
3047+ " not not 1" ,
3048+ " not -0" ,
3049+ " not ~-1" ,
3050+ " not !0 == 0" ,
3051+ " compl compl 1 == 1" ,
3052+ " compl -1 == 0" ,
3053+ " !(compl -1 + 1 == 0)" ,
3054+ " -compl 0 == 1" ,
3055+ // followed by "("
3056+ " not (0)" ,
3057+ " not(0)" ,
3058+ " compl (0) == -1"
3059+ };
3060+ for (const char * const expr : exprs) {
3061+ const std::string code = std::string (" #if " ) + expr + " \n "
3062+ " 1\n "
3063+ " #else\n "
3064+ " 2\n "
3065+ " #endif\n " ;
3066+ ASSERT_EQUALS (" \n 1" , preprocess (code.c_str ()));
3067+ }
3068+ }
3069+
30253070static void ifexpr ()
30263071{
30273072 const char code[] = " #define MACRO() (1)\n "
@@ -5226,6 +5271,7 @@ static void runTests(int argc, char **argv, Input input)
52265271 TEST_CASE (ifInvalidExpression);
52275272 TEST_CASE (ifTrueFalse);
52285273 TEST_CASE (ifalt); // using "and", "or", etc
5274+ TEST_CASE (ifAltUnaryOperators);
52295275 TEST_CASE (ifexpr);
52305276 TEST_CASE (ifUndefFuncStyleMacro);
52315277
0 commit comments