diff --git a/cms/db/contest.py b/cms/db/contest.py index 7543c58d6..2789e952b 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 000000000..3d70ce27f --- /dev/null +++ b/cms/grading/languages/cpp20_gpp.py @@ -0,0 +1,63 @@ +#!/usr/bin/env python3 + +# Contest Management System - http://cms-dev.github.io/ +# Copyright © 2024 Filippo Casarin +# +# 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 2cf440d4a..37947d39e 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 000000000..657724821 --- /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; +} diff --git a/setup.py b/setup.py index 8ba0d4cc9..9761864d6 100755 --- a/setup.py +++ b/setup.py @@ -185,6 +185,7 @@ def run(self): "C++11 / g++=cms.grading.languages.cpp11_gpp:Cpp11Gpp", "C++14 / g++=cms.grading.languages.cpp14_gpp:Cpp14Gpp", "C++17 / g++=cms.grading.languages.cpp17_gpp:Cpp17Gpp", + "C++20 / g++=cms.grading.languages.cpp20_gpp:Cpp20Gpp", "C11 / gcc=cms.grading.languages.c11_gcc:C11Gcc", "C# / Mono=cms.grading.languages.csharp_mono:CSharpMono", "Haskell / ghc=cms.grading.languages.haskell_ghc:HaskellGhc",