microsoft / microsoft/wil

Make smart pointer constructors (e.g. `wil::com_ptr`) constexpr when initializing to nullptr

Open
#535 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
3k
Forks
300
Avg merge
19h 12m
Merged PRs (30d)
1

Description

e.g. something along the lines of:

diff --git a/include/wil/com.h b/include/wil/com.h
index 2492611..33e126c 100644
--- a/include/wil/com.h
+++ b/include/wil/com.h
@@ -215,12 +215,12 @@ public:
     //! @{
 
     //! Default constructor (holds nullptr).
-    com_ptr_t() WI_NOEXCEPT : m_ptr(nullptr)
+    __WI_LIBCPP_CONSTEXPR com_ptr_t() WI_NOEXCEPT : m_ptr(nullptr)
     {
     }
 
     //! Implicit construction from nullptr_t (holds nullptr).
-    com_ptr_t(wistd::nullptr_t) WI_NOEXCEPT : com_ptr_t()
+    __WI_LIBCPP_CONSTEXPR com_ptr_t(wistd::nullptr_t) WI_NOEXCEPT : com_ptr_t()
     {
     }
 
@@ -234,7 +234,7 @@ public:
     }
 
     //! Copy-construction from a like `com_ptr_t` (copies and AddRef's the parameter).
-    com_ptr_t(const com_ptr_t& other) WI_NOEXCEPT : com_ptr_t(other.get())
+    __WI_LIBCPP_CONSTEXPR com_ptr_t(const com_ptr_t& other) WI_NOEXCEPT : com_ptr_t(other.get())
     {
     }
 
@@ -269,7 +269,7 @@ public:
     //! @{
 
     //! Assign to nullptr (releases the current pointer, holds nullptr).
-    com_ptr_t& operator=(wistd::nullptr_t) WI_NOEXCEPT
+    __WI_LIBCPP_CONSTEXPR com_ptr_t& operator=(wistd::nullptr_t) WI_NOEXCEPT
     {
         reset();
         return *this;
@@ -292,7 +292,7 @@ public:
     }
 
     //! Assign a like `com_ptr_t` (releases current pointer, copies and AddRef's the parameter).
-    com_ptr_t& operator=(const com_ptr_t& other) WI_NOEXCEPT
+    __WI_LIBCPP_CONSTEXPR com_ptr_t& operator=(const com_ptr_t& other) WI_NOEXCEPT
     {
         return operator=(other.get());
     }

Not sending a pull request due to build dependencies on nuget, separately installed detours etc instead of more isolated and common tools like vcpkg.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in include/wil/com.h and review the wil::com_ptr constructors and assignments shown in the issue, then identify whether the same nullptr initialization pattern applies to other smart pointer types. Check the available project build requirements before validating constexpr initialization; done means the relevant constructors support nullptr initialization without breaking existing compatibility.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
devtools
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.