How to Avoid Error C2686 When Using Microsoft Visual Studio* with Enabled C++17 Support as a Host Compiler for DPC++

When Microsoft* Visual Studio compiler with enabled C++17 support as a host compiler for DPC++ application causes error C2686. Visit Use a Third-Party Compiler as a Host Compiler for DPC++ Code to learn more about external compiler usage for DPC++.

Issue Description:

Let’s review a simple reproducer: 

#include <CL/sycl.hpp>
#include <iostream>
int main(int argc, char** argv)
{
    std::cout << "Build from: " << __DATE__ << " " << __TIME__ << std::endl;
    std::cout << "OK" << std::endl;
    return 0;
}

  • Should work (C++ 17 support is not enabled):

> cl /EHsc /I "C:\Program Files (x86)\Intel\oneAPI\compiler\latest\windows\include\sycl" main.cpp /Fe:main.exe
> main.exe
Build from: Jun  4 2021 16:51:50
OK

  • Should NOT work after adding /std:c++17  : 

>cl /EHsc /Zc:__cplusplus /std:c++17 /I "C:\Program Files (x86)\Intel\oneAPI\compiler\latest\windows\include\sycl" main.cpp /Fe:main_err.exe
Microsoft (R) C/C++ Optimizing Compiler Version 19.28.29334 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.main.cpp
cl_version.h: CL_TARGET_OPENCL_VERSION is not defined. Defaulting to 300 (OpenCL 3.0)
C:\Program Files (x86)\Intel\oneAPI\compiler\latest\windows\include\sycl\CL/sycl/ONEAPI/accessor_property_list.hpp(199): error C2686: cannot overload static and non-static member functions with the same parameter types
C:\Program Files (x86)\Intel\oneAPI\compiler\latest\windows\include\sycl\CL/sycl/ONEAPI/accessor_property_list.hpp(199): note: could be 'std::enable_if<cl::sycl::ONEAPI::is_compile_time_property<PropT>::value,bool>::type cl::sycl::ONEAPI::accessor_property_list<T...>::has_property(void)'
C:\Program Files (x86)\Intel\oneAPI\compiler\latest\windows\include\sycl\CL/sycl/ONEAPI/accessor_property_list.hpp(199): note: or       'std::enable_if<!cl::sycl::ONEAPI::is_compile_time_property<PropT>::value,bool>::type cl::sycl::ONEAPI::accessor_property_list<T...>::has_property(void) const'
C:\Program Files (x86)\Intel\oneAPI\compiler\latest\windows\include\sycl\CL/sycl/ONEAPI/accessor_property_list.hpp(230): note: see reference to class template instantiation 'cl::sycl::ONEAPI::accessor_property_list<T...>' being compiled
C:\Program Files (x86)\Intel\oneAPI\compiler\latest\windows\include\sycl\CL/sycl/ONEAPI/accessor_property_list.hpp(207): error C2686: cannot overload static and non-static member functions with the same parameter types
C:\Program Files (x86)\Intel\oneAPI\compiler\latest\windows\include\sycl\CL/sycl/ONEAPI/accessor_property_list.hpp(207): note: could be 'auto cl::sycl::ONEAPI::accessor_property_list<T...>::get_property(void)'
C:\Program Files (x86)\Intel\oneAPI\compiler\latest\windows\include\sycl\CL/sycl/ONEAPI/accessor_property_list.hpp(207): note: or       'PropT cl::sycl::ONEAPI::accessor_property_list<T...>::get_property(void) const'
Alignment of class vec is not in accordance with SYCL specification requirements, a limitation of the MSVC compiler(Error C2719).Applied default alignment.
>

Solution: 

As you see, the crash happens with C:\Program Files (x86)\Intel\oneAPI\compiler\latest\windows\include\sycl\CL/sycl/ONEAPI/accessor_property_list.hpp. Open this file in administrative mode to apply the fix: 


1.    This is what we see in the original header file:
#if __cplusplus >= 201703L
<problem code for MSVC her>
#endif


2.    The patch: 
#if __cplusplus >= 201703L && !defined(_MSC_VER)
<problem code for MSVC her>
#endif

 

After that, you can easily compile the simple reproducer without any errors. 

Product and Performance Information

1

Performance varies by use, configuration and other factors. Learn more at www.Intel.com/PerformanceIndex.