@@ -41,23 +41,20 @@ struct StringReferenceLike {
4141 std::string_view viewValue;
4242};
4343
44- struct ImplicitStringViewLike {
45- operator std::string_view () const { return value ; }
44+ struct ImplicitAndExplicitStringViewLike {
45+ operator std::string () const { return " unexpected-string-key " ; }
4646
47- std::string_view value;
48- };
47+ // Copy-initialization must ignore the explicit conversion below.
48+ // Direct-initialization would prefer it for a non-const lvalue.
49+ operator std::string_view () const & { return value; }
4950
50- struct ExplicitStringViewLike {
51- explicit operator std::string_view () const { return value; }
51+ explicit operator std::string_view () & {
52+ return " unexpected-explicit-string-view-key" ;
53+ }
5254
5355 std::string_view value;
5456};
5557
56- struct ImplicitAndExplicitStringViewLike : ImplicitStringViewLike,
57- ExplicitStringViewLike {
58- operator std::string () const { return " unexpected-string-key" ; }
59- };
60-
6158} // namespace
6259
6360Symbol CreateNewSymbolWithNoArgs (const Napi::CallbackInfo&) {
@@ -150,10 +147,7 @@ Symbol FetchSymbolFromGlobalRegistryWithStringReferenceKey(
150147Symbol FetchSymbolFromGlobalRegistryWithImplicitViewKey (
151148 const Napi::CallbackInfo& info) {
152149 std::string value = info[0 ].As <String>().Utf8Value ();
153- ImplicitAndExplicitStringViewLike key;
154- static_cast <ImplicitStringViewLike&>(key).value = value;
155- static_cast <ExplicitStringViewLike&>(key).value =
156- " unexpected-explicit-string-view-key" ;
150+ ImplicitAndExplicitStringViewLike key{value};
157151 return MaybeUnwrap (Symbol::For (info.Env (), key));
158152}
159153
0 commit comments