Bug type: Language Service
The Issue
Intellisense unable to deduce member type of constrained template (via c++20 concepts).
The following code encapsulates the error, important lines have a comment preceding them:
#include <type_traits>
#include <stddef.h>
template<typename... Ts>
struct Bundle;
template<typename First, typename... Rest>
struct Bundle<First, Rest...>
{
static constexpr size_t size = 1 + sizeof...(Rest);
typedef First FirstType;
typedef Bundle<Rest...> Bundle_Rest;
};
template<>
struct Bundle<>
{
static constexpr size_t size = 0;
};
template<typename T>
struct Is_Bundle : std::integral_constant<bool, false>{};
template<typename... Ts>
struct Is_Bundle<Bundle<Ts...>> : std::integral_constant<bool, true>{};
template<typename T>
concept Bundle_T = Is_Bundle<T>::value;
template<typename T>
concept Has_Type = requires (typename T::T){true;};
template<Bundle_T B1, Bundle_T B2>
struct Concat {};
template<typename... T1s, typename... T2s>
struct Concat<Bundle<T1s...>, Bundle<T2s...>>
{
typedef Bundle<T1s..., T2s...> T;
};
template<typename Type>
struct TestExpression
{
typedef bool T;
};
template<Bundle_T B, template<typename> typename Expression>
//if this requires line is removed, the issues disappear (but concepts are cool so I want it)
requires Has_Type<Expression<typename B::FirstType>> || (B::size == 0)
struct Template_For
{
typedef typename Concat<Bundle<typename Expression<typename B::FirstType>::T>,
typename Template_For<typename B::Bundle_Rest, Expression>::T>::T T;
};
template<template<typename> typename Expression>
struct Template_For<Bundle<>, Expression>
{
typedef Bundle<> T;
};
template<Bundle_T T>
struct TheEnd {};
int main()
{
//Intellisense label Type0 as <error-type>
typedef Template_For<Bundle<int>, TestExpression>::T Type0;
//due to the Bundle_T concept, this shows a red squiggle error
TheEnd<Type0> a;
}
Expected Behavior
'Type0' should deduce to 'Bundle', and therefor the line after should not have a red squiggle.
System Used
- OS and Version: Ubuntu 20.04
- VS Code Version: 1.59.1
- C/C++ Extension Version: 1.6.0
- Other extensions you installed (and if the issue persists after disabling them): Jupyter, Pylance, Python (persists upon disabling all)
c_cpp_properties.json
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [],
"compilerPath": "/bin/clang++",
"cStandard": "c11",
"intelliSenseMode": "linux-clang-x64",
"cppStandard": "c++20"
}
],
"version": 4
}
Bug type: Language Service
The Issue
Intellisense unable to deduce member type of constrained template (via c++20 concepts).
The following code encapsulates the error, important lines have a comment preceding them:
Expected Behavior
'Type0' should deduce to 'Bundle', and therefor the line after should not have a red squiggle.
System Used
c_cpp_properties.json
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [],
"compilerPath": "/bin/clang++",
"cStandard": "c11",
"intelliSenseMode": "linux-clang-x64",
"cppStandard": "c++20"
}
],
"version": 4
}