Skip to content

Commit eb7bc8f

Browse files
Virv12wil93
authored andcommitted
Support for c++20
1 parent 40c0ef4 commit eb7bc8f

File tree

5 files changed

+79
-4
lines changed

5 files changed

+79
-4
lines changed

cms/db/contest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class Contest(Base):
7979
languages = Column(
8080
ARRAY(String),
8181
nullable=False,
82-
default=["C11 / gcc", "C++17 / g++", "Pascal / fpc"])
82+
default=["C11 / gcc", "C++20 / g++", "Pascal / fpc"])
8383

8484
# Whether contestants allowed to download their submissions.
8585
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 <[email protected]>
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"
@@ -52,14 +53,14 @@
5253
LANG_RUST = "Rust"
5354
LANG_C_SHARP = "C# / Mono"
5455
ALL_LANGUAGES = (
55-
LANG_CPP, LANG_CPP14, LANG_CPP17, LANG_C, LANG_HS, LANG_JAVA, LANG_PASCAL,
56+
LANG_CPP, LANG_CPP14, LANG_CPP17, LANG_CPP20, LANG_C, LANG_HS, LANG_JAVA, LANG_PASCAL,
5657
LANG_PHP, LANG_PYTHON3, LANG_RUST, LANG_C_SHARP
5758
)
5859
NON_INTERPRETED_LANGUAGES = (
59-
LANG_C, LANG_CPP, LANG_CPP14, LANG_CPP17, LANG_PASCAL
60+
LANG_C, LANG_CPP, LANG_CPP14, LANG_CPP17, LANG_CPP20, LANG_PASCAL
6061
)
6162
COMPILED_LANGUAGES = (
62-
LANG_C, LANG_CPP, LANG_CPP14, LANG_CPP17, LANG_PASCAL, LANG_JAVA,
63+
LANG_C, LANG_CPP, LANG_CPP14, LANG_CPP17, LANG_CPP20, LANG_PASCAL, LANG_JAVA,
6364
LANG_PYTHON3, LANG_HS, LANG_RUST, LANG_C_SHARP
6465
)
6566

@@ -72,6 +73,7 @@
7273
alt_filenames={
7374
LANG_CPP14: ['correct-stdio-cxx14.%l'],
7475
LANG_CPP17: ['correct-stdio-cxx17.%l'],
76+
LANG_CPP20: ['correct-stdio-cxx20.%l'],
7577
},
7678
languages=ALL_LANGUAGES,
7779
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
@@ -185,6 +185,7 @@ def run(self):
185185
"C++11 / g++=cms.grading.languages.cpp11_gpp:Cpp11Gpp",
186186
"C++14 / g++=cms.grading.languages.cpp14_gpp:Cpp14Gpp",
187187
"C++17 / g++=cms.grading.languages.cpp17_gpp:Cpp17Gpp",
188+
"C++20 / g++=cms.grading.languages.cpp20_gpp:Cpp20Gpp",
188189
"C11 / gcc=cms.grading.languages.c11_gcc:C11Gcc",
189190
"C# / Mono=cms.grading.languages.csharp_mono:CSharpMono",
190191
"Haskell / ghc=cms.grading.languages.haskell_ghc:HaskellGhc",

0 commit comments

Comments
 (0)