Skip to content

Commit f806d1e

Browse files
authored
Merge pull request #8673 from tautschnig/bugfixes/8617-attributes-c23
Support C17, C23 standards with goto-cc
2 parents e88ed5f + fbb9502 commit f806d1e

File tree

4 files changed

+41
-1
lines changed

4 files changed

+41
-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=c2x
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
--
7+
^warning: ignoring
8+
^CONVERSION ERROR$

src/ansi-c/scanner.l

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -899,8 +899,18 @@ 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+
"[[" { // C23 attributes (also C++11 and later, but for C++ we
903+
// handle them directly in the parser); GCC >= 11, Clang
904+
// >= 17, and Visual Studio >= 2022 support these
905+
// irrespective of the language standard selected on the
906+
// command-line.
907+
if(PARSER.c23 ||
908+
PARSER.mode==configt::ansi_ct::flavourt::GCC ||
909+
PARSER.mode==configt::ansi_ct::flavourt::CLANG ||
910+
PARSER.mode==configt::ansi_ct::flavourt::VISUAL_STUDIO)
911+
{
903912
BEGIN(STD_ANNOTATION);
913+
}
904914
else
905915
{
906916
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)