@@ -2293,6 +2293,60 @@ static void ifA()
22932293 ASSERT_EQUALS (" \n X" , preprocess (code, dui));
22942294}
22952295
2296+ static void ifFloatingPointLiteral () // #612
2297+ {
2298+ simplecpp::OutputList outputList;
2299+ simplecpp::DUI dui;
2300+ dui.defines .emplace_back (" A=1" );
2301+
2302+ const char issue[] = " #if A == 1.0\n "
2303+ " int i;\n "
2304+ " #endif\n " ;
2305+ ASSERT_EQUALS (" " , preprocess (issue, dui, &outputList));
2306+ ASSERT_EQUALS (" file0,1,syntax_error,failed to evaluate #if condition, floating point literal in preprocessor expression\n " , toString (outputList));
2307+
2308+ outputList.clear ();
2309+
2310+ const char otherSpelling[] = " #if 0\n "
2311+ " #elif .5\n "
2312+ " int i;\n "
2313+ " #endif\n " ;
2314+ ASSERT_EQUALS (" " , preprocess (otherSpelling, &outputList));
2315+ ASSERT_EQUALS (" file0,2,syntax_error,failed to evaluate #elif condition, floating point literal in preprocessor expression\n " , toString (outputList));
2316+
2317+ outputList.clear ();
2318+
2319+ const char exponent[] = " #if 1e3\n "
2320+ " int i;\n "
2321+ " #endif\n " ;
2322+ ASSERT_EQUALS (" " , preprocess (exponent, &outputList));
2323+ ASSERT_EQUALS (" file0,1,syntax_error,failed to evaluate #if condition, floating point literal in preprocessor expression\n " , toString (outputList));
2324+
2325+ outputList.clear ();
2326+
2327+ const char suffix[] = " #if 1.f\n "
2328+ " int i;\n "
2329+ " #endif\n " ;
2330+ ASSERT_EQUALS (" " , preprocess (suffix, &outputList));
2331+ ASSERT_EQUALS (" file0,1,syntax_error,failed to evaluate #if condition, floating point literal in preprocessor expression\n " , toString (outputList));
2332+
2333+ outputList.clear ();
2334+
2335+ const char hexadecimal[] = " #if 0x1p3\n "
2336+ " int i;\n "
2337+ " #endif\n " ;
2338+ ASSERT_EQUALS (" " , preprocess (hexadecimal, &outputList));
2339+ ASSERT_EQUALS (" file0,1,syntax_error,failed to evaluate #if condition, floating point literal in preprocessor expression\n " , toString (outputList));
2340+
2341+ outputList.clear ();
2342+
2343+ const char integer[] = " #if A == 1\n "
2344+ " int i;\n "
2345+ " #endif\n " ;
2346+ ASSERT_EQUALS (" \n int i ;" , preprocess (integer, dui, &outputList));
2347+ ASSERT_EQUALS (" " , toString (outputList));
2348+ }
2349+
22962350static void ifCharLiteral ()
22972351{
22982352 const char code[] = " #if ('A'==0x41)\n "
@@ -4717,6 +4771,7 @@ static void runTests(int argc, char **argv, Input input)
47174771 TEST_CASE (ifdef2);
47184772 TEST_CASE (ifndef);
47194773 TEST_CASE (ifA);
4774+ TEST_CASE (ifFloatingPointLiteral); // #612
47204775 TEST_CASE (ifCharLiteral);
47214776 TEST_CASE (ifDefined);
47224777 TEST_CASE (ifDefinedNoPar);
0 commit comments