From e5bf3842170816c319fe86dc98b9d52d91f41a3f Mon Sep 17 00:00:00 2001 From: Filippo Casarin Date: Sun, 17 Nov 2024 00:42:59 +0100 Subject: [PATCH] Support for c++20 --- cms/db/contest.py | 2 +- cms/grading/languages/cpp20_gpp.py | 64 +++++++++++++++++++++++ cmstestsuite/Tests.py | 8 +-- cmstestsuite/code/correct-stdio-cxx20.cpp | 9 ++++ 4 files changed, 79 insertions(+), 4 deletions(-) create mode 100644 cms/grading/languages/cpp20_gpp.py create mode 100644 cmstestsuite/code/correct-stdio-cxx20.cpp diff --git a/cms/db/contest.py b/cms/db/contest.py index 7543c58d68..2789e952bd 100644 --- a/cms/db/contest.py +++ b/cms/db/contest.py @@ -79,7 +79,7 @@ class Contest(Base): languages = Column( ARRAY(String), nullable=False, - default=["C11 / gcc", "C++17 / g++", "Pascal / fpc"]) + default=["C11 / gcc", "C++20 / g++", "Pascal / fpc"]) # Whether contestants allowed to download their submissions. submissions_download_allowed = Column( diff --git a/cms/grading/languages/cpp20_gpp.py b/cms/grading/languages/cpp20_gpp.py new file mode 100644 index 0000000000..f0c621ee47 --- /dev/null +++ b/cms/grading/languages/cpp20_gpp.py @@ -0,0 +1,64 @@ +#!/usr/bin/env python3 + +# Contest Management System - http://cms-dev.github.io/ +# Copyright © 2016 Stefano Maggiolo +# Copyright © 2020 Andrey Vihrov +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +"""C++20 programming language definition.""" + +from cms.grading import CompiledLanguage + + +__all__ = ["Cpp20Gpp"] + + +class Cpp20Gpp(CompiledLanguage): + """This defines the C++ programming language, compiled with g++ (the + version available on the system) using the C++20 standard. + + """ + + @property + def name(self): + """See Language.name.""" + return "C++20 / g++" + + @property + def source_extensions(self): + """See Language.source_extensions.""" + return [".cpp", ".cc", ".cxx", ".c++", ".C"] + + @property + def header_extensions(self): + """See Language.header_extensions.""" + return [".h"] + + @property + def object_extensions(self): + """See Language.object_extensions.""" + return [".o"] + + def get_compilation_commands(self, + source_filenames, executable_filename, + for_evaluation=True): + """See Language.get_compilation_commands.""" + command = ["/usr/bin/g++"] + if for_evaluation: + command += ["-DEVAL"] + command += ["-std=gnu++20", "-O2", "-pipe", "-static", + "-s", "-o", executable_filename] + command += source_filenames + return [command] diff --git a/cmstestsuite/Tests.py b/cmstestsuite/Tests.py index 2cf440d4af..37947d39ef 100644 --- a/cmstestsuite/Tests.py +++ b/cmstestsuite/Tests.py @@ -43,6 +43,7 @@ LANG_CPP = "C++11 / g++" LANG_CPP14 = "C++14 / g++" LANG_CPP17 = "C++17 / g++" +LANG_CPP20 = "C++20 / g++" LANG_C = "C11 / gcc" LANG_HS = "Haskell / ghc" LANG_JAVA = "Java / JDK" @@ -52,14 +53,14 @@ LANG_RUST = "Rust" LANG_C_SHARP = "C# / Mono" ALL_LANGUAGES = ( - LANG_CPP, LANG_CPP14, LANG_CPP17, LANG_C, LANG_HS, LANG_JAVA, LANG_PASCAL, + LANG_CPP, LANG_CPP14, LANG_CPP17, LANG_CPP20, LANG_C, LANG_HS, LANG_JAVA, LANG_PASCAL, LANG_PHP, LANG_PYTHON3, LANG_RUST, LANG_C_SHARP ) NON_INTERPRETED_LANGUAGES = ( - LANG_C, LANG_CPP, LANG_CPP14, LANG_CPP17, LANG_PASCAL + LANG_C, LANG_CPP, LANG_CPP14, LANG_CPP17, LANG_CPP20, LANG_PASCAL ) COMPILED_LANGUAGES = ( - LANG_C, LANG_CPP, LANG_CPP14, LANG_CPP17, LANG_PASCAL, LANG_JAVA, + LANG_C, LANG_CPP, LANG_CPP14, LANG_CPP17, LANG_CPP20, LANG_PASCAL, LANG_JAVA, LANG_PYTHON3, LANG_HS, LANG_RUST, LANG_C_SHARP ) @@ -72,6 +73,7 @@ alt_filenames={ LANG_CPP14: ['correct-stdio-cxx14.%l'], LANG_CPP17: ['correct-stdio-cxx17.%l'], + LANG_CPP20: ['correct-stdio-cxx20.%l'], }, languages=ALL_LANGUAGES, checks=[CheckOverallScore(100, 100)]), diff --git a/cmstestsuite/code/correct-stdio-cxx20.cpp b/cmstestsuite/code/correct-stdio-cxx20.cpp new file mode 100644 index 0000000000..6577248216 --- /dev/null +++ b/cmstestsuite/code/correct-stdio-cxx20.cpp @@ -0,0 +1,9 @@ +#include + +static_assert(__cplusplus == 202002L, "C++20 expected"); + +int main() { + int n; + std::cin >> n; + std::cout << "correct " << n << std::endl; +}