Skip to content

Commit 8aed51f

Browse files
Virv12vytisb
authored andcommitted
Add support for c++20 language (cms-dev#1275)
1 parent 49067e4 commit 8aed51f

5 files changed

Lines changed: 79 additions & 4 deletions

File tree

cms/db/contest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class Contest(Base):
8787
languages = Column(
8888
ARRAY(String),
8989
nullable=False,
90-
default=["C11 / gcc", "C++17 / g++", "Pascal / fpc"])
90+
default=["C11 / gcc", "C++20 / g++", "Pascal / fpc"])
9191

9292
# Whether contestants allowed to download their submissions.
9393
submissions_download_allowed = Column(

cms/grading/languages/cpp20_gpp.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/usr/bin/env python3
2+
3+
# Contest Management System - http://cms-dev.github.io/
4+
# Copyright © 2024 Filippo Casarin <casarin.filippo17@gmail.com>
5+
#
6+
# This program is free software: you can redistribute it and/or modify
7+
# it under the terms of the GNU Affero General Public License as
8+
# published by the Free Software Foundation, either version 3 of the
9+
# License, or (at your option) any later version.
10+
#
11+
# This program is distributed in the hope that it will be useful,
12+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
# GNU Affero General Public License for more details.
15+
#
16+
# You should have received a copy of the GNU Affero General Public License
17+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
18+
19+
"""C++20 programming language definition."""
20+
21+
from cms.grading import CompiledLanguage
22+
23+
24+
__all__ = ["Cpp20Gpp"]
25+
26+
27+
class Cpp20Gpp(CompiledLanguage):
28+
"""This defines the C++ programming language, compiled with g++ (the
29+
version available on the system) using the C++20 standard.
30+
31+
"""
32+
33+
@property
34+
def name(self):
35+
"""See Language.name."""
36+
return "C++20 / g++"
37+
38+
@property
39+
def source_extensions(self):
40+
"""See Language.source_extensions."""
41+
return [".cpp", ".cc", ".cxx", ".c++", ".C"]
42+
43+
@property
44+
def header_extensions(self):
45+
"""See Language.header_extensions."""
46+
return [".h"]
47+
48+
@property
49+
def object_extensions(self):
50+
"""See Language.object_extensions."""
51+
return [".o"]
52+
53+
def get_compilation_commands(self,
54+
source_filenames, executable_filename,
55+
for_evaluation=True):
56+
"""See Language.get_compilation_commands."""
57+
command = ["/usr/bin/g++"]
58+
if for_evaluation:
59+
command += ["-DEVAL"]
60+
command += ["-std=gnu++20", "-O2", "-pipe", "-static",
61+
"-s", "-o", executable_filename]
62+
command += source_filenames
63+
return [command]

cmstestsuite/Tests.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
LANG_CPP = "C++11 / g++"
4444
LANG_CPP14 = "C++14 / g++"
4545
LANG_CPP17 = "C++17 / g++"
46+
LANG_CPP20 = "C++20 / g++"
4647
LANG_C = "C11 / gcc"
4748
LANG_HS = "Haskell / ghc"
4849
LANG_JAVA = "Java / JDK"
@@ -53,14 +54,14 @@
5354
LANG_RUST = "Rust"
5455
LANG_C_SHARP = "C# / Mono"
5556
ALL_LANGUAGES = (
56-
LANG_CPP, LANG_CPP14, LANG_CPP17, LANG_C, LANG_HS, LANG_JAVA, LANG_PASCAL,
57+
LANG_CPP, LANG_CPP14, LANG_CPP17, LANG_CPP20, LANG_C, LANG_HS, LANG_JAVA, LANG_PASCAL,
5758
LANG_PHP, LANG_PYTHON, LANG_PYTHON3, LANG_RUST, LANG_C_SHARP
5859
)
5960
NON_INTERPRETED_LANGUAGES = (
60-
LANG_C, LANG_CPP, LANG_CPP14, LANG_CPP17, LANG_PASCAL
61+
LANG_C, LANG_CPP, LANG_CPP14, LANG_CPP17, LANG_CPP20, LANG_PASCAL
6162
)
6263
COMPILED_LANGUAGES = (
63-
LANG_C, LANG_CPP, LANG_CPP14, LANG_CPP17, LANG_PASCAL, LANG_JAVA,
64+
LANG_C, LANG_CPP, LANG_CPP14, LANG_CPP17, LANG_CPP20, LANG_PASCAL, LANG_JAVA,
6465
LANG_PYTHON, LANG_PYTHON3, LANG_HS, LANG_RUST, LANG_C_SHARP
6566
)
6667

@@ -73,6 +74,7 @@
7374
alt_filenames={
7475
LANG_CPP14: ['correct-stdio-cxx14.%l'],
7576
LANG_CPP17: ['correct-stdio-cxx17.%l'],
77+
LANG_CPP20: ['correct-stdio-cxx20.%l'],
7678
},
7779
languages=ALL_LANGUAGES,
7880
checks=[CheckOverallScore(100, 100)]),
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#include <iostream>
2+
3+
static_assert(__cplusplus == 202002L, "C++20 expected");
4+
5+
int main() {
6+
int n;
7+
std::cin >> n;
8+
std::cout << "correct " << n << std::endl;
9+
}

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ def run(self):
191191
"C++11 / g++=cms.grading.languages.cpp11_gpp:Cpp11Gpp",
192192
"C++14 / g++=cms.grading.languages.cpp14_gpp:Cpp14Gpp",
193193
"C++17 / g++=cms.grading.languages.cpp17_gpp:Cpp17Gpp",
194+
"C++20 / g++=cms.grading.languages.cpp20_gpp:Cpp20Gpp",
194195
"C11 / gcc=cms.grading.languages.c11_gcc:C11Gcc",
195196
"C# / Mono=cms.grading.languages.csharp_mono:CSharpMono",
196197
"Haskell / ghc=cms.grading.languages.haskell_ghc:HaskellGhc",

0 commit comments

Comments
 (0)