Skip to content

Commit f805f13

Browse files
committed
Reject fractional integers in C++
1 parent 7cc8d8a commit f805f13

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

packages/quicktype-core/src/language/CPlusPlus/CPlusPlusRenderer.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1505,6 +1505,19 @@ export class CPlusPlusRenderer extends ConvenienceRenderer {
15051505
return;
15061506
}
15071507

1508+
if (propType.kind === "integer") {
1509+
const key = this.NarrowString.createStringLiteral([
1510+
stringEscape(json),
1511+
]);
1512+
this.emitLine(
1513+
"if (j.find(",
1514+
key,
1515+
") != j.end() && !j.at(",
1516+
key,
1517+
').is_number_integer()) throw std::runtime_error("Expected integer");',
1518+
);
1519+
}
1520+
15081521
if (p.isOptional || propType instanceof UnionType) {
15091522
const [nullOrOptional, typeSet] = ((): [
15101523
boolean,

test/languages.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -719,6 +719,7 @@ export const CPlusPlusLanguage: Language = {
719719
"enum",
720720
"union",
721721
"no-defaults",
722+
"integer",
722723
],
723724
output: "quicktype.hpp",
724725
topLevel: "TopLevel",

0 commit comments

Comments
 (0)