Skip to content

Commit cc5854b

Browse files
committed
Prevent SimpleGeneratorRef from being used as the copy constructor.
1 parent e14f2bc commit cc5854b

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

include/swift/Basic/Generators.h

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,10 @@ class ArrayRefGenerator {
146146
}
147147
};
148148

149+
namespace generator_details {
150+
template <class T> struct is_simple_generator_ref;
151+
}
152+
149153
/// An abstracting reference to an existing generator.
150154
///
151155
/// The implementation of this type holds the reference to the existing
@@ -182,7 +186,8 @@ class SimpleGeneratorRef {
182186
constexpr SimpleGeneratorRef() : vtable(nullptr), pointer(nullptr) {}
183187

184188
template <class G>
185-
constexpr SimpleGeneratorRef(G &generator)
189+
constexpr SimpleGeneratorRef(G &generator,
190+
typename std::enable_if<!generator_details::is_simple_generator_ref<G>::value, bool>::type = false)
186191
: vtable(&VTableImpl<G>::vtable), pointer(&generator) {}
187192

188193
/// Test whether this generator ref was initialized with a
@@ -212,6 +217,19 @@ class SimpleGeneratorRef {
212217
}
213218
};
214219

220+
namespace generator_details {
221+
222+
template <class T>
223+
struct is_simple_generator_ref<SimpleGeneratorRef<T>> {
224+
static constexpr bool value = true;
225+
};
226+
template <class T>
227+
struct is_simple_generator_ref {
228+
static constexpr bool value = false;
229+
};
230+
231+
}
232+
215233
} // end namespace swift
216234

217235
#endif

0 commit comments

Comments
 (0)