summaryrefslogtreecommitdiff
path: root/libcpp
diff options
context:
space:
mode:
authorJoseph Myers <joseph@codesourcery.com>2019-10-11 23:22:52 +0100
committerJoseph Myers <jsm28@gcc.gnu.org>2019-10-11 23:22:52 +0100
commit175a85b29718141d73230ed19efcfcf963a0d0b6 (patch)
tree298edc1e58a374a72a21832169c07cd2157bcb8b /libcpp
parent53f3c1a103d3939c1bf72361830280fa621d528a (diff)
Support decimal floating-point constants in C2x.
ISO C2x adds decimal floating point as an optional standard feature. This patch accordingly makes GCC accept DFP constants (DF, DD, DL, df, dd, dl suffixes) in strict C2X mode, with a pedwarn-if-pedantic for older standards and a warning with -Wc11-c2x-compat even in C2x mode (which in turn requires -Wc11-c2x-compat to be newly passed through to libcpp). Bootstrapped with no regressions on x86_64-pc-linux-gnu. gcc/c-family: * c.opt (Wc11-c2x-compat): Add CPP(cpp_warn_c11_c2x_compat) CppReason(CPP_W_C11_C2X_COMPAT). gcc/testsuite: * gcc.dg/dfp/c11-constants-1.c, gcc.dg/dfp/c11-constants-2.c, gcc.dg/dfp/c2x-constants-1.c, gcc.dg/dfp/c2x-constants-2.c: New tests. * gcc.dg/dfp/constants-pedantic.c: Use -std=gnu17 explicitly. Update expected diagnostics. libcpp: * include/cpplib.h (struct cpp_options): Add dfp_constants and cpp_warn_c11_c2x_compat. (enum cpp_warning_reason): Add CPP_W_C11_C2X_COMPAT. * init.c (struct lang_flags): Add dfp_constants. (lang_defaults): Set dfp_constants to 1 for GNUC2X and STDC2X and 0 for other languages. (cpp_set_lang): Set dfp_constants from language. (cpp_create_reader): Set cpp_warn_c11_c2x_compat to -1. * expr.c (interpret_float_suffix): Mention DFP constants as C2X in comment. (cpp_classify_number): Do not diagnose DFP constants for languages setting dfp_constants, unless cpp_warn_c11_c2x_compat. From-SVN: r276908
Diffstat (limited to 'libcpp')
-rw-r--r--libcpp/ChangeLog15
-rw-r--r--libcpp/expr.c17
-rw-r--r--libcpp/include/cpplib.h7
-rw-r--r--libcpp/init.c49
4 files changed, 60 insertions, 28 deletions
diff --git a/libcpp/ChangeLog b/libcpp/ChangeLog
index f3237fbd38f..e8d2e488588 100644
--- a/libcpp/ChangeLog
+++ b/libcpp/ChangeLog
@@ -1,3 +1,18 @@
+2019-10-11 Joseph Myers <joseph@codesourcery.com>
+
+ * include/cpplib.h (struct cpp_options): Add dfp_constants and
+ cpp_warn_c11_c2x_compat.
+ (enum cpp_warning_reason): Add CPP_W_C11_C2X_COMPAT.
+ * init.c (struct lang_flags): Add dfp_constants.
+ (lang_defaults): Set dfp_constants to 1 for GNUC2X and STDC2X and
+ 0 for other languages.
+ (cpp_set_lang): Set dfp_constants from language.
+ (cpp_create_reader): Set cpp_warn_c11_c2x_compat to -1.
+ * expr.c (interpret_float_suffix): Mention DFP constants as C2X in
+ comment.
+ (cpp_classify_number): Do not diagnose DFP constants for languages
+ setting dfp_constants, unless cpp_warn_c11_c2x_compat.
+
2019-10-04 Nathan Sidwell <nathan@acm.org>
PR preprocessor/91991
diff --git a/libcpp/expr.c b/libcpp/expr.c
index 4b514b17d9c..65baafe3f1e 100644
--- a/libcpp/expr.c
+++ b/libcpp/expr.c
@@ -98,8 +98,8 @@ interpret_float_suffix (cpp_reader *pfile, const uchar *s, size_t len)
flags = 0;
f = d = l = w = q = i = fn = fnx = fn_bits = 0;
- /* The following decimal float suffixes, from TR 24732:2009 and TS
- 18661-2:2015, are supported:
+ /* The following decimal float suffixes, from TR 24732:2009, TS
+ 18661-2:2015 and C2X, are supported:
df, DF - _Decimal32.
dd, DD - _Decimal64.
@@ -744,9 +744,16 @@ cpp_classify_number (cpp_reader *pfile, const cpp_token *token,
cpp_error_with_line (pfile, CPP_DL_PEDWARN, virtual_location, 0,
"fixed-point constants are a GCC extension");
- if ((result & CPP_N_DFLOAT) && CPP_PEDANTIC (pfile))
- cpp_error_with_line (pfile, CPP_DL_PEDWARN, virtual_location, 0,
- "decimal float constants are a GCC extension");
+ if (result & CPP_N_DFLOAT)
+ {
+ if (CPP_PEDANTIC (pfile) && !CPP_OPTION (pfile, dfp_constants))
+ cpp_error_with_line (pfile, CPP_DL_PEDWARN, virtual_location, 0,
+ "decimal float constants are a C2X feature");
+ else if (CPP_OPTION (pfile, cpp_warn_c11_c2x_compat) > 0)
+ cpp_warning_with_line (pfile, CPP_W_C11_C2X_COMPAT,
+ virtual_location, 0,
+ "decimal float constants are a C2X feature");
+ }
result |= CPP_N_FLOATING;
}
diff --git a/libcpp/include/cpplib.h b/libcpp/include/cpplib.h
index ccbcfde6dc4..224369b93ad 100644
--- a/libcpp/include/cpplib.h
+++ b/libcpp/include/cpplib.h
@@ -480,6 +480,9 @@ struct cpp_options
/* Nonzero for C++ 2014 Standard digit separators. */
unsigned char digit_separators;
+ /* Nonzero for C2X decimal floating-point constants. */
+ unsigned char dfp_constants;
+
/* Nonzero for C++2a __VA_OPT__ feature. */
unsigned char va_opt;
@@ -508,6 +511,9 @@ struct cpp_options
/* True if warn about differences between C90 and C99. */
signed char cpp_warn_c90_c99_compat;
+ /* True if warn about differences between C11 and C2X. */
+ signed char cpp_warn_c11_c2x_compat;
+
/* True if warn about differences between C++98 and C++11. */
bool cpp_warn_cxx11_compat;
@@ -607,6 +613,7 @@ enum cpp_warning_reason {
CPP_W_DATE_TIME,
CPP_W_PEDANTIC,
CPP_W_C90_C99_COMPAT,
+ CPP_W_C11_C2X_COMPAT,
CPP_W_CXX11_COMPAT,
CPP_W_EXPANSION_TO_DEFINED
};
diff --git a/libcpp/init.c b/libcpp/init.c
index c932598b5fb..4bcec7be3e5 100644
--- a/libcpp/init.c
+++ b/libcpp/init.c
@@ -93,32 +93,33 @@ struct lang_flags
char utf8_char_literals;
char va_opt;
char scope;
+ char dfp_constants;
};
static const struct lang_flags lang_defaults[] =
-{ /* c99 c++ xnum xid c11 std digr ulit rlit udlit bincst digsep trig u8chlit vaopt scope*/
- /* GNUC89 */ { 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1 },
- /* GNUC99 */ { 1, 0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1, 1, 1 },
- /* CXX17 */ { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1 },
- /* GNUCXX2A */ { 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1 },
- /* CXX2A */ { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1 },
- /* ASM */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
+{ /* c99 c++ xnum xid c11 std digr ulit rlit udlit bincst digsep trig u8chlit vaopt scope dfp */
+ /* GNUC89 */ { 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0 },
+ /* GNUC99 */ { 1, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0 },
+ /* GNUC11 */ { 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0 },
+ /* GNUC17 */ { 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0 },
+ /* GNUC2X */ { 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1 },
+ /* STDC89 */ { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 },
+ /* STDC94 */ { 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 },
+ /* STDC99 */ { 1, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 },
+ /* STDC11 */ { 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0 },
+ /* STDC17 */ { 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0 },
+ /* STDC2X */ { 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 1, 1 },
+ /* GNUCXX */ { 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0 },
+ /* CXX98 */ { 0, 1, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0 },
+ /* GNUCXX11 */ { 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0 },
+ /* CXX11 */ { 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 1, 0 },
+ /* GNUCXX14 */ { 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0 },
+ /* CXX14 */ { 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0 },
+ /* GNUCXX17 */ { 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0 },
+ /* CXX17 */ { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0 },
+ /* GNUCXX2A */ { 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0 },
+ /* CXX2A */ { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0 },
+ /* ASM */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
};
/* Sets internal flags correctly for a given language. */
@@ -145,6 +146,7 @@ cpp_set_lang (cpp_reader *pfile, enum c_lang lang)
CPP_OPTION (pfile, utf8_char_literals) = l->utf8_char_literals;
CPP_OPTION (pfile, va_opt) = l->va_opt;
CPP_OPTION (pfile, scope) = l->scope;
+ CPP_OPTION (pfile, dfp_constants) = l->dfp_constants;
}
/* Initialize library global state. */
@@ -193,6 +195,7 @@ cpp_create_reader (enum c_lang lang, cpp_hash_table *table,
CPP_OPTION (pfile, warn_trigraphs) = 2;
CPP_OPTION (pfile, warn_endif_labels) = 1;
CPP_OPTION (pfile, cpp_warn_c90_c99_compat) = -1;
+ CPP_OPTION (pfile, cpp_warn_c11_c2x_compat) = -1;
CPP_OPTION (pfile, cpp_warn_cxx11_compat) = 0;
CPP_OPTION (pfile, cpp_warn_deprecated) = 1;
CPP_OPTION (pfile, cpp_warn_long_long) = 0;