/* Parse C expressions for cpplib.
- Copyright (C) 1987-2013 Free Software Foundation, Inc.
+ Copyright (C) 1987-2014 Free Software Foundation, Inc.
Contributed by Per Bothner, 1994.
This program is free software; you can redistribute it and/or modify it
unsigned int max_digit, result, radix;
enum {NOT_FLOAT = 0, AFTER_POINT, AFTER_EXPON} float_flag;
bool seen_digit;
+ bool seen_digit_sep;
if (ud_suffix)
*ud_suffix = NULL;
max_digit = 0;
radix = 10;
seen_digit = false;
+ seen_digit_sep = false;
/* First, interpret the radix. */
if (*str == '0')
str++;
/* Require at least one hex digit to classify it as hex. */
- if ((*str == 'x' || *str == 'X')
- && (str[1] == '.' || ISXDIGIT (str[1])))
+ if (*str == 'x' || *str == 'X')
{
- radix = 16;
- str++;
+ if (str[1] == '.' || ISXDIGIT (str[1]))
+ {
+ radix = 16;
+ str++;
+ }
+ else if (DIGIT_SEP (str[1]))
+ SYNTAX_ERROR_AT (virtual_location,
+ "digit separator after base indicator");
}
- else if ((*str == 'b' || *str == 'B') && (str[1] == '0' || str[1] == '1'))
+ else if (*str == 'b' || *str == 'B')
{
- radix = 2;
- str++;
+ if (str[1] == '0' || str[1] == '1')
+ {
+ radix = 2;
+ str++;
+ }
+ else if (DIGIT_SEP (str[1]))
+ SYNTAX_ERROR_AT (virtual_location,
+ "digit separator after base indicator");
}
}
if (ISDIGIT (c) || (ISXDIGIT (c) && radix == 16))
{
+ seen_digit_sep = false;
seen_digit = true;
c = hex_value (c);
if (c > max_digit)
max_digit = c;
}
+ else if (DIGIT_SEP (c))
+ {
+ if (seen_digit_sep)
+ SYNTAX_ERROR_AT (virtual_location, "adjacent digit separators");
+ seen_digit_sep = true;
+ }
else if (c == '.')
{
+ if (seen_digit_sep || DIGIT_SEP (*str))
+ SYNTAX_ERROR_AT (virtual_location,
+ "digit separator adjacent to decimal point");
+ seen_digit_sep = false;
if (float_flag == NOT_FLOAT)
float_flag = AFTER_POINT;
else
else if ((radix <= 10 && (c == 'e' || c == 'E'))
|| (radix == 16 && (c == 'p' || c == 'P')))
{
+ if (seen_digit_sep || DIGIT_SEP (*str))
+ SYNTAX_ERROR_AT (virtual_location,
+ "digit separator adjacent to exponent");
float_flag = AFTER_EXPON;
break;
}
}
}
+ if (seen_digit_sep && float_flag != AFTER_EXPON)
+ SYNTAX_ERROR_AT (virtual_location,
+ "digit separator outside digit sequence");
+
/* The suffix may be for decimal fixed-point constants without exponent. */
if (radix != 16 && float_flag == NOT_FLOAT)
{
/* Exponent is decimal, even if string is a hex float. */
if (!ISDIGIT (*str))
- SYNTAX_ERROR_AT (virtual_location, "exponent has no digits");
-
+ {
+ if (DIGIT_SEP (*str))
+ SYNTAX_ERROR_AT (virtual_location,
+ "digit separator adjacent to exponent");
+ else
+ SYNTAX_ERROR_AT (virtual_location, "exponent has no digits");
+ }
do
- str++;
- while (ISDIGIT (*str));
+ {
+ seen_digit_sep = DIGIT_SEP (*str);
+ str++;
+ }
+ while (ISDIGIT (*str) || DIGIT_SEP (*str));
}
else if (radix == 16)
SYNTAX_ERROR_AT (virtual_location,
"hexadecimal floating constants require an exponent");
+ if (seen_digit_sep)
+ SYNTAX_ERROR_AT (virtual_location,
+ "digit separator outside digit sequence");
+
result = interpret_float_suffix (pfile, str, limit - str);
if (result == 0)
{
&& CPP_OPTION (pfile, cpp_warn_long_long))
{
const char *message = CPP_OPTION (pfile, cplusplus)
- ? N_("use of C++0x long long integer constant")
+ ? N_("use of C++11 long long integer constant")
: N_("use of C99 long long integer constant");
if (CPP_OPTION (pfile, c99))
if ((result & CPP_N_IMAGINARY) && CPP_PEDANTIC (pfile))
cpp_error_with_line (pfile, CPP_DL_PEDWARN, virtual_location, 0,
"imaginary constants are a GCC extension");
- if (radix == 2 && CPP_PEDANTIC (pfile))
+ if (radix == 2
+ && !CPP_OPTION (pfile, binary_constants)
+ && CPP_PEDANTIC (pfile))
cpp_error_with_line (pfile, CPP_DL_PEDWARN, virtual_location, 0,
- "binary constants are a GCC extension");
+ CPP_OPTION (pfile, cplusplus)
+ ? "binary constants are a C++1y feature "
+ "or GCC extension"
+ : "binary constants are a GCC extension");
if (radix == 10)
result |= CPP_N_DECIMAL;
if (ISDIGIT (c) || (base == 16 && ISXDIGIT (c)))
c = hex_value (c);
+ else if (DIGIT_SEP (c))
+ continue;
else
break;
/* Arithmetic. */
case CPP_MINUS:
- rhs = num_negate (rhs, precision);
+ result.low = lhs.low - rhs.low;
+ result.high = lhs.high - rhs.high;
+ if (result.low > lhs.low)
+ result.high--;
+ result.unsignedp = lhs.unsignedp || rhs.unsignedp;
+ result.overflow = false;
+
+ result = num_trim (result, precision);
+ if (!result.unsignedp)
+ {
+ bool lhsp = num_positive (lhs, precision);
+ result.overflow = (lhsp != num_positive (rhs, precision)
+ && lhsp != num_positive (result, precision));
+ }
+ return result;
+
case CPP_PLUS:
result.low = lhs.low + rhs.low;
result.high = lhs.high + rhs.high;