diff options
author | Jakub Jelinek <jakub@redhat.com> | 2024-11-13 09:41:41 +0100 |
---|---|---|
committer | Jakub Jelinek <jakub@gcc.gnu.org> | 2024-11-13 09:41:41 +0100 |
commit | eb45d151fa1780d01533d9fc9545fec50bfd7152 (patch) | |
tree | 5270592b4fc51ec8898cf3a0b86d6773a09c7ca3 /libcpp/expr.cc | |
parent | 9b2915d95d855333d4d8f66b71a75f653ee0d076 (diff) | |
download | gcc-eb45d151fa1780d01533d9fc9545fec50bfd7152.zip gcc-eb45d151fa1780d01533d9fc9545fec50bfd7152.tar.gz gcc-eb45d151fa1780d01533d9fc9545fec50bfd7152.tar.bz2 |
c: Implement C2Y N3298 - Introduce complex literals [PR117029]
The following patch implements the C2Y N3298 paper Introduce complex literals
by providing different (or no) diagnostics on imaginary constants (except
for integer ones).
For _DecimalN constants we don't support _Complex _DecimalN and error on any
i/j suffixes mixed with DD/DL/DF, so nothing changed there.
2024-11-13 Jakub Jelinek <jakub@redhat.com>
PR c/117029
libcpp/
* include/cpplib.h (struct cpp_options): Add imaginary_constants
member.
* init.cc (struct lang_flags): Add imaginary_constants bitfield.
(lang_defaults): Add column for imaginary_constants.
(cpp_set_lang): Copy over imaginary_constants.
* expr.cc (cpp_classify_number): Diagnose CPP_N_IMAGINARY
non-CPP_N_FLOATING constants differently for C.
gcc/testsuite/
* gcc.dg/cpp/pr7263-3.c: Adjust expected diagnostic wording.
* gcc.dg/c23-imaginary-constants-1.c: New test.
* gcc.dg/c23-imaginary-constants-2.c: New test.
* gcc.dg/c23-imaginary-constants-3.c: New test.
* gcc.dg/c23-imaginary-constants-4.c: New test.
* gcc.dg/c23-imaginary-constants-5.c: New test.
* gcc.dg/c23-imaginary-constants-6.c: New test.
* gcc.dg/c23-imaginary-constants-7.c: New test.
* gcc.dg/c23-imaginary-constants-8.c: New test.
* gcc.dg/c23-imaginary-constants-9.c: New test.
* gcc.dg/c23-imaginary-constants-10.c: New test.
* gcc.dg/c2y-imaginary-constants-1.c: New test.
* gcc.dg/c2y-imaginary-constants-2.c: New test.
* gcc.dg/c2y-imaginary-constants-3.c: New test.
* gcc.dg/c2y-imaginary-constants-4.c: New test.
* gcc.dg/c2y-imaginary-constants-5.c: New test.
* gcc.dg/c2y-imaginary-constants-6.c: New test.
* gcc.dg/c2y-imaginary-constants-7.c: New test.
* gcc.dg/c2y-imaginary-constants-8.c: New test.
* gcc.dg/c2y-imaginary-constants-9.c: New test.
* gcc.dg/c2y-imaginary-constants-10.c: New test.
* gcc.dg/c2y-imaginary-constants-11.c: New test.
* gcc.dg/c2y-imaginary-constants-12.c: New test.
Diffstat (limited to 'libcpp/expr.cc')
-rw-r--r-- | libcpp/expr.cc | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/libcpp/expr.cc b/libcpp/expr.cc index 53980f4..bbf21b8 100644 --- a/libcpp/expr.cc +++ b/libcpp/expr.cc @@ -911,8 +911,25 @@ cpp_classify_number (cpp_reader *pfile, const cpp_token *token, syntax_ok: if (result & CPP_N_IMAGINARY) - cpp_pedwarning_with_line (pfile, CPP_W_PEDANTIC, virtual_location, 0, - "imaginary constants are a GCC extension"); + { + if (CPP_OPTION (pfile, cplusplus) || (result & CPP_N_FLOATING) == 0) + cpp_pedwarning_with_line (pfile, CPP_W_PEDANTIC, virtual_location, 0, + "imaginary constants are a GCC extension"); + else + { + bool warned = false; + if (!CPP_OPTION (pfile, imaginary_constants) && CPP_PEDANTIC (pfile)) + warned + = cpp_pedwarning_with_line (pfile, CPP_W_PEDANTIC, + virtual_location, 0, + "imaginary constants are a C2Y " + "feature or GCC extension"); + if (!warned && CPP_OPTION (pfile, cpp_warn_c23_c2y_compat) > 0) + cpp_warning_with_line (pfile, CPP_W_C23_C2Y_COMPAT, + virtual_location, 0, + "imaginary constants are a C2Y feature"); + } + } if (radix == 2) { bool warned = false; |