Fix remaining explicit-constructor warnings These are all explicit constructors and operators that clang-tidy can detect that cpplint can't. Make explicit where possible. Otherwise, constructors are explicit(false) and operators get a NOLINT. Audited that all of the newly-marked implicit conversions don't seem bugprone. Bug: 501491694 Change-Id: I3beaaede0292f284b25c4abdf3d6005d7d605e70 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/322596 Reviewed-by: dan sinclair <dsinclair@chromium.org> Commit-Queue: Kai Ninomiya <kainino@chromium.org>
diff --git a/generator/templates/dawn/wire/server/ServerBase.h b/generator/templates/dawn/wire/server/ServerBase.h index ed7d727..d895b3c 100644 --- a/generator/templates/dawn/wire/server/ServerBase.h +++ b/generator/templates/dawn/wire/server/ServerBase.h
@@ -44,7 +44,7 @@ class ServerBase : public ChunkedCommandHandler, public ObjectIdResolver { public: - ServerBase(const DawnProcTable& procs) : mProcs(std::make_shared<DawnProcTable>(procs)) {} + explicit ServerBase(const DawnProcTable& procs) : mProcs(std::make_shared<DawnProcTable>(procs)) {} ~ServerBase() override = default; Mutex::AutoLock GetGuard() { return Mutex::AutoLock(&mMutex); }
diff --git a/src/dawn/common/Atomic.h b/src/dawn/common/Atomic.h index de1a7f4..52e134c 100644 --- a/src/dawn/common/Atomic.h +++ b/src/dawn/common/Atomic.h
@@ -52,6 +52,7 @@ return *this; } + // NOLINTNEXTLINE(google-explicit-constructor) operator T() const { return mValue.load(LoadMemoryOrder); } T operator=(T value) {
diff --git a/src/dawn/common/RefBase.h b/src/dawn/common/RefBase.h index 5e48acb..549cdba 100644 --- a/src/dawn/common/RefBase.h +++ b/src/dawn/common/RefBase.h
@@ -95,7 +95,7 @@ // operators defined with `other` == RefBase<T, Traits>. template <typename U, typename UTraits> requires std::convertible_to<U, T> - RefBase(const RefBase<U, UTraits>& other) : mValue(other.mValue) { + explicit(false) RefBase(const RefBase<U, UTraits>& other) : mValue(other.mValue) { AddRef(other.mValue); } @@ -108,7 +108,7 @@ template <typename U, typename UTraits> requires std::convertible_to<U, T> - RefBase(RefBase<U, UTraits>&& other) { + explicit(false) RefBase(RefBase<U, UTraits>&& other) { mValue = other.Detach(); }
diff --git a/src/dawn/common/Result.h b/src/dawn/common/Result.h index e8f2557..e311064 100644 --- a/src/dawn/common/Result.h +++ b/src/dawn/common/Result.h
@@ -77,7 +77,7 @@ class [[nodiscard]] Result<void, E> { public: Result(); - Result(std::unique_ptr<E> error); + explicit(false) Result(std::unique_ptr<E> error); Result(Result<void, E>&& other); Result<void, E>& operator=(Result<void, E>&& other); @@ -132,13 +132,13 @@ static_assert(alignof_if_defined_else_default<E, 4> >= 4, "Result<T*, E*> reserves two bits for tagging pointers"); - Result(T* success); - Result(std::unique_ptr<E> error); + explicit(false) Result(T* success); + explicit(false) Result(std::unique_ptr<E> error); // Support returning a Result<T*, E*> from a Result<TChild*, E*> template <typename TChild> requires std::same_as<TChild, T> || std::derived_from<TChild, T> - Result(Result<TChild*, E>&& other); + explicit(false) Result(Result<TChild*, E>&& other); template <typename TChild> requires std::same_as<TChild, T> || std::derived_from<TChild, T> Result<T*, E>& operator=(Result<TChild*, E>&& other); @@ -166,8 +166,8 @@ static_assert(alignof_if_defined_else_default<E, 4> >= 4, "Result<T*, E*> reserves two bits for tagging pointers"); - Result(const T* success); - Result(std::unique_ptr<E> error); + explicit(false) Result(const T* success); + explicit(false) Result(std::unique_ptr<E> error); Result(Result<const T*, E>&& other); Result<const T*, E>& operator=(Result<const T*, E>&& other); @@ -197,16 +197,16 @@ template <typename U> requires std::convertible_to<U*, T*> - Result(Ref<U>&& success); + explicit(false) Result(Ref<U>&& success); template <typename U> requires std::convertible_to<U*, T*> - Result(const Ref<U>& success); - Result(std::unique_ptr<E> error); - constexpr Result(std::nullptr_t); + explicit(false) Result(const Ref<U>& success); + explicit(false) Result(std::unique_ptr<E> error); + explicit(false) constexpr Result(std::nullptr_t); template <typename U> requires std::convertible_to<U*, T*> - Result(Result<Ref<U>, E>&& other); + explicit(false) Result(Result<Ref<U>, E>&& other); template <typename U> requires std::convertible_to<U*, T*> Result<Ref<U>, E>& operator=(Result<Ref<U>, E>&& other); @@ -232,8 +232,8 @@ template <typename T, typename E> class [[nodiscard]] Result { public: - Result(T success); - Result(std::unique_ptr<E> error); + explicit(false) Result(T success); + explicit(false) Result(std::unique_ptr<E> error); Result(Result<T, E>&& other); Result<T, E>& operator=(Result<T, E>&& other);
diff --git a/src/dawn/common/SlabAllocator.h b/src/dawn/common/SlabAllocator.h index 250b08a..e95f3f3 100644 --- a/src/dawn/common/SlabAllocator.h +++ b/src/dawn/common/SlabAllocator.h
@@ -192,9 +192,9 @@ template <typename T> class SlabAllocator : public SlabAllocatorImpl { public: - SlabAllocator(size_t totalObjectBytes, - uint32_t objectSize = u32_sizeof<T>, - uint32_t objectAlignment = u32_alignof<T>) + explicit SlabAllocator(size_t totalObjectBytes, + uint32_t objectSize = u32_sizeof<T>, + uint32_t objectAlignment = u32_alignof<T>) : SlabAllocatorImpl(std::max(totalObjectBytes / objectSize, size_t{1}), objectSize, objectAlignment) {}
diff --git a/src/dawn/common/vulkan_platform.h b/src/dawn/common/vulkan_platform.h index 0005f68..5702081 100644 --- a/src/dawn/common/vulkan_platform.h +++ b/src/dawn/common/vulkan_platform.h
@@ -88,7 +88,7 @@ public: // Default constructor and assigning of VK_NULL_HANDLE VkHandle() = default; - VkHandle(std::nullptr_t) {} + explicit(false) VkHandle(std::nullptr_t) {} // Use default copy constructor/assignment VkHandle(const VkHandle<Tag, HandleType>& other) = default; @@ -102,6 +102,7 @@ bool operator!=(std::nullptr_t) const { return mHandle != 0; } // Implicit conversion to real Vulkan types. + // NOLINTNEXTLINE(google-explicit-constructor) operator HandleType() const { return GetHandle(); } const HandleType& GetHandle() const { return mHandle; }
diff --git a/src/dawn/native/CommandEncoder.h b/src/dawn/native/CommandEncoder.h index c5dbfca..24193a6 100644 --- a/src/dawn/native/CommandEncoder.h +++ b/src/dawn/native/CommandEncoder.h
@@ -123,7 +123,7 @@ private: // Only CommandEncoder can make this class. friend class CommandEncoder; - InternalUsageScope(CommandEncoder* encoder); + explicit InternalUsageScope(CommandEncoder* encoder); raw_ptr<CommandEncoder> mEncoder; UsageValidationMode mUsageValidationMode = UsageValidationMode::Default;
diff --git a/src/dawn/native/d3d/d3d_platform.h b/src/dawn/native/d3d/d3d_platform.h index b5fe84b..e52b2a2 100644 --- a/src/dawn/native/d3d/d3d_platform.h +++ b/src/dawn/native/d3d/d3d_platform.h
@@ -48,6 +48,7 @@ #include <utility> using Microsoft::WRL::ComPtr; + template <typename T> struct std::hash<ComPtr<T>> { std::size_t operator()(const ComPtr<T>& v) const noexcept { return std::hash<T*>{}(v.Get()); }
diff --git a/src/dawn/native/vulkan/VulkanFunctions.h b/src/dawn/native/vulkan/VulkanFunctions.h index 75ea60a..cda9e4a 100644 --- a/src/dawn/native/vulkan/VulkanFunctions.h +++ b/src/dawn/native/vulkan/VulkanFunctions.h
@@ -414,6 +414,7 @@ public: constexpr static VkResult WrapUnsafe(::VkResult value) { return VkResult(value); } + // NOLINTNEXTLINE(google-explicit-constructor) constexpr operator ::VkResult() const { return mValue; } private:
diff --git a/src/dawn/node/binding/GPU.h b/src/dawn/node/binding/GPU.h index 64c2a35..9345441 100644 --- a/src/dawn/node/binding/GPU.h +++ b/src/dawn/node/binding/GPU.h
@@ -42,7 +42,7 @@ // GPU is an implementation of interop::GPU that wraps a dawn::native::Instance. class GPU final : public interop::GPU { public: - GPU(Flags flags); + explicit GPU(Flags flags); // interop::GPU interface compliance interop::Promise<std::optional<interop::Interface<interop::GPUAdapter>>> requestAdapter(
diff --git a/src/dawn/node/binding/GPUBindGroup.h b/src/dawn/node/binding/GPUBindGroup.h index a3ca20c..8928c63 100644 --- a/src/dawn/node/binding/GPUBindGroup.h +++ b/src/dawn/node/binding/GPUBindGroup.h
@@ -44,6 +44,7 @@ GPUBindGroup(const wgpu::BindGroupDescriptor& desc, wgpu::BindGroup group); // Implicit cast operator to Dawn GPU object + // NOLINTNEXTLINE(google-explicit-constructor) inline operator const wgpu::BindGroup&() const { return group_; } // interop::GPUBindGroup interface compliance
diff --git a/src/dawn/node/binding/GPUBindGroupLayout.h b/src/dawn/node/binding/GPUBindGroupLayout.h index c369c60..fad3e2f 100644 --- a/src/dawn/node/binding/GPUBindGroupLayout.h +++ b/src/dawn/node/binding/GPUBindGroupLayout.h
@@ -45,6 +45,7 @@ GPUBindGroupLayout(const wgpu::BindGroupLayoutDescriptor& desc, wgpu::BindGroupLayout layout); // Implicit cast operator to Dawn GPU object + // NOLINTNEXTLINE(google-explicit-constructor) inline operator const wgpu::BindGroupLayout&() const { return layout_; } // interop::GPUBindGroupLayout interface compliance
diff --git a/src/dawn/node/binding/GPUBuffer.h b/src/dawn/node/binding/GPUBuffer.h index 3da588c..92422b9 100644 --- a/src/dawn/node/binding/GPUBuffer.h +++ b/src/dawn/node/binding/GPUBuffer.h
@@ -53,6 +53,7 @@ const wgpu::BufferDescriptor& Desc() const { return desc_; } // Implicit cast operator to Dawn GPU object + // NOLINTNEXTLINE(google-explicit-constructor) inline operator const wgpu::Buffer&() const { return buffer_; } // interop::GPUBuffer interface compliance
diff --git a/src/dawn/node/binding/GPUCommandBuffer.h b/src/dawn/node/binding/GPUCommandBuffer.h index 374cb3f..bd922d9 100644 --- a/src/dawn/node/binding/GPUCommandBuffer.h +++ b/src/dawn/node/binding/GPUCommandBuffer.h
@@ -45,6 +45,7 @@ GPUCommandBuffer(const wgpu::CommandBufferDescriptor& desc, wgpu::CommandBuffer cmd_buf); // Implicit cast operator to Dawn GPU object + // NOLINTNEXTLINE(google-explicit-constructor) inline operator const wgpu::CommandBuffer&() const { return cmd_buf_; } // interop::GPUCommandBuffer interface compliance
diff --git a/src/dawn/node/binding/GPUComputePassEncoder.h b/src/dawn/node/binding/GPUComputePassEncoder.h index 0695283..46e9e6d 100644 --- a/src/dawn/node/binding/GPUComputePassEncoder.h +++ b/src/dawn/node/binding/GPUComputePassEncoder.h
@@ -46,6 +46,7 @@ GPUComputePassEncoder(const wgpu::ComputePassDescriptor& desc, wgpu::ComputePassEncoder enc); // Implicit cast operator to Dawn GPU object + // NOLINTNEXTLINE(google-explicit-constructor) inline operator const wgpu::ComputePassEncoder&() const { return enc_; } // interop::GPUComputePassEncoder interface compliance
diff --git a/src/dawn/node/binding/GPUComputePipeline.h b/src/dawn/node/binding/GPUComputePipeline.h index cf91ad4..e40154d 100644 --- a/src/dawn/node/binding/GPUComputePipeline.h +++ b/src/dawn/node/binding/GPUComputePipeline.h
@@ -46,6 +46,7 @@ GPUComputePipeline(wgpu::ComputePipeline pipeline, std::string label); // Implicit cast operator to Dawn GPU object + // NOLINTNEXTLINE(google-explicit-constructor) inline operator const wgpu::ComputePipeline&() const { return pipeline_; } // interop::GPUComputePipeline interface compliance
diff --git a/src/dawn/node/binding/GPUPipelineLayout.h b/src/dawn/node/binding/GPUPipelineLayout.h index 3492f6c..7b69bd6 100644 --- a/src/dawn/node/binding/GPUPipelineLayout.h +++ b/src/dawn/node/binding/GPUPipelineLayout.h
@@ -45,6 +45,7 @@ GPUPipelineLayout(const wgpu::PipelineLayoutDescriptor& desc, wgpu::PipelineLayout layout); // Implicit cast operator to Dawn GPU object + // NOLINTNEXTLINE(google-explicit-constructor) inline operator const wgpu::PipelineLayout&() const { return layout_; } // interop::GPUPipelineLayout interface compliance
diff --git a/src/dawn/node/binding/GPUQuerySet.h b/src/dawn/node/binding/GPUQuerySet.h index 4040bf0..05a97ca 100644 --- a/src/dawn/node/binding/GPUQuerySet.h +++ b/src/dawn/node/binding/GPUQuerySet.h
@@ -44,6 +44,7 @@ GPUQuerySet(const wgpu::QuerySetDescriptor& desc, wgpu::QuerySet query_set); // Implicit cast operator to Dawn GPU object + // NOLINTNEXTLINE(google-explicit-constructor) inline operator const wgpu::QuerySet&() const { return query_set_; } // interop::GPUQuerySet interface compliance
diff --git a/src/dawn/node/binding/GPURenderBundle.h b/src/dawn/node/binding/GPURenderBundle.h index 6ee5914..6203d0c 100644 --- a/src/dawn/node/binding/GPURenderBundle.h +++ b/src/dawn/node/binding/GPURenderBundle.h
@@ -45,6 +45,7 @@ GPURenderBundle(const wgpu::RenderBundleDescriptor& desc, wgpu::RenderBundle bundle); // Implicit cast operator to Dawn GPU object + // NOLINTNEXTLINE(google-explicit-constructor) inline operator const wgpu::RenderBundle&() const { return bundle_; } // interop::GPURenderBundle interface compliance
diff --git a/src/dawn/node/binding/GPURenderPassEncoder.h b/src/dawn/node/binding/GPURenderPassEncoder.h index 88ddc76..a08d9df 100644 --- a/src/dawn/node/binding/GPURenderPassEncoder.h +++ b/src/dawn/node/binding/GPURenderPassEncoder.h
@@ -46,6 +46,7 @@ GPURenderPassEncoder(const wgpu::RenderPassDescriptor& desc, wgpu::RenderPassEncoder enc); // Implicit cast operator to Dawn GPU object + // NOLINTNEXTLINE(google-explicit-constructor) inline operator const wgpu::RenderPassEncoder&() const { return enc_; } // interop::GPURenderPassEncoder interface compliance
diff --git a/src/dawn/node/binding/GPURenderPipeline.h b/src/dawn/node/binding/GPURenderPipeline.h index 51cad32..6a9bd92 100644 --- a/src/dawn/node/binding/GPURenderPipeline.h +++ b/src/dawn/node/binding/GPURenderPipeline.h
@@ -46,6 +46,7 @@ GPURenderPipeline(wgpu::RenderPipeline pipeline, std::string label); // Implicit cast operator to Dawn GPU object + // NOLINTNEXTLINE(google-explicit-constructor) inline operator const wgpu::RenderPipeline&() const { return pipeline_; } // interop::GPURenderPipeline interface compliance
diff --git a/src/dawn/node/binding/GPUResourceTable.h b/src/dawn/node/binding/GPUResourceTable.h index 9d10868..e8233a8 100644 --- a/src/dawn/node/binding/GPUResourceTable.h +++ b/src/dawn/node/binding/GPUResourceTable.h
@@ -42,6 +42,7 @@ GPUResourceTable(const wgpu::ResourceTableDescriptor& desc, wgpu::ResourceTable table); // Implicit cast operator to Dawn GPU object + // NOLINTNEXTLINE(google-explicit-constructor) inline operator const wgpu::ResourceTable&() const { return table_; } // interop::GPUResourceTable interface compliance
diff --git a/src/dawn/node/binding/GPUSampler.h b/src/dawn/node/binding/GPUSampler.h index 4a7eb85..af66b27 100644 --- a/src/dawn/node/binding/GPUSampler.h +++ b/src/dawn/node/binding/GPUSampler.h
@@ -43,6 +43,7 @@ GPUSampler(const wgpu::SamplerDescriptor& desc, wgpu::Sampler sampler); // Implicit cast operator to Dawn GPU object + // NOLINTNEXTLINE(google-explicit-constructor) inline operator const wgpu::Sampler&() const { return sampler_; } // interop::GPUSampler interface compliance
diff --git a/src/dawn/node/binding/GPUShaderModule.h b/src/dawn/node/binding/GPUShaderModule.h index 3ba4699..189ebc3 100644 --- a/src/dawn/node/binding/GPUShaderModule.h +++ b/src/dawn/node/binding/GPUShaderModule.h
@@ -49,6 +49,7 @@ std::shared_ptr<AsyncRunner> async); // Implicit cast operator to Dawn GPU object + // NOLINTNEXTLINE(google-explicit-constructor) inline operator const wgpu::ShaderModule&() const { return shader_; } // interop::GPUShaderModule interface compliance
diff --git a/src/dawn/node/binding/GPUTexture.h b/src/dawn/node/binding/GPUTexture.h index 4a2456d..2590701 100644 --- a/src/dawn/node/binding/GPUTexture.h +++ b/src/dawn/node/binding/GPUTexture.h
@@ -44,6 +44,7 @@ GPUTexture(wgpu::Device device, const wgpu::TextureDescriptor& desc, wgpu::Texture texture); // Implicit cast operator to Dawn GPU object + // NOLINTNEXTLINE(google-explicit-constructor) inline operator const wgpu::Texture&() const { return texture_; } // interop::GPUTexture interface compliance
diff --git a/src/dawn/node/binding/GPUTextureView.h b/src/dawn/node/binding/GPUTextureView.h index 08fbc27..29fcb5a 100644 --- a/src/dawn/node/binding/GPUTextureView.h +++ b/src/dawn/node/binding/GPUTextureView.h
@@ -45,6 +45,7 @@ GPUTextureView(const wgpu::TextureViewDescriptor& desc, wgpu::TextureView view); // Implicit cast operator to Dawn GPU object + // NOLINTNEXTLINE(google-explicit-constructor) inline operator const wgpu::TextureView&() const { return view_; } // interop::GPUTextureView interface compliance
diff --git a/src/dawn/node/interop/Core.h b/src/dawn/node/interop/Core.h index c5980f4..cbdc398 100644 --- a/src/dawn/node/interop/Core.h +++ b/src/dawn/node/interop/Core.h
@@ -95,6 +95,7 @@ using IntegerType = T; ClampedInteger() : value(0) {} explicit(false) ClampedInteger(T v) : value(v) {} + // NOLINTNEXTLINE(google-explicit-constructor) operator T() const { return value; } T value; }; @@ -107,6 +108,7 @@ using IntegerType = T; EnforceRangeInteger() : value(0) {} explicit(false) EnforceRangeInteger(T v) : value(v) {} + // NOLINTNEXTLINE(google-explicit-constructor) operator T() const { return value; } T value; }; @@ -163,8 +165,11 @@ explicit inline Interface(Napi::Object o) : object(o) {} // Implicit conversion operators to Napi objects. + // NOLINTNEXTLINE(google-explicit-constructor) inline operator napi_value() const { return object; } + // NOLINTNEXTLINE(google-explicit-constructor) inline operator const Napi::Value&() const { return object; } + // NOLINTNEXTLINE(google-explicit-constructor) inline operator const Napi::Object&() const { return object; } // Member and dereference operators @@ -208,8 +213,11 @@ class PromiseBase { public: // Implicit conversion operators to Napi promises. + // NOLINTNEXTLINE(google-explicit-constructor) inline operator napi_value() const { return state_->deferred.Promise(); } + // NOLINTNEXTLINE(google-explicit-constructor) inline operator Napi::Value() const { return state_->deferred.Promise(); } + // NOLINTNEXTLINE(google-explicit-constructor) inline operator Napi::Promise() const { return state_->deferred.Promise(); } // Comparison operator between promises @@ -771,6 +779,7 @@ T default_value; // The default value if no argument supplied // Implicit conversion operator. Returns value. + // NOLINTNEXTLINE(google-explicit-constructor) inline operator const T&() const { return value; } };
diff --git a/src/dawn/node/interop/WebGPU.h.tmpl b/src/dawn/node/interop/WebGPU.h.tmpl index 285e678..1c612e2 100644 --- a/src/dawn/node/interop/WebGPU.h.tmpl +++ b/src/dawn/node/interop/WebGPU.h.tmpl
@@ -53,7 +53,7 @@ namespace interop { struct Constructors : public ManualConstructors { - Constructors(Napi::Env env) : ManualConstructors(env) {} + explicit Constructors(Napi::Env env) : ManualConstructors(env) {} {{ range $ := .Declarations}} {{- if and (IsInterfaceOrNamespace $) (not (HasAnnotation $ "ManualImplementation"))}} Napi::FunctionReference {{$.Name}}_ctor;
diff --git a/src/dawn/platform/metrics/HistogramMacros.h b/src/dawn/platform/metrics/HistogramMacros.h index 03148ff..26ddd0b 100644 --- a/src/dawn/platform/metrics/HistogramMacros.h +++ b/src/dawn/platform/metrics/HistogramMacros.h
@@ -182,7 +182,7 @@ class [[nodiscard]] ScopedHistogramTimer##key { \ public: \ using Platform = PlatformType##key; \ - ScopedHistogramTimer##key(Platform* p) \ + explicit ScopedHistogramTimer##key(Platform* p) \ : platform_(p), constructed_(platform_->MonotonicallyIncreasingTime()) {} \ ~ScopedHistogramTimer##key() { \ if (constructed_ == 0) \
diff --git a/src/dawn/platform/tracing/TraceEvent.h b/src/dawn/platform/tracing/TraceEvent.h index b2672bd..d4c470f 100644 --- a/src/dawn/platform/tracing/TraceEvent.h +++ b/src/dawn/platform/tracing/TraceEvent.h
@@ -833,6 +833,7 @@ class TraceStringWithCopy { public: explicit TraceStringWithCopy(const char* str) : m_str(str) {} + // NOLINTNEXTLINE(google-explicit-constructor) operator const char*() const { return m_str; } private:
diff --git a/src/dawn/tests/AdapterTestConfig.h b/src/dawn/tests/AdapterTestConfig.h index 6b73eea..ae28789 100644 --- a/src/dawn/tests/AdapterTestConfig.h +++ b/src/dawn/tests/AdapterTestConfig.h
@@ -37,9 +37,9 @@ #include <vector> struct BackendTestConfig { - BackendTestConfig(wgpu::BackendType backendType, - std::initializer_list<const char*> forceEnabledWorkarounds = {}, - std::initializer_list<const char*> forceDisabledWorkarounds = {}); + explicit BackendTestConfig(wgpu::BackendType backendType, + std::initializer_list<const char*> forceEnabledWorkarounds = {}, + std::initializer_list<const char*> forceDisabledWorkarounds = {}); wgpu::BackendType backendType;
diff --git a/src/dawn/tests/ParamGenerator.h b/src/dawn/tests/ParamGenerator.h index 0466e9b..ba79e6a 100644 --- a/src/dawn/tests/ParamGenerator.h +++ b/src/dawn/tests/ParamGenerator.h
@@ -96,7 +96,7 @@ } \ struct StructName : BaseStructName, DAWN_PP_CONCATENATE(_Dawn_, StructName) { \ template <typename... Args> \ - StructName(const BaseStructName& param, Args&&... args) \ + explicit StructName(const BaseStructName& param, Args&&... args) \ : BaseStructName(param), DAWN_PP_CONCATENATE(_Dawn_, StructName) { \ std::forward<Args>(args)... \ } \ @@ -133,7 +133,7 @@ } \ struct StructName : DAWN_PP_CONCATENATE(_Dawn_, StructName) { \ template <typename... Args> \ - StructName(Args&&... args) : DAWN_PP_CONCATENATE(_Dawn_, StructName) { \ + explicit StructName(Args&&... args) : DAWN_PP_CONCATENATE(_Dawn_, StructName) { \ std::forward<Args>(args)... \ } \ { \
diff --git a/src/dawn/utils/WGPUHelpers.h b/src/dawn/utils/WGPUHelpers.h index 19ed430..f0a1322 100644 --- a/src/dawn/utils/WGPUHelpers.h +++ b/src/dawn/utils/WGPUHelpers.h
@@ -78,8 +78,9 @@ struct ComboRenderPassDescriptor : public wgpu::RenderPassDescriptor { public: - ComboRenderPassDescriptor(const std::vector<wgpu::TextureView>& colorAttachmentInfo = {}, - wgpu::TextureView depthStencil = wgpu::TextureView()); + explicit ComboRenderPassDescriptor( + const std::vector<wgpu::TextureView>& colorAttachmentInfo = {}, + wgpu::TextureView depthStencil = wgpu::TextureView()); ~ComboRenderPassDescriptor(); ComboRenderPassDescriptor(const ComboRenderPassDescriptor& otherRenderPass);
diff --git a/src/dawn/wire/ObjectHandle.h b/src/dawn/wire/ObjectHandle.h index 6a08195..c828cad 100644 --- a/src/dawn/wire/ObjectHandle.h +++ b/src/dawn/wire/ObjectHandle.h
@@ -45,7 +45,7 @@ ObjectHandle(); ObjectHandle(ObjectId objId, ObjectGeneration objGeneration); - explicit ObjectHandle(const volatile ObjectHandle& rhs); + explicit(false) ObjectHandle(const volatile ObjectHandle& rhs); ObjectHandle& operator=(const volatile ObjectHandle& rhs); ObjectHandle(const ObjectHandle& rhs);
diff --git a/src/tint/lang/core/number.h b/src/tint/lang/core/number.h index aa8d743..156d4bc 100644 --- a/src/tint/lang/core/number.h +++ b/src/tint/lang/core/number.h
@@ -176,6 +176,7 @@ /// Conversion operator /// @returns the value as T + // NOLINTNEXTLINE(google-explicit-constructor) operator T() const { return value; } /// Negation operator @@ -244,6 +245,7 @@ /// Conversion operator /// @returns the value as the internal representation type of F16 + // NOLINTNEXTLINE(google-explicit-constructor) operator float() const { return value; } /// Negation operator
diff --git a/src/tint/lang/wgsl/ast/type.h b/src/tint/lang/wgsl/ast/type.h index e2f9bc5..5782d85 100644 --- a/src/tint/lang/wgsl/ast/type.h +++ b/src/tint/lang/wgsl/ast/type.h
@@ -47,6 +47,7 @@ /// Implicit conversion operator to the type's expression /// @return #expr + // NOLINTNEXTLINE(google-explicit-constructor) operator const IdentifierExpression*() const { return expr; } };
diff --git a/src/tint/lang/wgsl/reader/parser/parser.cc b/src/tint/lang/wgsl/reader/parser/parser.cc index df240d4..b2ce424 100644 --- a/src/tint/lang/wgsl/reader/parser/parser.cc +++ b/src/tint/lang/wgsl/reader/parser/parser.cc
@@ -142,6 +142,7 @@ /// @returns the Source that returns the combined source from start to the current last token's /// source. + // NOLINTNEXTLINE(google-explicit-constructor) operator tint::Source() const { auto end = parser_->last_source().End(); if (end < start_) {
diff --git a/src/tint/lang/wgsl/resolver/resolver_helper_test.h b/src/tint/lang/wgsl/resolver/resolver_helper_test.h index 3e00ed6..563732e 100644 --- a/src/tint/lang/wgsl/resolver/resolver_helper_test.h +++ b/src/tint/lang/wgsl/resolver/resolver_helper_test.h
@@ -180,10 +180,10 @@ /// Constructor /// @param val the value used to construct this Scalar template <typename T> - Scalar(T&& val) : value(std::forward<T>(val)) {} // NOLINT + explicit(false) Scalar(T&& val) : value(std::forward<T>(val)) {} /// @returns the Value - operator Value&() { return value; } + explicit operator Value&() { return value; } /// Equality operator /// @param other the other Scalar
diff --git a/src/tint/utils/command/command_posix.cc b/src/tint/utils/command/command_posix.cc index a770d46..f3ab5056 100644 --- a/src/tint/utils/command/command_posix.cc +++ b/src/tint/utils/command/command_posix.cc
@@ -76,6 +76,7 @@ } /// @returns the file handle + // NOLINTNEXTLINE(google-explicit-constructor) operator int() { return handle_; } /// @returns true if the file is not closed
diff --git a/src/tint/utils/command/command_windows.cc b/src/tint/utils/command/command_windows.cc index 430d1ce..91448c1 100644 --- a/src/tint/utils/command/command_windows.cc +++ b/src/tint/utils/command/command_windows.cc
@@ -73,6 +73,7 @@ } /// @returns the handle + // NOLINTNEXTLINE(google-explicit-constructor) operator HANDLE() { return handle_; } /// @returns true if the handle is not invalid
diff --git a/src/tint/utils/containers/bitset.h b/src/tint/utils/containers/bitset.h index a53622e..d05b3b2 100644 --- a/src/tint/utils/containers/bitset.h +++ b/src/tint/utils/containers/bitset.h
@@ -78,6 +78,7 @@ /// Conversion operator /// @returns the bit value + // NOLINTNEXTLINE(google-explicit-constructor) operator bool() const { return (word & mask) != 0; } };
diff --git a/src/tint/utils/containers/hashmap_base.h b/src/tint/utils/containers/hashmap_base.h index d7b4569..9aed7ae 100644 --- a/src/tint/utils/containers/hashmap_base.h +++ b/src/tint/utils/containers/hashmap_base.h
@@ -142,6 +142,7 @@ const T& Value() const { return value_; } /// @returns the value of the key + // NOLINTNEXTLINE(google-explicit-constructor) operator const T&() const { return value_; } /// @returns the pointer to the value, or the value itself if T is a pointer.
diff --git a/src/tint/utils/containers/unique_vector.h b/src/tint/utils/containers/unique_vector.h index 38e4714..a323938 100644 --- a/src/tint/utils/containers/unique_vector.h +++ b/src/tint/utils/containers/unique_vector.h
@@ -120,6 +120,7 @@ auto rend() const { return vector.rend(); } /// @returns a reference to the internal vector + // NOLINTNEXTLINE(google-explicit-constructor) operator VectorRef<T>() const { return vector; } /// @returns the std::move()'d vector.
diff --git a/src/tint/utils/ice/ice.h b/src/tint/utils/ice/ice.h index a6fb44d..6b012aa 100644 --- a/src/tint/utils/ice/ice.h +++ b/src/tint/utils/ice/ice.h
@@ -87,7 +87,7 @@ /// This operator overload exists so that we can use an InternalCompilerError object on the /// right-hand side of a short-circuiting operator, which is how the TINT_ASSERT macro works. - operator bool() const { return false; } + explicit operator bool() const { return false; } private: InternalCompilerError(const InternalCompilerError&) = delete;
diff --git a/src/tint/utils/text/unicode.h b/src/tint/utils/text/unicode.h index adb7257..b371801 100644 --- a/src/tint/utils/text/unicode.h +++ b/src/tint/utils/text/unicode.h
@@ -46,6 +46,7 @@ inline explicit CodePoint(uint32_t v) : value(v) {} /// @returns the code point value + // NOLINTNEXTLINE(google-explicit-constructor) inline operator uint32_t() const { return value; } /// Assignment operator
diff --git a/src/tint/utils/text_generator/text_generator.h b/src/tint/utils/text_generator/text_generator.h index 3223bb1..ab1f94f 100644 --- a/src/tint/utils/text_generator/text_generator.h +++ b/src/tint/utils/text_generator/text_generator.h
@@ -116,6 +116,7 @@ ~LineWriter(); /// @returns the StringStream + // NOLINTNEXTLINE(google-explicit-constructor) operator StringStream&() { return os; } /// @param rhs the value to write to the line