- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
When recently compiling a bit of code using the classic compiler included in the oneAPI HPC toolkit, I encountered the following warning:
warning #4070: the implicit by-copy capture of "this" is deprecated
This is a new warning and the error occurs inside of a lambda expression which does a default capture-by-ref, namely [&]
Per the link below, it would seem the committee decided to disallow implicit capture of this with [=] but to allow it via [&]
Deprecate implicit capture of this via [=] (open-std.org)
Here is a snippet from the relevant text:
- P0806R1: Remove the [&] part; only deprecate [=] now, as requested by EWG. Rebased on current working paper wording.
Historical note: Revision 0 proposed to deprecate the implicit capture of this for both [=] and [&] capture-defaults. During discussion in Albuquerque, EWG wanted to retain [&] as an idiomatic way to capture this and only supported the deprecation the case of [=].
I believe the committee adopted this recommendation in C++20?
My understanding of the spec is that [=] no longer captures "this" (or "*this") by value implicitly but requires [=, this] (or [=, *this]), but [&] continues to work as before capturing "this" as before, no?
EDIT: incidentally, changing [&] to [&, this] resolves the warning but this is syntactically redundant.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
The problem you reported is fixed in our latest Intel oneAPI C++ Compiler Classic version, 2021.3. This is a part of Intel oneAPI HPC Toolkit and can be downloaded here: https://software.intel.com/content/www/us/en/develop/tools/oneapi/hpc-toolkit/download.html
We have also checked it on our end. This issue has been resolved and we will no longer respond to this thread. If you require additional assistance from Intel, please start a new thread.
Any further interaction in this thread will be considered community only.
Thanks.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Thanks for reaching out to us.
We are looking into this issue and we will get back to you with the updates.
Warm Regards,
Abhishek
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
Could you please send us a reproducer and indicate how you compile it, so we can try it on our end?
Regards,
Khalik.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yes, I imagine this will be simple to isolate. I will post something here later today schedule permitting.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Attached.
Compiled in Visual Studio 2019 16.9.2 using "legacy" Intel Classic Compiler 19.2 (2021.1.2) with /std:c++latest and /Od. Target plataform x64.
(apparently I can't upload any text files to this forum because of some mime type nonsense and I'm tired of trying so I will paste)
#include <algorithm>
#include <iterator>
#include <vector>
template <typename T>
class Tester
{
public:
Tester() { }
explicit Tester(std::vector<T> const &initial_vals) : m_dst(initial_vals) { }
public:
void CopyOddUniques(std::vector<T> const &src)
{
// std::copy_if(src.cbegin(), src.cend(), back_inserter(m_dst), [=](T const &value) // ok - correctly warns 4070, capture-by-value of this is now disallowed
std::copy_if(src.cbegin(), src.cend(), back_inserter(m_dst), [&](T const &value) // bug - warn 4070, capture-by-ref should allow implicit capture of this
{
return std::find(m_dst.cbegin(), m_dst.cend(), value) == m_dst.cend() && value % 2 != 0;
}
);
}
void CopyEvenUniques(std::vector<T> const &src)
{
// std::copy_if(src.cbegin(), src.cend(), back_inserter(m_dst), [=, this](T const &value) // ok
std::copy_if(src.cbegin(), src.cend(), back_inserter(m_dst), [&, this](T const &value) // ok - resolves 4070, but is syntactically redundant and should not be required
{
return std::find(m_dst.cbegin(), m_dst.cend(), value) == m_dst.cend() && value % 2 == 0;
}
);
}
private:
std::vector<T> m_dst;
};
int main()
{
std::vector src { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
Tester t(std::vector { 1, 2, 5, 6 });
t.CopyOddUniques(src);
t.CopyEvenUniques(src);
return 0;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you for the reproducer.
We were able to reproduce issue on our end (we also reproduced it on Linux).
The implicit capture of "this" was deprecated in C++20, so this warning message is unexpected when doing capture-by-reference [&].
I have forwarded this case to the development team to get it fixed.
In the meantime, you could use [&, this] which is syntactically redundant, as you mentioned.
The other workaround you can use is via usage of Intel oneAPI DPC++/C++ Compiler, which does not display this warning message.
Kind regards,
Khalik.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Glad you could reproduce and thanks for the update!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
The problem you reported is fixed in our latest Intel oneAPI C++ Compiler Classic version, 2021.3. This is a part of Intel oneAPI HPC Toolkit and can be downloaded here: https://software.intel.com/content/www/us/en/develop/tools/oneapi/hpc-toolkit/download.html
We have also checked it on our end. This issue has been resolved and we will no longer respond to this thread. If you require additional assistance from Intel, please start a new thread.
Any further interaction in this thread will be considered community only.
Thanks.

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page