Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

error: class template placeholder not permitted in this context

The following snippet compiles in gcc 12.1 but not in gcc 11.1. Unfortunately, I only have gcc 11 at hand as I’m crosscompiling for a microcontroller. Is there a way to make it work? Also what is this cryptic "use ‘auto’ for an abbreviated function template" all about?

Demo

#include <cstdio>
#include <tuple>

template <typename T>
struct channel
{
    int a;
    T b;
};

template <typename... Channels>
struct light
{
    light(const std::tuple<Channels...>& channels)
        :   channels_ { channels }
    {
        
    }

    std::tuple<Channels...> channels_;
};

int main()
{
    light li(std::tuple{channel(2, 2), channel(2,false)});
}

Error (only in gcc 11.1):

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

<source>:25:14: error: class template placeholder 'std::tuple' not permitted in this context
   25 |     light li(std::tuple{channel(2, 2), channel(2,false)});
      |              ^~~
<source>:25:14: note: use 'auto' for an abbreviated function template

Interestingly, gcc 10.4 has something even different to say:

<source>:25:14: error: 'auto' parameter not permitted in this context
   25 |     light li(std::tuple{channel(2, 2), channel(2,false)});
      |              ^~~

I need a workaround that allows me to not specify all the template parameters of std::tuple as that would blow up my initializer to the point of unrecognizeability :/

>Solution :

I need a workaround …

light li{ std::tuple{channel(2, 2), channel(2, false)} };
//      ^                                              ^
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading