Skip to content

[lldb-dap] Mitigate a build error on Windows. #137388

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 25, 2025

Conversation

ashgti
Copy link
Contributor

@ashgti ashgti commented Apr 25, 2025

When building with MSVC 2019 using std::future<llvm::Error> causes a compile time build error.

C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30133\include\future(196): error C2248: 'llvm::Error::Error': cannot access protected member declared in class 'llvm::Error'

C:\work\main\llvm-project\llvm\include\llvm/Support/Error.h(181): note: see declaration of 'llvm::Error::Error'

C:\work\main\llvm-project\llvm\include\llvm/Support/FormatVariadicDetails.h(20): note: see declaration of 'llvm::Error'

C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30133\include\future(193): note: while compiling class template member function 'std::_Associated_state<_Ty>::_Associated_state(std::_Deleter_base<_Ty> *)'

        with

        [

            _Ty=llvm::Error

        ]

C:\work\main\llvm-project\lldb\tools\lldb-dap\DAP.cpp(854): note: see reference to class template instantiation 'std::future<llvm::Error>' being compiled

To work around this, swapping to a lldb::SBError for now.

When building with MSVC 2019 using `std::future<llvm::Error>` causes a compile time build error.

```
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30133\include\future(196): error C2248: 'llvm::Error::Error': cannot access protected member declared in class 'llvm::Error'

C:\work\main\llvm-project\llvm\include\llvm/Support/Error.h(181): note: see declaration of 'llvm::Error::Error'

C:\work\main\llvm-project\llvm\include\llvm/Support/FormatVariadicDetails.h(20): note: see declaration of 'llvm::Error'

C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30133\include\future(193): note: while compiling class template member function 'std::_Associated_state<_Ty>::_Associated_state(std::_Deleter_base<_Ty> *)'

        with

        [

            _Ty=llvm::Error

        ]

C:\work\main\llvm-project\lldb\tools\lldb-dap\DAP.cpp(854): note: see reference to class template instantiation 'std::future<llvm::Error>' being compiled
```

To work around this, swapping to a lldb::SBError for now.
@ashgti ashgti requested a review from JDevlieghere as a code owner April 25, 2025 19:51
@ashgti ashgti requested review from vogelsgesang and removed request for JDevlieghere April 25, 2025 19:51
@ashgti ashgti requested a review from JDevlieghere April 25, 2025 19:51
@llvmbot
Copy link
Member

llvmbot commented Apr 25, 2025

@llvm/pr-subscribers-lldb

Author: John Harrison (ashgti)

Changes

When building with MSVC 2019 using std::future&lt;llvm::Error&gt; causes a compile time build error.

C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30133\include\future(196): error C2248: 'llvm::Error::Error': cannot access protected member declared in class 'llvm::Error'

C:\work\main\llvm-project\llvm\include\llvm/Support/Error.h(181): note: see declaration of 'llvm::Error::Error'

C:\work\main\llvm-project\llvm\include\llvm/Support/FormatVariadicDetails.h(20): note: see declaration of 'llvm::Error'

C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30133\include\future(193): note: while compiling class template member function 'std::_Associated_state&lt;_Ty&gt;::_Associated_state(std::_Deleter_base&lt;_Ty&gt; *)'

        with

        [

            _Ty=llvm::Error

        ]

C:\work\main\llvm-project\lldb\tools\lldb-dap\DAP.cpp(854): note: see reference to class template instantiation 'std::future&lt;llvm::Error&gt;' being compiled

To work around this, swapping to a lldb::SBError for now.


Full diff: https://github.com/llvm/llvm-project/pull/137388.diff

1 Files Affected:

  • (modified) lldb/tools/lldb-dap/DAP.cpp (+11-6)
diff --git a/lldb/tools/lldb-dap/DAP.cpp b/lldb/tools/lldb-dap/DAP.cpp
index 185b475cfcad6..1813d8f853cda 100644
--- a/lldb/tools/lldb-dap/DAP.cpp
+++ b/lldb/tools/lldb-dap/DAP.cpp
@@ -844,8 +844,10 @@ static std::optional<T> getArgumentsIfRequest(const Message &pm,
 }
 
 llvm::Error DAP::Loop() {
-  std::future<llvm::Error> queue_reader =
-      std::async(std::launch::async, [&]() -> llvm::Error {
+  // Can't use \a std::future<llvm::Error> because it doesn't compile on
+  // Windows.
+  std::future<lldb::SBError> queue_reader =
+      std::async(std::launch::async, [&]() -> lldb::SBError {
         llvm::set_thread_name(transport.GetClientName() + ".transport_handler");
         auto cleanup = llvm::make_scope_exit([&]() {
           // Ensure we're marked as disconnecting when the reader exits.
@@ -867,8 +869,11 @@ llvm::Error DAP::Loop() {
             continue;
           }
 
-          if (llvm::Error err = next.takeError())
-            return err;
+          if (llvm::Error err = next.takeError()) {
+            lldb::SBError errWrapper;
+            errWrapper.SetErrorString(llvm::toString(std::move(err)).c_str());
+            return errWrapper;
+          }
 
           if (const protocol::Request *req =
                   std::get_if<protocol::Request>(&*next);
@@ -906,7 +911,7 @@ llvm::Error DAP::Loop() {
           m_queue_cv.notify_one();
         }
 
-        return llvm::Error::success();
+        return lldb::SBError();
       });
 
   auto cleanup = llvm::make_scope_exit([&]() {
@@ -930,7 +935,7 @@ llvm::Error DAP::Loop() {
                                      "unhandled packet");
   }
 
-  return queue_reader.get();
+  return ToError(queue_reader.get());
 }
 
 lldb::SBError DAP::WaitForProcessToStop(std::chrono::seconds seconds) {

Copy link
Member

@JDevlieghere JDevlieghere left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Weird, I wonder what the protected member is that the error is talking about. Anyway, this seems fine.

@ashgti
Copy link
Contributor Author

ashgti commented Apr 25, 2025

It seems to work with MSVC 2022, so I guess its something to do with the way std::future is implemented in the 2019 version.

@ashgti ashgti merged commit a3b6423 into llvm:main Apr 25, 2025
11 of 12 checks passed
@labath
Copy link
Collaborator

labath commented Apr 28, 2025

Weird, I wonder what the protected member is that the error is talking about. Anyway, this seems fine.

'llvm::Error::Error'

It's the default constructor. I guess the implementation tries to default construct the object on some (maybe not dynamically reachable) code path.

jyli0116 pushed a commit to jyli0116/llvm-project that referenced this pull request Apr 28, 2025
When building with MSVC 2019 using `std::future<llvm::Error>` causes a
compile time build error.

```
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30133\include\future(196): error C2248: 'llvm::Error::Error': cannot access protected member declared in class 'llvm::Error'

C:\work\main\llvm-project\llvm\include\llvm/Support/Error.h(181): note: see declaration of 'llvm::Error::Error'

C:\work\main\llvm-project\llvm\include\llvm/Support/FormatVariadicDetails.h(20): note: see declaration of 'llvm::Error'

C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30133\include\future(193): note: while compiling class template member function 'std::_Associated_state<_Ty>::_Associated_state(std::_Deleter_base<_Ty> *)'

        with

        [

            _Ty=llvm::Error

        ]

C:\work\main\llvm-project\lldb\tools\lldb-dap\DAP.cpp(854): note: see reference to class template instantiation 'std::future<llvm::Error>' being compiled
```

To work around this, swapping to a lldb::SBError for now.
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
When building with MSVC 2019 using `std::future<llvm::Error>` causes a
compile time build error.

```
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30133\include\future(196): error C2248: 'llvm::Error::Error': cannot access protected member declared in class 'llvm::Error'

C:\work\main\llvm-project\llvm\include\llvm/Support/Error.h(181): note: see declaration of 'llvm::Error::Error'

C:\work\main\llvm-project\llvm\include\llvm/Support/FormatVariadicDetails.h(20): note: see declaration of 'llvm::Error'

C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30133\include\future(193): note: while compiling class template member function 'std::_Associated_state<_Ty>::_Associated_state(std::_Deleter_base<_Ty> *)'

        with

        [

            _Ty=llvm::Error

        ]

C:\work\main\llvm-project\lldb\tools\lldb-dap\DAP.cpp(854): note: see reference to class template instantiation 'std::future<llvm::Error>' being compiled
```

To work around this, swapping to a lldb::SBError for now.
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
When building with MSVC 2019 using `std::future<llvm::Error>` causes a
compile time build error.

```
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30133\include\future(196): error C2248: 'llvm::Error::Error': cannot access protected member declared in class 'llvm::Error'

C:\work\main\llvm-project\llvm\include\llvm/Support/Error.h(181): note: see declaration of 'llvm::Error::Error'

C:\work\main\llvm-project\llvm\include\llvm/Support/FormatVariadicDetails.h(20): note: see declaration of 'llvm::Error'

C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30133\include\future(193): note: while compiling class template member function 'std::_Associated_state<_Ty>::_Associated_state(std::_Deleter_base<_Ty> *)'

        with

        [

            _Ty=llvm::Error

        ]

C:\work\main\llvm-project\lldb\tools\lldb-dap\DAP.cpp(854): note: see reference to class template instantiation 'std::future<llvm::Error>' being compiled
```

To work around this, swapping to a lldb::SBError for now.
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
When building with MSVC 2019 using `std::future<llvm::Error>` causes a
compile time build error.

```
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30133\include\future(196): error C2248: 'llvm::Error::Error': cannot access protected member declared in class 'llvm::Error'

C:\work\main\llvm-project\llvm\include\llvm/Support/Error.h(181): note: see declaration of 'llvm::Error::Error'

C:\work\main\llvm-project\llvm\include\llvm/Support/FormatVariadicDetails.h(20): note: see declaration of 'llvm::Error'

C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30133\include\future(193): note: while compiling class template member function 'std::_Associated_state<_Ty>::_Associated_state(std::_Deleter_base<_Ty> *)'

        with

        [

            _Ty=llvm::Error

        ]

C:\work\main\llvm-project\lldb\tools\lldb-dap\DAP.cpp(854): note: see reference to class template instantiation 'std::future<llvm::Error>' being compiled
```

To work around this, swapping to a lldb::SBError for now.
Ankur-0429 pushed a commit to Ankur-0429/llvm-project that referenced this pull request May 9, 2025
When building with MSVC 2019 using `std::future<llvm::Error>` causes a
compile time build error.

```
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30133\include\future(196): error C2248: 'llvm::Error::Error': cannot access protected member declared in class 'llvm::Error'

C:\work\main\llvm-project\llvm\include\llvm/Support/Error.h(181): note: see declaration of 'llvm::Error::Error'

C:\work\main\llvm-project\llvm\include\llvm/Support/FormatVariadicDetails.h(20): note: see declaration of 'llvm::Error'

C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30133\include\future(193): note: while compiling class template member function 'std::_Associated_state<_Ty>::_Associated_state(std::_Deleter_base<_Ty> *)'

        with

        [

            _Ty=llvm::Error

        ]

C:\work\main\llvm-project\lldb\tools\lldb-dap\DAP.cpp(854): note: see reference to class template instantiation 'std::future<llvm::Error>' being compiled
```

To work around this, swapping to a lldb::SBError for now.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants