@@ -2471,6 +2471,60 @@ static void ifA()
24712471 ASSERT_EQUALS (" \n X" , preprocess (code, dui));
24722472}
24732473
2474+ static void ifFloatingPointLiteral () // #612
2475+ {
2476+ simplecpp::OutputList outputList;
2477+ simplecpp::DUI dui;
2478+ dui.defines .emplace_back (" A=1" );
2479+
2480+ const char issue[] = " #if A == 1.0\n "
2481+ " int i;\n "
2482+ " #endif\n " ;
2483+ ASSERT_EQUALS (" " , preprocess (issue, dui, &outputList));
2484+ ASSERT_EQUALS (" file0,1,syntax_error,failed to evaluate #if condition, floating point literal in preprocessor expression\n " , toString (outputList));
2485+
2486+ outputList.clear ();
2487+
2488+ const char otherSpelling[] = " #if 0\n "
2489+ " #elif .5\n "
2490+ " int i;\n "
2491+ " #endif\n " ;
2492+ ASSERT_EQUALS (" " , preprocess (otherSpelling, &outputList));
2493+ ASSERT_EQUALS (" file0,2,syntax_error,failed to evaluate #elif condition, floating point literal in preprocessor expression\n " , toString (outputList));
2494+
2495+ outputList.clear ();
2496+
2497+ const char exponent[] = " #if 1e3\n "
2498+ " int i;\n "
2499+ " #endif\n " ;
2500+ ASSERT_EQUALS (" " , preprocess (exponent, &outputList));
2501+ ASSERT_EQUALS (" file0,1,syntax_error,failed to evaluate #if condition, floating point literal in preprocessor expression\n " , toString (outputList));
2502+
2503+ outputList.clear ();
2504+
2505+ const char suffix[] = " #if 1.f\n "
2506+ " int i;\n "
2507+ " #endif\n " ;
2508+ ASSERT_EQUALS (" " , preprocess (suffix, &outputList));
2509+ ASSERT_EQUALS (" file0,1,syntax_error,failed to evaluate #if condition, floating point literal in preprocessor expression\n " , toString (outputList));
2510+
2511+ outputList.clear ();
2512+
2513+ const char hexadecimal[] = " #if 0x1p3\n "
2514+ " int i;\n "
2515+ " #endif\n " ;
2516+ ASSERT_EQUALS (" " , preprocess (hexadecimal, &outputList));
2517+ ASSERT_EQUALS (" file0,1,syntax_error,failed to evaluate #if condition, floating point literal in preprocessor expression\n " , toString (outputList));
2518+
2519+ outputList.clear ();
2520+
2521+ const char integer[] = " #if A == 1\n "
2522+ " int i;\n "
2523+ " #endif\n " ;
2524+ ASSERT_EQUALS (" \n int i ;" , preprocess (integer, dui, &outputList));
2525+ ASSERT_EQUALS (" " , toString (outputList));
2526+ }
2527+
24742528static void ifCharLiteral ()
24752529{
24762530 const char code[] = " #if ('A'==0x41)\n "
@@ -4973,6 +5027,7 @@ static void runTests(int argc, char **argv, Input input)
49735027 TEST_CASE (ifdef2);
49745028 TEST_CASE (ifndef);
49755029 TEST_CASE (ifA);
5030+ TEST_CASE (ifFloatingPointLiteral); // #612
49765031 TEST_CASE (ifCharLiteral);
49775032 TEST_CASE (ifDefined);
49785033 TEST_CASE (ifDefinedNoPar);
0 commit comments