From b0cdf95213b361ece722107d3e20ce22ccdd6ed1 Mon Sep 17 00:00:00 2001 From: Austin Eng Date: Tue, 15 Oct 2019 07:30:35 +0000 Subject: [PATCH] Fix compilation with MSVC of volatile assignment operator Bug: dawn:230 Change-Id: Ie6e4ddf52132a6980d86c9d80524385b51d9d0d6 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/12200 Commit-Queue: Corentin Wallez Reviewed-by: Kai Ninomiya Reviewed-by: Corentin Wallez --- generator/templates/dawn_wire/WireCmd.cpp | 8 ++++++-- generator/templates/dawn_wire/WireCmd.h | 11 +++++++++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/generator/templates/dawn_wire/WireCmd.cpp b/generator/templates/dawn_wire/WireCmd.cpp index ab28047cb7..731751f502 100644 --- a/generator/templates/dawn_wire/WireCmd.cpp +++ b/generator/templates/dawn_wire/WireCmd.cpp @@ -369,8 +369,12 @@ namespace dawn_wire { ObjectHandle::ObjectHandle() = default; ObjectHandle::ObjectHandle(ObjectId id, ObjectSerial serial) : id(id), serial(serial) {} ObjectHandle::ObjectHandle(const volatile ObjectHandle& rhs) : id(rhs.id), serial(rhs.serial) {} - ObjectHandle& ObjectHandle::operator=(const ObjectHandle& rhs) = default; - ObjectHandle& ObjectHandle::operator=(const volatile ObjectHandle& rhs) { + ObjectHandle& ObjectHandle::AssignFrom(const ObjectHandle& rhs) { + id = rhs.id; + serial = rhs.serial; + return *this; + } + ObjectHandle& ObjectHandle::AssignFrom(const volatile ObjectHandle& rhs) { id = rhs.id; serial = rhs.serial; return *this; diff --git a/generator/templates/dawn_wire/WireCmd.h b/generator/templates/dawn_wire/WireCmd.h index 83490e6772..7d80b03432 100644 --- a/generator/templates/dawn_wire/WireCmd.h +++ b/generator/templates/dawn_wire/WireCmd.h @@ -28,8 +28,15 @@ namespace dawn_wire { ObjectHandle(); ObjectHandle(ObjectId id, ObjectSerial serial); ObjectHandle(const volatile ObjectHandle& rhs); - ObjectHandle& operator=(const ObjectHandle& rhs); - ObjectHandle& operator=(const volatile ObjectHandle& rhs); + + // MSVC has a bug where it thinks the volatile copy assignment is a duplicate. + // Workaround this by forwarding to a different function AssignFrom. + template + ObjectHandle& operator=(const T& rhs) { + return AssignFrom(rhs); + } + ObjectHandle& AssignFrom(const ObjectHandle& rhs); + ObjectHandle& AssignFrom(const volatile ObjectHandle& rhs); }; enum class DeserializeResult {