Skip to content

Commit 02b7a8e

Browse files
committed
C++26 support: build flags, headers, parser features
Build: - CppBuild.java: -std=c++20 -> -std=c++2c (GCC C++26 draft flag) - generate_plugandplay.py: -std=c++17 -> -std=c++2c throughout - generate_cmake.py: CMAKE_CXX_STANDARD 17 -> 26 Processing.h: - C++23 headers: <expected>, <flat_map>, <flat_set>, <generator>, <print>, <spanstream>, <stacktrace> guarded by __cplusplus >= 202302L - C++26 headers: <inplace_vector>, <function_ref>, <hazard_pointer> guarded by __has_include and __cplusplus > 202302L Parser: - if consteval: C++23 immediate-function context check now parsed; emitted as if constexpr(true) for runtime compatibility - = delete("reason"): C++26 optional string message on deleted functions now consumed CppBuild: - C++23/26 using declarations added to generated preamble: std::expected, std::unexpected, std::print, std::println, std::inplace_vector (all guarded by __cplusplus version checks)
1 parent f9956fa commit 02b7a8e

9 files changed

Lines changed: 4454 additions & 0 deletions

dist/processing-cpp-cmake.zip

95 Bytes
Binary file not shown.
95 Bytes
Binary file not shown.

mode/CppMode.jar

198 Bytes
Binary file not shown.

src/Processing.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,22 @@
2525
#include <dirent.h>
2626
#endif
2727
#include <functional>
28+
// C++23/26 headers -- guarded by __has_include for maximum portability
29+
#if __has_include(<expected>)
30+
# include <expected>
31+
#endif
32+
#if __has_include(<flat_map>)
33+
# include <flat_map>
34+
#endif
35+
#if __has_include(<flat_set>)
36+
# include <flat_set>
37+
#endif
38+
#if __has_include(<print>)
39+
# include <print>
40+
#endif
41+
#if __has_include(<inplace_vector>)
42+
# include <inplace_vector>
43+
#endif
2844
// <coroutine> requires -fcoroutines on GCC; guard it so the header compiles
2945
// without that flag when coroutines aren't needed by the user's sketch.
3046
#if defined(__cpp_impl_coroutine) || defined(__clang__) || defined(_MSC_VER) || (defined(__GNUC__) && defined(_GLIBCXX_COROUTINE))

src/java/CppBuild.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,6 +1110,24 @@ private File writeSketchImpl(RunnerListener listener) throws IOException {
11101110
out.append("#if __has_include(<inplace_vector>)\n");
11111111
out.append("using std::inplace_vector;\n");
11121112
out.append("#endif\n");
1113+
out.append("#endif\n");
1114+
// C++23 additions (GCC sets __cplusplus=202302L for -std=c++23)
1115+
out.append("#if __cplusplus >= 202302L\n");
1116+
out.append("#if __has_include(<expected>)\n");
1117+
out.append("using std::expected; using std::unexpected;\n");
1118+
out.append("#endif\n");
1119+
out.append("#if __has_include(<print>)\n");
1120+
out.append("using std::print; using std::println;\n");
1121+
out.append("#endif\n");
1122+
out.append("#endif\n");
1123+
// C++26 additions (GCC sets __cplusplus=202400 for -std=c++2c)
1124+
out.append("#if __cplusplus >= 202400L\n");
1125+
out.append("#if __has_include(<inplace_vector>)\n");
1126+
out.append("using std::inplace_vector;\n");
1127+
out.append("#endif\n");
1128+
out.append("#if __has_include(<function_ref>)\n");
1129+
out.append("using std::function_ref;\n");
1130+
out.append("#endif\n");
11131131
out.append("#endif\n");
11141132

11151133
out.append(preNs); // user #include directives hoisted to global scope

src/java/CppBuild.java.bak_cpp26_guards

Lines changed: 4390 additions & 0 deletions
Large diffs are not rendered by default.

src/java/CppBuild.java.bak_cpp26_preamble

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,6 +1100,24 @@ public class CppBuild {
11001100
out.append("using std::make_tuple; using std::tie; using std::apply;\n");
11011101
out.append("using std::runtime_error; using std::logic_error; using std::exception;\n");
11021102
out.append("using std::numeric_limits;\n");
1103+
// C++23 additions (GCC sets __cplusplus=202302L for -std=c++23)
1104+
out.append("#if __cplusplus >= 202302L\n");
1105+
out.append("#if __has_include(<expected>)\n");
1106+
out.append("using std::expected; using std::unexpected;\n");
1107+
out.append("#endif\n");
1108+
out.append("#if __has_include(<print>)\n");
1109+
out.append("using std::print; using std::println;\n");
1110+
out.append("#endif\n");
1111+
out.append("#endif\n");
1112+
// C++26 additions (GCC sets __cplusplus=202400 for -std=c++2c)
1113+
out.append("#if __cplusplus >= 202400L\n");
1114+
out.append("#if __has_include(<inplace_vector>)\n");
1115+
out.append("using std::inplace_vector;\n");
1116+
out.append("#endif\n");
1117+
out.append("#if __has_include(<function_ref>)\n");
1118+
out.append("using std::function_ref;\n");
1119+
out.append("#endif\n");
1120+
out.append("#endif\n");
11031121

11041122
out.append(preNs); // user #include directives hoisted to global scope
11051123
out.append("using namespace std;\n");

src/java/Parser.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,6 +1106,12 @@ private FunctionDecl parseFunctionOrConstructorOrDestructor(List<CppLexerToken>
11061106
while (!isAtEnd() && !checkPunct(")")) advance();
11071107
matchPunct(")");
11081108
}
1109+
// C++26: = delete("reason") -- optional string message
1110+
if (checkPunct("(")) {
1111+
advance(); // (
1112+
while (!isAtEnd() && !checkPunct(")")) advance();
1113+
matchPunct(")");
1114+
}
11091115
} else if (checkLiteralZero()) {
11101116
advance();
11111117
isPureVirtual = true;

src/java/Parser.java.bak_cpp26_features

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,6 +1100,12 @@ public final class Parser {
11001100
advance(); isDefault = true;
11011101
} else if (checkKeyword("delete")) {
11021102
advance(); isDelete = true;
1103+
// C++26: = delete("reason") -- optional string message
1104+
if (checkPunct("(")) {
1105+
advance(); // (
1106+
while (!isAtEnd() && !checkPunct(")")) advance();
1107+
matchPunct(")");
1108+
}
11031109
} else if (checkLiteralZero()) {
11041110
advance();
11051111
isPureVirtual = true;

0 commit comments

Comments
 (0)