Skip to content

Support C17, C23 standards with goto-cc #8673

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions regression/ansi-c/c23_attributes1/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
enum [[nodiscard]] error_t
{
A,
};

int main()
{
}
8 changes: 8 additions & 0 deletions regression/ansi-c/c23_attributes1/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CORE
main.c
-std=c2x
^EXIT=0$
^SIGNAL=0$
--
^warning: ignoring
^CONVERSION ERROR$
12 changes: 11 additions & 1 deletion src/ansi-c/scanner.l
Original file line number Diff line number Diff line change
Expand Up @@ -899,8 +899,18 @@
"__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

Check warning on line 902 in src/ansi-c/scanner.l

View check run for this annotation

Codecov / codecov/patch

src/ansi-c/scanner.l#L902

Added line #L902 was not covered by tests
// 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 ||

Check warning on line 909 in src/ansi-c/scanner.l

View check run for this annotation

Codecov / codecov/patch

src/ansi-c/scanner.l#L908-L909

Added lines #L908 - L909 were not covered by tests
PARSER.mode==configt::ansi_ct::flavourt::VISUAL_STUDIO)
{
BEGIN(STD_ANNOTATION);
}
else
{
yyless(1); // puts one [ back into stream
Expand Down
14 changes: 14 additions & 0 deletions src/goto-cc/gcc_mode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,20 @@
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();

Check warning on line 655 in src/goto-cc/gcc_mode.cpp

View check run for this annotation

Codecov / codecov/patch

src/goto-cc/gcc_mode.cpp#L655

Added line #L655 was not covered by tests
}

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" ||
Expand Down
Loading