Skip to content

Commit

Permalink
Add support for c++20 language (#1275)
Browse files Browse the repository at this point in the history
  • Loading branch information
Virv12 authored Nov 17, 2024
1 parent 40c0ef4 commit b12d0b1
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 4 deletions.
2 changes: 1 addition & 1 deletion cms/db/contest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
63 changes: 63 additions & 0 deletions cms/grading/languages/cpp20_gpp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/usr/bin/env python3

# Contest Management System - http://cms-dev.github.io/
# Copyright © 2024 Filippo Casarin <[email protected]>
#
# 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 <http://www.gnu.org/licenses/>.

"""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]
8 changes: 5 additions & 3 deletions cmstestsuite/Tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
)

Expand All @@ -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)]),
Expand Down
9 changes: 9 additions & 0 deletions cmstestsuite/code/correct-stdio-cxx20.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include <iostream>

static_assert(__cplusplus == 202002L, "C++20 expected");

int main() {
int n;
std::cin >> n;
std::cout << "correct " << n << std::endl;
}
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit b12d0b1

Please sign in to comment.