Skip to content
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

Unable to deduce type in template metaprogram using concepts #8132

Closed
davidBronicki opened this issue Sep 10, 2021 · 2 comments
Closed

Unable to deduce type in template metaprogram using concepts #8132

davidBronicki opened this issue Sep 10, 2021 · 2 comments
Labels
bug fixed Check the Milestone for the release in which the fix is or will be available. Language Service Visual Studio Inherited from Visual Studio
Milestone

Comments

@davidBronicki
Copy link

davidBronicki commented Sep 10, 2021

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
}

@michelleangela michelleangela added this to the Tracking milestone Sep 11, 2021
@michelleangela
Copy link
Contributor

michelleangela commented Sep 11, 2021

I've filed an internal bug (1398106) against our shared Visual Studio (VS) IntelliSense process.

@sean-mcmanus sean-mcmanus modified the milestones: Tracking, 1.19.0 Oct 25, 2023
@sean-mcmanus sean-mcmanus added the fixed Check the Milestone for the release in which the fix is or will be available. label Oct 25, 2023
@sean-mcmanus
Copy link
Contributor

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug fixed Check the Milestone for the release in which the fix is or will be available. Language Service Visual Studio Inherited from Visual Studio
Projects
None yet
Development

No branches or pull requests

4 participants