Skip to content

Commit 59cd36a

Browse files
committed
fix C++17 build
1 parent 7cd7516 commit 59cd36a

File tree

1 file changed

+25
-21
lines changed

1 file changed

+25
-21
lines changed

src/tools/wasm-fuzz-lattices.cpp

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <optional>
1818
#include <random>
1919
#include <string>
20+
#include <type_traits>
2021
#include <variant>
2122

2223
#include "analysis/lattice.h"
@@ -170,14 +171,14 @@ RandomFullLattice::RandomFullLattice(Random& rand,
170171
uint32_t pick = maybePick ? *maybePick : rand.upTo(3);
171172
switch (pick) {
172173
case 0:
173-
lattice = std::make_unique<L>(Bool{});
174+
lattice = std::make_unique<L>(L{Bool{}});
174175
return;
175176
case 1:
176-
lattice = std::make_unique<L>(UInt32{});
177+
lattice = std::make_unique<L>(L{UInt32{}});
177178
return;
178179
case 2:
179180
lattice =
180-
std::make_unique<L>(Inverted{RandomFullLattice{rand, depth + 1}});
181+
std::make_unique<L>(L{Inverted{RandomFullLattice{rand, depth + 1}}});
181182
return;
182183
}
183184
WASM_UNREACHABLE("unexpected pick");
@@ -190,13 +191,13 @@ RandomLattice::RandomLattice(Random& rand, size_t depth) : rand(rand) {
190191
case 0:
191192
case 1:
192193
case 2:
193-
lattice = std::make_unique<L>(RandomFullLattice{rand, depth, pick});
194+
lattice = std::make_unique<L>(L{RandomFullLattice{rand, depth, pick}});
194195
return;
195196
case 3:
196-
lattice = std::make_unique<L>(Flat<uint32_t>{});
197+
lattice = std::make_unique<L>(L{Flat<uint32_t>{}});
197198
return;
198199
case 4:
199-
lattice = std::make_unique<L>(Lift{RandomLattice{rand, depth + 1}});
200+
lattice = std::make_unique<L>(L{Lift{RandomLattice{rand, depth + 1}}});
200201
return;
201202
}
202203
WASM_UNREACHABLE("unexpected pick");
@@ -670,15 +671,18 @@ RandomFullLattice::Element RandomFullLattice::getTop() const noexcept {
670671
*lattice);
671672
}
672673

674+
// TODO: use std::remove_cvref_t from C++20 instead.
675+
template<typename T> using bare = std::remove_cv_t<std::remove_reference_t<T>>;
676+
673677
LatticeComparison RandomFullLattice::compare(const Element& a,
674678
const Element& b) const noexcept {
675679
return std::visit(
676680
[](const auto& l,
677681
const auto& elemA,
678682
const auto& elemB) -> LatticeComparison {
679-
using ElemT = typename std::remove_cvref_t<decltype(l)>::Element;
680-
using A = std::remove_cvref_t<decltype(elemA)>;
681-
using B = std::remove_cvref_t<decltype(elemB)>;
683+
using ElemT = typename bare<decltype(l)>::Element;
684+
using A = bare<decltype(elemA)>;
685+
using B = bare<decltype(elemB)>;
682686
if constexpr (std::is_same_v<ElemT, A> && std::is_same_v<ElemT, B>) {
683687
return l.compare(elemA, elemB);
684688
}
@@ -692,9 +696,9 @@ LatticeComparison RandomFullLattice::compare(const Element& a,
692696
bool RandomFullLattice::join(Element& a, const Element& b) const noexcept {
693697
return std::visit(
694698
[](const auto& l, auto& elemA, const auto& elemB) -> bool {
695-
using ElemT = typename std::remove_cvref_t<decltype(l)>::Element;
696-
using A = std::remove_cvref_t<decltype(elemA)>;
697-
using B = std::remove_cvref_t<decltype(elemB)>;
699+
using ElemT = typename bare<decltype(l)>::Element;
700+
using A = bare<decltype(elemA)>;
701+
using B = bare<decltype(elemB)>;
698702
if constexpr (std::is_same_v<ElemT, A> && std::is_same_v<ElemT, B>) {
699703
return l.join(elemA, elemB);
700704
}
@@ -708,9 +712,9 @@ bool RandomFullLattice::join(Element& a, const Element& b) const noexcept {
708712
bool RandomFullLattice::meet(Element& a, const Element& b) const noexcept {
709713
return std::visit(
710714
[](const auto& l, auto& elemA, const auto& elemB) -> bool {
711-
using ElemT = typename std::remove_cvref_t<decltype(l)>::Element;
712-
using A = std::remove_cvref_t<decltype(elemA)>;
713-
using B = std::remove_cvref_t<decltype(elemB)>;
715+
using ElemT = typename bare<decltype(l)>::Element;
716+
using A = bare<decltype(elemA)>;
717+
using B = bare<decltype(elemB)>;
714718
if constexpr (std::is_same_v<ElemT, A> && std::is_same_v<ElemT, B>) {
715719
return l.meet(elemA, elemB);
716720
}
@@ -732,9 +736,9 @@ LatticeComparison RandomLattice::compare(const Element& a,
732736
[](const auto& l,
733737
const auto& elemA,
734738
const auto& elemB) -> LatticeComparison {
735-
using ElemT = typename std::remove_cvref_t<decltype(l)>::Element;
736-
using A = std::remove_cvref_t<decltype(elemA)>;
737-
using B = std::remove_cvref_t<decltype(elemB)>;
739+
using ElemT = typename bare<decltype(l)>::Element;
740+
using A = bare<decltype(elemA)>;
741+
using B = bare<decltype(elemB)>;
738742
if constexpr (std::is_same_v<ElemT, A> && std::is_same_v<ElemT, B>) {
739743
return l.compare(elemA, elemB);
740744
}
@@ -748,9 +752,9 @@ LatticeComparison RandomLattice::compare(const Element& a,
748752
bool RandomLattice::join(Element& a, const Element& b) const noexcept {
749753
return std::visit(
750754
[](const auto& l, auto& elemA, const auto& elemB) -> bool {
751-
using ElemT = typename std::remove_cvref_t<decltype(l)>::Element;
752-
using A = std::remove_cvref_t<decltype(elemA)>;
753-
using B = std::remove_cvref_t<decltype(elemB)>;
755+
using ElemT = typename bare<decltype(l)>::Element;
756+
using A = bare<decltype(elemA)>;
757+
using B = bare<decltype(elemB)>;
754758
if constexpr (std::is_same_v<ElemT, A> && std::is_same_v<ElemT, B>) {
755759
return l.join(elemA, elemB);
756760
}

0 commit comments

Comments
 (0)