diff --git a/regression/ansi-c/c23_attributes1/main.c b/regression/ansi-c/c23_attributes1/main.c new file mode 100644 index 00000000000..b1a2f40d0f8 --- /dev/null +++ b/regression/ansi-c/c23_attributes1/main.c @@ -0,0 +1,8 @@ +enum [[nodiscard]] error_t +{ + A, +}; + +int main() +{ +} diff --git a/regression/ansi-c/c23_attributes1/test.desc b/regression/ansi-c/c23_attributes1/test.desc new file mode 100644 index 00000000000..969ea06f4b5 --- /dev/null +++ b/regression/ansi-c/c23_attributes1/test.desc @@ -0,0 +1,8 @@ +CORE +main.c +-std=c2x +^EXIT=0$ +^SIGNAL=0$ +-- +^warning: ignoring +^CONVERSION ERROR$ diff --git a/src/ansi-c/scanner.l b/src/ansi-c/scanner.l index 50c86fb90a7..f9c7b8674ce 100644 --- a/src/ansi-c/scanner.l +++ b/src/ansi-c/scanner.l @@ -899,8 +899,18 @@ enable_or_disable ("enable"|"disable") "__if_not_exists" { return MSC_cpp_keyword(TOK_MSC_IF_NOT_EXISTS); } "__underlying_type" { return conditional_keyword(PARSER.cpp98, TOK_UNDERLYING_TYPE); } -"[[" { if(PARSER.c23) +"[[" { // C23 attributes (also C++11 and later, but for C++ we + // handle them directly in the parser); GCC >= 11, Clang + // >= 17, and Visual Studio >= 2022 support these + // irrespective of the language standard selected on the + // command-line. + if(PARSER.c23 || + PARSER.mode==configt::ansi_ct::flavourt::GCC || + PARSER.mode==configt::ansi_ct::flavourt::CLANG || + PARSER.mode==configt::ansi_ct::flavourt::VISUAL_STUDIO) + { BEGIN(STD_ANNOTATION); + } else { yyless(1); // puts one [ back into stream diff --git a/src/goto-cc/gcc_mode.cpp b/src/goto-cc/gcc_mode.cpp index a3ffa2d5e16..d48c4234abb 100644 --- a/src/goto-cc/gcc_mode.cpp +++ b/src/goto-cc/gcc_mode.cpp @@ -648,6 +648,20 @@ int gcc_modet::doit() std_string=="gnu1x" || std_string=="c1x") config.ansi_c.set_c11(); + if( + std_string == "gnu17" || std_string == "c17" || std_string == "gnu18" || + std_string == "c18") + { + config.ansi_c.set_c17(); + } + + if( + std_string == "gnu2x" || std_string == "c2x" || std_string == "gnu23" || + std_string == "c23") + { + config.ansi_c.set_c23(); + } + if(std_string=="c++11" || std_string=="c++1x" || std_string=="gnu++11" || std_string=="gnu++1x" || std_string=="c++1y" ||