Skip to content

Commit 8230566

Browse files
committed
Support C17, C23 standards with goto-cc
We previously added the necessary language features in the C front end, but failed to permit selection of these standards in goto-cc. Also, GCC >= 11 and Clang >= 17 support C23-style attributes irrespective of the configured language standard. So let's accept these in our C front end whenever operating in GCC/Clang mode. Fixes: #8617
1 parent 48490fb commit 8230566

File tree

4 files changed

+35
-1
lines changed

4 files changed

+35
-1
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
enum [[nodiscard]] error_t
2+
{
3+
A,
4+
};
5+
6+
int main()
7+
{
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.c
3+
-std=c23
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
--
7+
^warning: ignoring
8+
^CONVERSION ERROR$

src/ansi-c/scanner.l

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -899,8 +899,12 @@ enable_or_disable ("enable"|"disable")
899899
"__if_not_exists" { return MSC_cpp_keyword(TOK_MSC_IF_NOT_EXISTS); }
900900
"__underlying_type" { return conditional_keyword(PARSER.cpp98, TOK_UNDERLYING_TYPE); }
901901

902-
"[[" { if(PARSER.c23)
902+
"[[" { if(PARSER.c23 ||
903+
PARSER.mode==configt::ansi_ct::flavourt::GCC ||
904+
PARSER.mode==configt::ansi_ct::flavourt::CLANG)
905+
{
903906
BEGIN(STD_ANNOTATION);
907+
}
904908
else
905909
{
906910
yyless(1); // puts one [ back into stream

src/goto-cc/gcc_mode.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,20 @@ int gcc_modet::doit()
648648
std_string=="gnu1x" || std_string=="c1x")
649649
config.ansi_c.set_c11();
650650

651+
if(
652+
std_string == "gnu17" || std_string == "c17" || std_string == "gnu18" ||
653+
std_string == "c18")
654+
{
655+
config.ansi_c.set_c17();
656+
}
657+
658+
if(
659+
std_string == "gnu2x" || std_string == "c2x" || std_string == "gnu23" ||
660+
std_string == "c23")
661+
{
662+
config.ansi_c.set_c23();
663+
}
664+
651665
if(std_string=="c++11" || std_string=="c++1x" ||
652666
std_string=="gnu++11" || std_string=="gnu++1x" ||
653667
std_string=="c++1y" ||

0 commit comments

Comments
 (0)